cmd-spawn
Run shell commands as string. Typescript(+typings) ES2015/ES2017 module. Node 6+ spawn with promises, buffered and unbuffered output, inspired by node-buffered-spawn.
Features:
- Written in typescript and typings are auto generated.
- Promise based (Bluebird instance returned).
- child process exposed in returned promise as
cp
property. - If shell option is passed to spawn, the shell commands can be run as is, even with pipes.
- Auto passed process.env if spawn env not overriden.
- Normal version and buffered(collects all output and then resolve) option.
- Uses cross-spawn by default, can be disabled.
Install
npm -S i cmd-spawn
Usage
unbuffered(normal spawn)
;// Inherit process.env auto if not overriden // Told to run the command as is in a shell// Returns Bluebird Promiseconst promise = ; // child process is always in property ppromisecp; promisecp;
buffered spawn
// compile typescript projectconst promise = ;// Bluebirdpromise ;
More usage examples
Can be found in src/__test__/cmd-spawn.spec.ts
.
API
;
usage: cmdSpawn(cmd, options)
Parameter | Default | Type | Description |
---|---|---|---|
cmd | undefined | string or Array<string> |
command to run, if array is given, the first index is the command and rest becomes arguments. |
options | { spawnOpts: {}, crossSpawn: true, buffer: false } |
object |
Options described below. |
options - ? means optional
// Options passed to spawn spawnOpts?: SpawnOptions; // buffer output flag, default false buffer?: boolean; // crossSpawn flag, default enabled crossSpawn?: boolean;
Contributing
Requires
node@6+
npm@4.x
because ofpackage.json
-prepare
script. (only required to run hook when publish)npm -g i gulp-cli jest-cli
.
Usage
gulp --tasks
to get going.
Developing
jest --watchAll
to watch recompiled files and rerun tests.
Testing
Supports:
jest
, needsjest-cli
installed. it will execute the transpiled files from typescript.
Dist
gulp
will run default task which consist of running tasks:lint
,clean
,build
,minify
thenjest
and collect coverage.
Note: All minified
files are only ES5.