async-chainable-exec
Plugin for async-chainable that provides exec() support
Last updated 3 years ago by hash-bang .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install async-chainable-exec 
SYNC missed versions from official npm registry.

async-chainable-exec

Plugin for async-chainable that adds external program execution.

var asyncChainable = require('async-chainable');
var asyncChainableExec = require('async-chainable-exec');

asyncChainable()
	.use(asyncChainableExec)
	.exec('echo one two three')
	.end();


asyncChainable()
	.use(asyncChainableExec)
	.exec('dirContents', ['ls', '-l', '-a'])
	.then(function(next) {
		console.log('The directory contains', this.dirContents);
		next();
	})
	.end(function(err) {
		if (err) throw new Error(err);
	});


asyncChainable()
	.use(asyncChainableExec)
	.exec({
		id: 'myDir',
		cmd: 'bash',
		params: ['-c', 'echo $PWD'],
		cwd: __dirname,
	})
	.then(function(next) {
		console.log('My directory is', this.myDir);
		next();
	})
	.end(function(err) {
		if (err) throw new Error(err);
	});


# Setting stdio=inherit will output to the console as the program runs
asyncChainable()
	.use(asyncChainableExec)
	.execDefaults({stdio: 'inherit'})
	.exec(['find -type f'])
	.end(function(err) {
		if (err) throw new Error(err);
	});


# Echo each command before it is executed
asyncChainable()
	.use(asyncChainableExec)
	.execDefaults({
		log: function(cmd) { console.log('[RUN]', cmd.cmd + ' ' + cmd.params.join(' ')) },
		out: function(line) { console.log('[GOT]', line) },
	})
	.exec('echo foo')
	.exec('echo bar')
	.exec('echo baz')
	.end(function(err) {
		if (err) throw new Error(err);
	});

API

async-chainable-exec provides a single function, exec() which can be called a number of ways:

exec(String <name>, Array <cmd + params>) // Execute the command + arguments array and store its response in 'name'
exec(String <cmd + params>) // Execute command + arguments (response is still available in `this.exec`)
exec(String <name>, String <cmd + params>) // Execute the command + arguments as a string and store its response in 'name'
exec(Array <cmd + params>) // Execute the command + arguments array
exec(Object) // Pass an object for execution, must contain at least 'cmd' but could contain 'params' as an array and 'id' as a string
exec(String <name>, Array <cmd + params>, Object <additional>) // Execute command + arguments from the array using addition spawn arguments and store its response in 'name'
exec(String <name>, Object) // Pass an object for execution (see 'Object' definition) and store its response in 'name'

Regardless of whether the exec function is called with a name / id the last executed item is stored in this.exec with the following properties:

Key Type Description
this.exec.code Int The exit code of the last executed item
this.exec.output Array The combined STDOUT and STDERR streams from the last execution

Options

In addition to the parameters supported by the generic child_process.spawn() method the following additional options are supported:

Option Type Description
log function(cmd) Pass the command object (see above) to this function before every execution
out function(data) Pass the output of every command run as a string (both STDOUT and STDERR)
passthru boolean Also output STDOUT + STDERR into process.stdout / process.stderr. The out property cannot be set if this is true
stderr function(data) Pass the output of any STDERR into a callback
stdout function(data) Pass the output of any STDOUT into a callback
style string Use a predefined style (sets log + out). Currently supported: batch, passthru

Current Tags

  • 1.3.4                                ...           latest (3 years ago)

13 Versions

  • 1.3.4                                ...           3 years ago
  • 1.3.3                                ...           3 years ago
  • 1.3.2                                ...           4 years ago
  • 1.3.1                                ...           4 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.5                                ...           5 years ago
  • 1.2.4                                ...           5 years ago
  • 1.2.3                                ...           5 years ago
  • 1.2.2                                ...           5 years ago
  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (5)

Copyright 2014 - 2016 © taobao.org |