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
find('src', 'lib');
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.
@ -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
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
@ -346,7 +350,8 @@ silent(true);
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

View File

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

View File

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

View File

@ -777,7 +777,7 @@ exports.which = wrap('which', _which);
//@ like `.to()`.
function _echo(options) {
var messages = [].slice.call(arguments, 1);
log.apply(this, messages);
console.log.apply(this, messages);
return ShellString(messages.join(' '));
};
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
//@ `output` (stdout + stderr) and its exit `code`. Otherwise the `callback` gets the
//@ 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) {
if (!command)
error('must specify command');
@ -868,7 +872,8 @@ exports.error = function() {
//@ 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) {
if (typeof _state !== 'boolean')
return state.silent;
@ -1020,7 +1025,7 @@ function wrap(cmd, fn, options) {
} catch (e) {
if (!state.error) {
// 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);
process.exit(1);
}
@ -1028,7 +1033,7 @@ function wrap(cmd, fn, options) {
throw e;
}
state.currentCmd = 'maker.js';
state.currentCmd = 'shell.js';
return retValue;
}
} // wrap
@ -1151,8 +1156,7 @@ function rmdirSyncRecursive(dir, force) {
try {
result = fs.rmdirSync(dir);
} catch(e) {
if (e.code === 'ENOTEMPTY')
error('directory not empty: ' + dir, true);
error('could not remove directory (code '+e.code+'): ' + dir, true);
}
return result;
@ -1234,8 +1238,11 @@ function tempDir() {
// Wrapper around exec() to enable echoing output to console in real time
function execAsync(cmd, opts, callback) {
var output = '',
silent = 'silent' in opts ? opts.silent : state.silent;
var output = '';
var options = extend({
silent: state.silent
}, opts);
var c = child.exec(cmd, {env: process.env}, function(err) {
if (callback)
@ -1244,14 +1251,14 @@ function execAsync(cmd, opts, callback) {
c.stdout.on('data', function(data) {
output += data;
if (!silent)
write(data);
if (!options.silent)
process.stdout.write(data);
});
c.stderr.on('data', function(data) {
output += data;
if (!silent)
write(data);
if (!options.silent)
process.stdout.write(data);
});
}
@ -1325,11 +1332,12 @@ function execSync(cmd, opts) {
var stdout = fs.readFileSync(stdoutFile, 'utf8');
_unlinkSync(scriptFile);
_unlinkSync(stdoutFile);
_unlinkSync(codeFile);
_unlinkSync(sleepFile);
// No biggie if we can't erase the files now -- they're in a temp dir anyway
try { _unlinkSync(scriptFile); } catch(e) {};
try { _unlinkSync(stdoutFile); } catch(e) {};
try { _unlinkSync(codeFile); } catch(e) {};
try { _unlinkSync(sleepFile); } catch(e) {};
// True if successful, false if not
var obj = {
code: code,