2.0.0 • Published 5 years ago

@pawelgalazka/shell v2.0.0

Weekly downloads
10,891
License
MIT
Repository
github
Last release
5 years ago

shell node version Build Status npm version

Simple exec of shell commands in node

const { shell } = require('@pawelgalazka/shell')

shell('touch somefile.js')
shell('http-server', { async: true })

shell(cmd, options)

Options:

{
    cwd: ..., // current working directory (String)
    async: ... // run command asynchronously (true/false), false by default
    env: ... // environment key-value pairs (Object)
    timeout: ...
    transform: // function which transforms the output, line by line
    nopipe: // if true, it will send output directly to parent process
    silent: // if true, it won't print anything to the terminal
}
interface IShellOptions {
  cwd?: string
  env?: NodeJS.ProcessEnv
  timeout?: number
  async?: boolean
  nopipe?: boolean
  silent?: boolean
  transform?: (output: string) => string
}

prefixTransform(prefix)

Transform function which can be used for transform option.

Example:

const { shell, prefixTransform } = require('@pawelgalazka/shell')

shell('echo "test"', { transform: prefixTransform('[prefix]') })
$ node ./script.js
echo "test"
[prefix] test