easy-external
install npm package and spawn process easily from code
Install
// yarnyarn add easy-external // npmnpm install --save easy-external
Usage
const createRunner = ; // create a Runner // 'cwd'(required) is the current working directory for your runnerlet runner = // use .installPackages(packages,isSaveDev) to install npm package// if yarn is installed, it will use yarn to install the package, otherwise npm is usedrunnerrunner // use .removePackages(packages,isSaveDev) to remove npm package// if yarn is used, you don't need to specify the second parameter, yarn will choose it for yourunnerrunner // use.spawn(cmd,args,options) to run a child process, this is just a wrapper for child_precess.spawnSync, we just set the default cwd to your runner's cwd, you can override it on optionsrunner // There is a result from .installPackages(...), .removePackages(...)let result = runner // if the child process return 0, result will be 'null'// else, result will be {error:"errorMessage...",raw:[Object]}, the 'raw' is the result return from child_process.spawnSync, the 'error' message is from the stderr on the child_process.// use this result to check whether you install your node package successfully