start-spawn
Start task to spawn a script/task/command using cross-spawn
Install
npm install --save-dev start-spawn# or yarn add --dev start-spawn
Usage
;; const start = ; const dev = ;
It automatically splits arguments and adds node_modules/.bin
to PATH (like npm scripts do).
Re-usage
If planning to re-use, initialize once and use the same task:
const runTask = ;const dev = ;
This way when the same task is run it automatically kills previously spawned process and cleans up any event listeneres.
It also returns the cleanup function in case you want to do it manually.
const runTask = ;const dev = ; const someOther = ;
By default it kills the child process using tree-kill* with a 'SIGTERM'
signal, but you can provide any other signal, or customize the killer function itself:
;const killer = { ;}runTask; // by argument// orrunTaskkiller = killer; // by configuring// (in case you just want to alter the function that it'll automatically call)
It waits for done
callback or awaits a returned promise to wait for it to completely exit.
*because child.kill() alone doesn't kill shell-spawned processes
Options
Takes same options as spawn, cross-spawn, and cross-spawn-promise.
Additional options:
forever
(boolean|number) (default: false)
Restarts if an error occurs, either indefinitely (if true
) or a set number
of times.
Issues
If you have a server app in a watch-spawn cycle but you're still getting EADDRINUSE
errors, make sure your app closes the server on any kill signals:
const app = ;//...process;