Executive

🕴Elegant command execution for Node.
Alternatives To Executive
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Enquirer6,9391,8761,2417 days ago35July 02, 2020198mitJavaScript
Stylish, intuitive and user-friendly prompts, for Node.js. Used by eslint, webpack, yarn, pm2, pnpm, RedwoodJS, FactorJS, salesforce, Cypress, Google Lighthouse, Generate, tencent cloudbase, lint-staged, gluegun, hygen, hardhat, AWS Amplify, GitHub Actions Toolkit, @airbnb/nimbus, and many others! Please follow Enquirer's author: https://github.com/jonschlinkert
Meow3,191320,6006,030a day ago35June 21, 202223mitJavaScript
🐈 CLI app helper
Gitkit Js594
5 years ago12apache-2.0JavaScript
Pure javascript implementation of Git (Node.js and Browser)
Wifi Password5681111a year ago14June 21, 20178mitJavaScript
Get current wifi password
Replace In File4872,9823,7523 months ago69May 30, 202218JavaScript
A simple utility to quickly replace contents in one or more files
React Native Version483426a year ago35March 04, 202048mitJavaScript
:1234: Version your React Native or Expo app in a `npm version` fashion.
Then Redis315386577 years ago29May 03, 20167JavaScript
A fast, promise-based Redis client for node.js
Koahub309
25 years ago22April 04, 2017mitHTML
KoaHub.js -- 中文最佳实践Node.js Web快速开发框架。支持Koa.js, Express.js中间件。当前项目已停止维护,推荐使用Doodoo.js
Ioredis Mock286931483 days ago178May 27, 202256mitJavaScript
Emulates ioredis by performing all operations in-memory.
Email Prompt25890302 years ago14August 17, 20211mitJavaScript
CLI email prompt with autocompletion and built-in validation
Alternatives To Executive
Select To Compare


Alternative Project Comparisons
Readme

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

Popular Command Line Projects
Popular Promise Projects
Popular Command Line Interface Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Shell
Command Line
Coffeescript
Promise
Serial
Parallel