Exports.install = function (ProjectPath, PackageName, save, Dev) {
const NPM = ' NPM '
const args = [' Install ']
Args.push (PackageName)
if (save) Args.push ('--save ')
if (dev) args.push ('--save-dev ')
var ls = require (' Child_process '). Spawn (NPM, args, {
//stdio: ' Inherit ',
cwd:projectpath
})
Ls.stdout.on (' data ', function (data) {
Console.log (' stdout: ' + data)
})
Ls.stderr.on (' Data ', function (err) {
Console.log (' stderr: ' + Err)
})
ls.once (' Close ', function () {
console.log (' Install success ... ')
})
}
Execute NPM Command and will report the following error
cause of error: NPM's execution name is different under Windows Workaround:
var ls = require (' child_process '). Spawn (Process.platform = = = ' Win32 '?) ' Npm.cmd ': npm, args, {
//stdio: ' Inherit ',
cwd:projectpath
})
PackageUtil.test.js
' Use strict '
const PATH = require (' path ')
const PACKAGEUTIL = require ('. /dist/packageutil ')
const P = path.resolve (__dirname, ' ... ')
/** perform npm install Koa-markdown--save-dev**/
packageutil.install (P, ' Koa-markdown ', True, True)
/** perform NPM Install Koa-markdown--save**/
Uncomment //stdio: ' Inherit ', remove Stdout.on and Stderr.on