All Projects → zeekay → executive

zeekay / executive

Licence: MIT License
🕴Elegant command execution for Node.

Programming Languages

coffeescript
4710 projects

Projects that are alternatives of or similar to executive

Flowa
🔥Service level control flow for Node.js
Stars: ✭ 66 (+78.38%)
Mutual labels:  serial, promise, parallel
Bach
Compose your async functions with elegance.
Stars: ✭ 117 (+216.22%)
Mutual labels:  promise, parallel
Promise Parallel Throttle
It's kinda like Promise.all(), but throttled!
Stars: ✭ 72 (+94.59%)
Mutual labels:  promise, parallel
Fluture
🦋 Fantasy Land compliant (monadic) alternative to Promises
Stars: ✭ 2,249 (+5978.38%)
Mutual labels:  promise, control-flow
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (+259.46%)
Mutual labels:  promise, parallel
P Map
Map over promises concurrently
Stars: ✭ 639 (+1627.03%)
Mutual labels:  promise, parallel
Metasync
Asynchronous Programming Library for JavaScript & Node.js
Stars: ✭ 164 (+343.24%)
Mutual labels:  promise, parallel
Asyncro
⛵️ Beautiful Array utilities for ESnext async/await ~
Stars: ✭ 487 (+1216.22%)
Mutual labels:  promise, parallel
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+421.62%)
Mutual labels:  promise, parallel
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (-10.81%)
Mutual labels:  promise, parallel
Node Serialport
Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
Stars: ✭ 5,015 (+13454.05%)
Mutual labels:  serial, promise
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-45.95%)
Mutual labels:  promise, parallel
lightflow
A tiny Promise-inspired control flow library for browser and Node.js.
Stars: ✭ 29 (-21.62%)
Mutual labels:  promise, parallel
asynckit
Minimal async jobs utility library, with streams support
Stars: ✭ 21 (-43.24%)
Mutual labels:  serial, parallel
bitmex-orderbook
The fastest order book implementation for the BitMEX WebSocket API.
Stars: ✭ 73 (+97.3%)
Mutual labels:  promise
shortcut-comparison
Performance comparison of parallel Rust and C++
Stars: ✭ 74 (+100%)
Mutual labels:  parallel
rzw
Rusty Z-Wave - A native Z-Wave library in Rust
Stars: ✭ 34 (-8.11%)
Mutual labels:  serial
node-steamapi
A nice Steam API wrapper for nodejs
Stars: ✭ 112 (+202.7%)
Mutual labels:  promise
lbvh
an implementation of parallel linear BVH (LBVH) on GPU
Stars: ✭ 67 (+81.08%)
Mutual labels:  parallel
distributed
Library to provide Erlang style distributed computations. This library is inspired by Cloud Haskell.
Stars: ✭ 49 (+32.43%)
Mutual labels:  parallel

executive

npm build dependencies downloads license chat

An elegant child_process.spawn

Executive is simple and intuitive interface to child_process.spawn with zero depdencies. Built-in support for async and sync process creation, built-in flow control and automatic shell make working with external processes in Node easy.

Features

  • Async callback, promise and sync APIs
  • Automatically pipes stderr and stdout by default
  • Automatically uses shell when commands use builtins, globs or operators
  • Built-in control flow with support for parallel and serial execution
  • Mix simple string commands with functions and promises returning commands
  • Multi-line strings parsed as multiple commands and executed sequentially
  • Streams stderr and stdout rather than blocking on command completion
  • Included TypeScript type definition
  • Improved Windows support
  • No external dependencies

Install

$ npm install executive --save-dev

Usage

No need to echo as stderr and stdout are piped by default.

import exec from 'executive'

exec('uglifyjs foo.js --compress --mangle > foo.min.js')

It's easy to be quiet too.

exec.quiet('uglifyjs foo.js --compress --mangle > foo.min.js')

Callbacks and promises are both supported.

exec('ls', (err, stdout, stderr) => console.log(stdout))
exec('ls').then(res => console.log(res.stdout))

Automatically serializes commands.

exec(['ls', 'ls', 'ls']) // All three ls commands will be executed in order

exec(`ls -l
      ls -lh
      ls -lha`) // Also executed in order

Want to execute your commands in parallel? No problem.

exec.parallel(['ls', 'ls', 'ls'])

Want to collect individual results? Easy.

{a, b, c} = await exec.parallel({
  a: 'echo a',
  b: 'echo b',
  c: 'echo c'
})

Want to blend in Promises or pure functions? You got it.

exec.parallel([
  'ls',

  // Promises can be blended directly in
  exec('ls'),

  // Promises returned by functions are automatically consumed
  () => exec('ls'),

  // Functions which return a string are assumed to be commands
  () => 'ls',

  // Functions and promises can return objects with stdout, stderr or status
  () => ({ stdout: 'huzzah', stderr: '', status: 0 }),

  'ls'
])

Options

Options are passed as the second argument to exec. Helper methods for quiet, interactive, parallel and sync do what you expect.

exec('ls', { quiet: true })

and

exec.quiet('ls')

are equivalent.

options.interactive | exec.interactive

default false

If you need to interact with a program (your favorite text editor for instance) or watch the output of a long running process (tail -f), or just don't care about checking stderr and stdout, set interactive to true:

exec.interactive('vim', err => {
  // Edit your commit message
})

options.quiet | exec.quiet

default false

If you'd prefer not to pipe stdout and stderr set quiet to true:

exec.quiet(['ls', 'ls'], (err, stdout, stderr) => {
  // You can still inspect stdout, stderr of course
})

options.sync | exec.sync

default false

Blocking version of exec. Returns {stdout, stderr} or throws an error.

options.parallel | exec.parallel

default false

Uses parallel rather than serial execution of commands.

options.shell

default null

Force a shell to be used for command execution.

options.strict

default false

Any non-zero exit status is treated as an error. Promises will be rejected and an error will be thrown with exec.sync if syncThrows is enabled.

options.syncThrows

default false

Will cause exec.sync to throw errors rather than returning them.

Extra

Great with sake, grunt, gulp and other task runners. Even nicer with async and await.

Fancy example using sake:

task('package', 'Package project', => {
  // Create dist folder
  await exec(`
    mkdir -p dist/
    rm   -rf dist/*
  `)

  // Copy assets to dist in parallel
  await exec.parallel(`
    cp manifest.json dist/
    cp -rf assets/   dist/
    cp -rf lib/      dist/
    cp -rf views/    dist/
  `)

  // Get current git commit hash
  let {stdout} = await exec('git rev-parse HEAD')
  let hash     = stdout.substring(0, 8)

  # Zip up dist
  exec(`zip -r package-${hash}.zip dist/`)
})

You can find more usage examples in the tests.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].