bumping ShellJS

This commit is contained in:
Artur Adib 2012-03-28 18:03:31 -04:00
parent 89ceead8b0
commit c0289497ec
4 changed files with 59 additions and 29 deletions

View File

@ -138,7 +138,7 @@ Examples:
```javascript ```javascript
find('src', 'lib'); find('src', 'lib');
find(['src', 'lib']); // same as above find(['src', 'lib']); // same as above
find('.').filter(function(file) { return file.match(/\.js$/); }) find('.').filter(function(file) { return file.match(/\.js$/); });
``` ```
Returns array of all files (however deep) in the given paths. Returns array of all files (however deep) in the given paths.
@ -325,6 +325,10 @@ When in synchronous mode returns the object `{ code:..., output:... }`, containi
`output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the `output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the
arguments `(code, output)`. arguments `(code, output)`.
**Note:** For long-lived processes, it's best to run `exec()` asynchronously as
the current synchronous implementation uses a lot of CPU. This should be getting
fixed soon.
## Non-Unix commands ## Non-Unix commands
@ -346,7 +350,8 @@ silent(true);
silent(silentState); // restore old silent state silent(silentState); // restore old silent state
``` ```
Suppresses all output if `state = true`. Returns state if no arguments given. Suppresses all command output if `state = true`, except for `echo()` calls.
Returns state if no arguments given.
## Deprecated ## Deprecated

View File

@ -23,7 +23,7 @@ setTimeout(function() {
if (oldTarget.done && !force) if (oldTarget.done && !force)
return; return;
oldTarget.done = true; oldTarget.done = true;
return oldTarget(arguments); return oldTarget.apply(oldTarget, arguments);
} }
})(t, target[t]); })(t, target[t]);

View File

@ -1,12 +1,29 @@
{ "name": "shelljs" {
, "version": "0.0.5pre2" "name": "shelljs",
, "author": "Artur Adib <aadib@mozilla.com>" "version": "0.0.5pre4",
, "description": "Portable Unix shell commands for Node.js" "author": "Artur Adib <aadib@mozilla.com>",
, "keywords": ["unix", "shell", "makefile", "make", "jake", "synchronous"] "description": "Portable Unix shell commands for Node.js",
, "repository": "git://github.com/arturadib/shelljs" "keywords": [
, "homepage": "http://github.com/arturadib/shelljs" "unix",
, "main": "./shell.js" "shell",
, "scripts": { "makefile",
"make",
"jake",
"synchronous"
],
"repository": {
"type": "git",
"url": "git://github.com/arturadib/shelljs.git"
},
"homepage": "http://github.com/arturadib/shelljs",
"main": "./shell.js",
"scripts": {
"test": "node scripts/run-tests" "test": "node scripts/run-tests"
},
"dependencies": {},
"devDependencies": {},
"optionalDependencies": {},
"engines": {
"node": "*"
} }
} }

View File

@ -777,7 +777,7 @@ exports.which = wrap('which', _which);
//@ like `.to()`. //@ like `.to()`.
function _echo(options) { function _echo(options) {
var messages = [].slice.call(arguments, 1); var messages = [].slice.call(arguments, 1);
log.apply(this, messages); console.log.apply(this, messages);
return ShellString(messages.join(' ')); return ShellString(messages.join(' '));
}; };
exports.echo = wrap('echo', _echo); exports.echo = wrap('echo', _echo);
@ -809,6 +809,10 @@ exports.env = process.env;
//@ When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's //@ When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's
//@ `output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the //@ `output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the
//@ arguments `(code, output)`. //@ arguments `(code, output)`.
//@
//@ **Note:** For long-lived processes, it's best to run `exec()` asynchronously as
//@ the current synchronous implementation uses a lot of CPU. This should be getting
//@ fixed soon.
function _exec(command, options, callback) { function _exec(command, options, callback) {
if (!command) if (!command)
error('must specify command'); error('must specify command');
@ -868,7 +872,8 @@ exports.error = function() {
//@ silent(silentState); // restore old silent state //@ silent(silentState); // restore old silent state
//@ ``` //@ ```
//@ //@
//@ Suppresses all output if `state = true`. Returns state if no arguments given. //@ Suppresses all command output if `state = true`, except for `echo()` calls.
//@ Returns state if no arguments given.
exports.silent = function(_state) { exports.silent = function(_state) {
if (typeof _state !== 'boolean') if (typeof _state !== 'boolean')
return state.silent; return state.silent;
@ -1020,7 +1025,7 @@ function wrap(cmd, fn, options) {
} catch (e) { } catch (e) {
if (!state.error) { if (!state.error) {
// If state.error hasn't been set it's an error thrown by Node, not us - probably a bug... // If state.error hasn't been set it's an error thrown by Node, not us - probably a bug...
console.log('maker.js: internal error'); console.log('shell.js: internal error');
console.log(e.stack || e); console.log(e.stack || e);
process.exit(1); process.exit(1);
} }
@ -1028,7 +1033,7 @@ function wrap(cmd, fn, options) {
throw e; throw e;
} }
state.currentCmd = 'maker.js'; state.currentCmd = 'shell.js';
return retValue; return retValue;
} }
} // wrap } // wrap
@ -1151,8 +1156,7 @@ function rmdirSyncRecursive(dir, force) {
try { try {
result = fs.rmdirSync(dir); result = fs.rmdirSync(dir);
} catch(e) { } catch(e) {
if (e.code === 'ENOTEMPTY') error('could not remove directory (code '+e.code+'): ' + dir, true);
error('directory not empty: ' + dir, true);
} }
return result; return result;
@ -1234,8 +1238,11 @@ function tempDir() {
// Wrapper around exec() to enable echoing output to console in real time // Wrapper around exec() to enable echoing output to console in real time
function execAsync(cmd, opts, callback) { function execAsync(cmd, opts, callback) {
var output = '', var output = '';
silent = 'silent' in opts ? opts.silent : state.silent;
var options = extend({
silent: state.silent
}, opts);
var c = child.exec(cmd, {env: process.env}, function(err) { var c = child.exec(cmd, {env: process.env}, function(err) {
if (callback) if (callback)
@ -1244,14 +1251,14 @@ function execAsync(cmd, opts, callback) {
c.stdout.on('data', function(data) { c.stdout.on('data', function(data) {
output += data; output += data;
if (!silent) if (!options.silent)
write(data); process.stdout.write(data);
}); });
c.stderr.on('data', function(data) { c.stderr.on('data', function(data) {
output += data; output += data;
if (!silent) if (!options.silent)
write(data); process.stdout.write(data);
}); });
} }
@ -1325,11 +1332,12 @@ function execSync(cmd, opts) {
var stdout = fs.readFileSync(stdoutFile, 'utf8'); var stdout = fs.readFileSync(stdoutFile, 'utf8');
_unlinkSync(scriptFile); // No biggie if we can't erase the files now -- they're in a temp dir anyway
_unlinkSync(stdoutFile); try { _unlinkSync(scriptFile); } catch(e) {};
_unlinkSync(codeFile); try { _unlinkSync(stdoutFile); } catch(e) {};
_unlinkSync(sleepFile); try { _unlinkSync(codeFile); } catch(e) {};
try { _unlinkSync(sleepFile); } catch(e) {};
// True if successful, false if not // True if successful, false if not
var obj = { var obj = {
code: code, code: code,