shell
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