# async-chainable-exec

> Plugin for async-chainable that provides exec() support

Latest version **1.3.4** (published 2017-04-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-chainable-exec
pnpm add async-chainable-exec
yarn add async-chainable-exec
bun add async-chainable-exec
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2017-04-19 |
| First published | 2015-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Matt Carter |
| Maintainers | hash-bang |
| Keywords | async, async-chainable, exec, spawn |

## Links

- npm: https://www.npmjs.com/package/async-chainable-exec
- Repository: https://github.com/hash-bang/async-chainable-exec
- Issues: https://github.com/hash-bang/async-chainable-exec/issues
- npm.io page: https://npm.io/package/async-chainable-exec

## Dependencies (4)

- [argy](https://npm.io/package/argy.md) ^1.3.1
- [chalk](https://npm.io/package/chalk.md) ^1.1.3
- [clone](https://npm.io/package/clone.md) ~2.1.1
- [spawn-args](https://npm.io/package/spawn-args.md) 0.2.0

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.3.4 (latest) — 2017-04-19
- 1.3.3 — 2017-04-13
- 1.3.2 — 2016-10-23
- 1.3.1 — 2016-09-22
- 1.3.0 — 2015-09-27
- 1.2.5 — 2015-06-26
- 1.2.4 — 2015-04-15
- 1.2.3 — 2015-03-24
- 1.2.2 — 2015-03-22
- 1.2.1 — 2015-03-10
- 1.2.0 — 2015-03-09
- 1.1.0 — 2015-02-02
- 1.0.0 — 2015-01-14

## README

async-chainable-exec
====================
Plugin for [async-chainable](https://github.com/hash-bang/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` |

---
_Source: https://npm.io/package/async-chainable-exec · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
