Comparing version 0.0.2-pre1 to 0.0.2
@@ -38,3 +38,3 @@ require('./global'); | ||
else { | ||
log('no such target: ' + arg); | ||
console.log('no such target: ' + arg); | ||
exit(1); | ||
@@ -41,0 +41,0 @@ } |
{ "name": "shelljs" | ||
, "version": "0.0.2pre1" | ||
, "version": "0.0.2" | ||
, "author": "Artur Adib <aadib@mozilla.com>" | ||
@@ -4,0 +4,0 @@ , "description": "Portable Unix shell commands for Node.js" |
# ShellJS - Unix shell commands for Node.js [![Build Status](https://secure.travis-ci.org/arturadib/shelljs.png)](http://travis-ci.org/arturadib/shelljs) | ||
_This project is young and experimental. Use at your own risk._ | ||
ShellJS is a **portable** (Windows included) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands. | ||
The project is both [unit-tested](http://travis-ci.org/arturadib/shelljs) and battle-tested at Mozilla's [pdf.js](http://github.com/mozilla/pdf.js). | ||
The project is [unit-tested](http://travis-ci.org/arturadib/shelljs) and is being used at Mozilla's [pdf.js](http://github.com/mozilla/pdf.js). | ||
@@ -15,3 +17,3 @@ | ||
mkdir('-p', 'out/Release'); | ||
cp('-R', 'lib/*.js', 'out/Release'); | ||
cp('-R', 'stuff/*', 'out/Release'); | ||
@@ -134,2 +136,23 @@ // Replace macros in each .js file | ||
#### find(path [,path ...]) | ||
#### find(path_array) | ||
Examples: | ||
```javascript | ||
find('src', 'lib'); | ||
find(['src', 'lib']); // same as above | ||
for (file in find('.')) { | ||
if (!file.match(/\.js$/)) | ||
continue; | ||
// all files at this point end in '.js' | ||
} | ||
``` | ||
Returns list of all files (however deep) in the given paths. For convenient iteration | ||
via `for (file in find(...))`, the format returned is a hash object: | ||
`{ 'file1':null, 'dir1/file2':null, ...}`. | ||
The main difference from `ls('-R', path)` is that the resulting file names | ||
include the base directories, e.g. `lib/resources/file1` instead of just `file1`. | ||
#### cp('[options ,] source [,source ...], dest') | ||
@@ -200,2 +223,17 @@ #### cp('[options ,] source_array, dest') | ||
#### test(expression) | ||
Available expression primaries: | ||
+ `'-d', 'path'`: true if path is a directory | ||
+ `'-f', 'path'`: true if path is a regular file | ||
Examples: | ||
```javascript | ||
if (test('-d', path)) { /* do something with dir */ }; | ||
if (!test('-f', path)) continue; // skip if it's a regular file | ||
``` | ||
Evaluates expression using the available primaries and returns corresponding value. | ||
#### cat(file [, file ...]) | ||
@@ -307,14 +345,32 @@ #### cat(file_array) | ||
#### error() | ||
Tests if error occurred in the last command. Returns `null` if no error occurred, | ||
otherwise returns string explaining the error | ||
#### silent([state]) | ||
Example: | ||
```javascript | ||
var silentState = silent(); | ||
silent(true); | ||
/* ... */ | ||
silent(silentState); // restore old silent state | ||
``` | ||
Suppresses all output if `state = true`. Returns state if no arguments given. | ||
## Deprecated | ||
#### exists(path [, path ...]) | ||
#### exists(path_array) | ||
_This function is being deprecated. Use `test()` instead._ | ||
Returns true if all the given paths exist. | ||
#### error() | ||
Tests if error occurred in the last command. Returns `null` if no error occurred, | ||
otherwise returns string explaining the error | ||
#### verbose() | ||
#### verbose() | ||
_This function is being deprecated. Use `silent(false) instead.`_ | ||
Enables all output (default) | ||
#### silent() | ||
Suppresses all output, except for explict `echo()` calls |
@@ -11,3 +11,3 @@ #!/usr/bin/env node | ||
// Remove '//@' | ||
docs = docs.replace(/\/\/\@ */g, ''); | ||
docs = docs.replace(/\/\/\@ ?/g, ''); | ||
// Append docs to README | ||
@@ -14,0 +14,0 @@ sed('-i', /# Command reference(.|\n)*/, '# Command reference\n\n' + docs, 'README.md'); |
153
shell.js
@@ -60,2 +60,3 @@ // | ||
//@ | ||
@@ -164,2 +165,50 @@ //@ #### ls([options ,] path [,path ...]) | ||
//@ | ||
//@ #### find(path [,path ...]) | ||
//@ #### find(path_array) | ||
//@ Examples: | ||
//@ | ||
//@ ```javascript | ||
//@ find('src', 'lib'); | ||
//@ find(['src', 'lib']); // same as above | ||
//@ for (file in find('.')) { | ||
//@ if (!file.match(/\.js$/)) | ||
//@ continue; | ||
//@ // all files at this point end in '.js' | ||
//@ } | ||
//@ ``` | ||
//@ | ||
//@ Returns list of all files (however deep) in the given paths. For convenient iteration | ||
//@ via `for (file in find(...))`, the format returned is a hash object: | ||
//@ `{ 'file1':null, 'dir1/file2':null, ...}`. | ||
//@ | ||
//@ The main difference from `ls('-R', path)` is that the resulting file names | ||
//@ include the base directories, e.g. `lib/resources/file1` instead of just `file1`. | ||
function _find(options, paths) { | ||
if (!paths) | ||
error('no path specified'); | ||
else if (typeof paths === 'object') | ||
paths = paths; // assume array | ||
else if (typeof paths === 'string') | ||
paths = [].slice.call(arguments, 1); | ||
var hash = {}; | ||
// why not simply do ls('-R', paths)? because the output wouldn't give the base dirs | ||
// to get the base dir in the output, we need instead ls('-R', 'dir/*') for every directory | ||
paths.forEach(function(file){ | ||
hash[file] = null; | ||
if (fs.statSync(file).isDirectory()) { | ||
for (subfile in _ls('-Ra', file+'/*')) | ||
hash[subfile] = null; | ||
} | ||
}); | ||
return hash; | ||
} | ||
exports.find = wrap('find', _find); | ||
//@ | ||
//@ #### cp('[options ,] source [,source ...], dest') | ||
@@ -444,2 +493,38 @@ //@ #### cp('[options ,] source_array, dest') | ||
//@ | ||
//@ #### test(expression) | ||
//@ Available expression primaries: | ||
//@ | ||
//@ + `'-d', 'path'`: true if path is a directory | ||
//@ + `'-f', 'path'`: true if path is a regular file | ||
//@ | ||
//@ Examples: | ||
//@ | ||
//@ ```javascript | ||
//@ if (test('-d', path)) { /* do something with dir */ }; | ||
//@ if (!test('-f', path)) continue; // skip if it's a regular file | ||
//@ ``` | ||
//@ | ||
//@ Evaluates expression using the available primaries and returns corresponding value. | ||
function _test(options, path) { | ||
if (!path) | ||
error('no path given'); | ||
// hack - only works with unary primaries | ||
options = parseOptions(options, { | ||
'd': 'directory', | ||
'f': 'file' | ||
}); | ||
if (!options.directory && !options.file) | ||
error('could not interpret expression'); | ||
if (options.directory) | ||
return fs.existsSync(path) && fs.statSync(path).isDirectory(); | ||
if (options.file) | ||
return fs.existsSync(path) && fs.statSync(path).isFile(); | ||
}; // test | ||
exports.test = wrap('test', _test); | ||
//@ | ||
//@ #### cat(file [, file ...]) | ||
@@ -743,7 +828,48 @@ //@ #### cat(file_array) | ||
//@ | ||
//@ #### error() | ||
//@ Tests if error occurred in the last command. Returns `null` if no error occurred, | ||
//@ otherwise returns string explaining the error | ||
exports.error = function() { | ||
return state.error; | ||
} | ||
//@ | ||
//@ #### silent([state]) | ||
//@ Example: | ||
//@ | ||
//@ ```javascript | ||
//@ var silentState = silent(); | ||
//@ silent(true); | ||
//@ /* ... */ | ||
//@ silent(silentState); // restore old silent state | ||
//@ ``` | ||
//@ | ||
//@ Suppresses all output if `state = true`. Returns state if no arguments given. | ||
exports.silent = function(_state) { | ||
if (typeof _state !== 'boolean') | ||
return state.silent; | ||
state.silent = _state; | ||
} | ||
//@ | ||
//@ ## Deprecated | ||
//@ | ||
//@ | ||
//@ #### exists(path [, path ...]) | ||
//@ #### exists(path_array) | ||
//@ | ||
//@ _This function is being deprecated. Use `test()` instead._ | ||
//@ | ||
//@ Returns true if all the given paths exist. | ||
function _exists(options, paths) { | ||
deprecate('exists', 'Use test() instead.'); | ||
if (!paths) | ||
@@ -766,23 +892,15 @@ error('no paths given'); | ||
//@ | ||
//@ #### error() | ||
//@ Tests if error occurred in the last command. Returns `null` if no error occurred, | ||
//@ otherwise returns string explaining the error | ||
exports.error = function() { | ||
return state.error; | ||
} | ||
//@ | ||
//@ #### verbose() | ||
//@ | ||
//@ _This function is being deprecated. Use `silent(false) instead.`_ | ||
//@ | ||
//@ Enables all output (default) | ||
exports.verbose = function() { | ||
deprecate('verbose', 'Use silent(false) instead.'); | ||
state.silent = false; | ||
} | ||
//@ | ||
//@ #### silent() | ||
//@ Suppresses all output, except for explict `echo()` calls | ||
exports.silent = function() { | ||
state.silent = true; | ||
} | ||
@@ -797,7 +915,2 @@ | ||
//////////////////////////////////////////////////////////////////////////////////////////////// | ||
@@ -813,2 +926,6 @@ // | ||
function deprecate(what, msg) { | ||
console.log('*** '+what+': This function is deprecated.', msg); | ||
} | ||
function write(msg) { | ||
@@ -815,0 +932,0 @@ if (!state.silent) |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -5,3 +5,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -8,0 +8,0 @@ shell.rm('-rf', 'tmp'); |
@@ -7,3 +7,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -10,0 +10,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -6,3 +6,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -9,0 +9,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ shell.rm('-rf', 'tmp'); |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
@@ -10,3 +10,3 @@ var shell = require('..'); | ||
shell.silent(); | ||
shell.silent(true); | ||
@@ -13,0 +13,0 @@ function numLines(str) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
80939
57
2117
373
1
32