Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
remove extend-shallow, rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Jan 27, 2015
1 parent d65a0b0 commit 6d7c294
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
16 changes: 7 additions & 9 deletions index.js
Expand Up @@ -10,7 +10,6 @@
var isEmptyFunction = require('is-empty-function');
var handleArguments = require('handle-arguments');
var handleErrors = require('handle-errors')('async-exec-cmd');
var extend = require('extend-shallow');
var unique = require('array-unique');
var spawn = require('cross-spawn');
var typeOf = require('kind-of');
Expand All @@ -33,11 +32,11 @@ var type = handleErrors.type;
* ```
*
* @name asyncExecCmd
* @param {String} `<cmd>`
* @param {Array|Function} `[args]`
* @param {Object|Function} `[opts]`
* @param {Function} `<callback>`
* @return {Stream} spawned child process
* @param {String} `<cmd>`
* @param {Array} `[args]`
* @param {Object} `[opts]`
* @param {Function} `<callback>`
* @return {Stream} spawned child process
* @api public
*/
module.exports = function asyncExecCmd() {
Expand All @@ -50,11 +49,11 @@ module.exports = function asyncExecCmd() {

function checkArguments(argz) {
if (!argz.args.length) {
return error('should have at least 1 argument - should not be function');
return error('first argument cant be function');
}

if (isEmptyFunction(argz.cb)) {
return error('should have `cb` (non empty callback)');
return error('should have `callback` (non empty callback)');
}

if (typeOf(argz.args[0]) !== 'string') {
Expand All @@ -78,7 +77,6 @@ function buildArguments(argz) {
var args = argz.cmd.split(' ');
argz.cmd = args.shift();
argz.args = unique(argz.args || [], args || []);
argz.opts = extend({}, argz.opts || {});
return argz;
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -47,7 +47,6 @@
"arr-union": "^2.0.0",
"array-unique": "^0.1.1",
"cross-spawn": "^0.2.3",
"extend-shallow": "^0.2.0",
"handle-arguments": "^1.0.4",
"handle-errors": "0.0.2",
"is-empty-function": "^1.0.0",
Expand Down
62 changes: 60 additions & 2 deletions readme.md
Expand Up @@ -16,8 +16,8 @@ npm test
> Async execute command via spawn
* `<cmd>` **{String}**
* `[args]` **{Array|Function}**
* `[opts]` **{Object|Function}**
* `[args]` **{Array}**
* `[opts]` **{Object}**
* `<callback>` **{Function}**
* `returns` **{Stream}** spawned child process

Expand All @@ -40,6 +40,64 @@ var cp = exec('echo', [
})
```

### Possible signatures (will work)
> these examples should work without problems
```js
var asyncExecCmd = require('async-exec-cmd');

function __cb(err, res) {
// res[0] is status code
if (err || res[0] > 0) {
console.error(err);
return;
}

// res[1] is actual result
console.log(res[1]);
}

asyncExecCmd('npm', __cb);
asyncExecCmd('npm', {someFake: 'options'}, __cb);
asyncExecCmd('npm', ['install', '--save-dev', 'bluebird'], __cb);
asyncExecCmd('npm', ['install', '--save-dev', 'bluebird'], {stdio: [null, null, null]}, __cb);
asyncExecCmd('npm -v', __cb)
asyncExecCmd('npm install', ['--save-dev', 'bluebird'], __cb);
asyncExecCmd('npm install', ['--save-dev', 'bluebird'], {stdio: [null, null, null]}, __cb);
asyncExecCmd('npm -v', {stdio: [null, null, null]}, __cb);
```

### Impossible signatures (will throws/errors)
> these examples should not work
```js
asyncExecCmd(__cb)
//=> first argument cant be function

asyncExecCmd({ok:true})
//=> should have `callback` (non empty callback)

asyncExecCmd(['--save-dev', 'bluebird'])
//=> should have `callback` (non empty callback)

asyncExecCmd(['--save-dev', 'bluebird'], {ok:true})
//=> should have `callback` (non empty callback)

asyncExecCmd({ok:true}, __cb)
//=> expect `cmd` be string

asyncExecCmd(['--save-dev', 'bluebird'], __cb)
//=> expect `cmd` be string

asyncExecCmd(['--save-dev', 'bluebird'], {ok:true}, __cb);
//=> expect `cmd` be string
```

actually, this will error.
npm-cli shows friendly output, but exits with code 1,
so if you want to handle this output, you should
search it in `err` object - `err.buffer.toString('utf8')`


## Author
**Charlike Mike Reagent**
Expand Down

0 comments on commit 6d7c294

Please sign in to comment.