@yun-jie/shell
v2.0.0
Published
Simple exec of shell commands
Downloads
2
Readme
shell
Simple exec of shell commands in node
const { shell } = require('@yun-jie/shell')
shell('touch somefile.js')
shell('http-server', { async: true })
shell(cmd, options)
Runs given command as a child process. Returns output of executed command.
const { shell } = require('@yun-jie/shell')
Options:
interface IShellOptions {
// current working directory
cwd?: string
// environment key-value pairs
env?: NodeJS.ProcessEnv
// timeout after which execution will be cancelled
timeout?: number
// default: false, if true it runs command asynchronously and returns a Promise
async?: boolean
// if true, it will send output directly to parent process (stdio="inherit"), it won't return the output though
// usefull if default piping strips too much colours when printing to the terminal
// if enabled, transform option won't work
nopipe?: boolean
// if true, it won't print anything to the terminal but it will still return the output as a string
silent?: boolean
// function which allows to transform the output, line by line
// usefull for adding prefixes to async commands output
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