```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.
`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
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
-{ "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": "*"
}
}
//@ 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);
//@ 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');
//@ 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;
} 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);
}
throw e;
}
- state.currentCmd = 'maker.js';
+ state.currentCmd = 'shell.js';
return retValue;
}
} // wrap
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;
// 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)
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);
});
}
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,