npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

async-chainable-exec

v1.3.4

Published

Plugin for async-chainable that provides exec() support

Downloads

175

Readme

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 |