Home

Awesome

async-exec-cmd npmjs.com The MIT License

Simple, fast, flexible and cross-platform async executing commands (with node-cross-spawn).

code climate standard code style travis build status coverage status dependency status

Install

npm i async-exec-cmd --save
npm test

API

For more use-cases see the tests

asyncExecCmd

Async execute command via spawn. All arguments are rebuilt, merged, structured, normalized and after all passed to cross-spawn, which actually is Node's spawn.

Example:

var asyncExecCmd = require('async-exec-cmd')

var child = asyncExecCmd('npm install', [
  '--save-dev', 'bluebird'
], function __cb (err, res, code, buffer) {
  if (err) {
    console.error(err, code)
    return
  }

  console.log(res, code, buffer)
})

Possible signatures (will work)

these examples should work without problems

var cmd = require('async-exec-cmd')

function __cb (err, res, code, buffer) {
  if (err) {
    console.error(err, code)
    return
  }

  console.log(res, code, buffer)
}

/**
 * Try all these commands separatly or run the tests
 * they cover all situations
 */

cmd('npm', __cb)
//=> res and buffer are undefined

cmd('npm', {stdio: [null, null, null]}, __cb)
//=> err Error object, res and buffer are undefined, 

cmd('npm', ['install', '--save', 'bluebird'], __cb)
//=> err undefined, code 0, res === 'unbuild bluebird@2.9.3'

cmd('npm', ['uninstall', '--save', 'bluebird'], {stdio: [null, null, null]}, __cb)
//=> err undefined, code 0, res === 'unbuild bluebird@2.9.3'

cmd('npm -v', __cb)
//=> err undefined, code 0, res === '2.9.0'

cmd('npm install', ['--save', 'bluebird'], __cb)
//=> err undefined, code 0, res === 'bluebird@2.9.3 node_modules/bluebird'

cmd('npm uninstall', ['--save', 'bluebird'], {stdio: [null, null, null]}, __cb)
//=> err  undefined, code 0, res === 'unbuild bluebird@2.9.3'

cmd('npm -v', {stdio: 'inherit'}, __cb)
//=> will directly outputs: 2.9.0
//=> err undefined, code 0, res === ''

Impossible signatures (will throws/errors)

these examples should not work

cmd(__cb)
//=> first argument cant be function

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

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

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

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

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

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

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github