Skip to content

Instantly share code, notes, and snippets.

@dabbott
Created April 4, 2016 23:45
Show Gist options
  • Select an option

  • Save dabbott/6842549fe832f814b7e07d5630b4eff5 to your computer and use it in GitHub Desktop.

Select an option

Save dabbott/6842549fe832f814b7e07d5630b4eff5 to your computer and use it in GitHub Desktop.
const once = require('once')
const fork = require('child_process').fork
class npm {
static run(cmd = [], opts = {}, cb) {
cb = once(cb)
console.log('run npm with', cmd, opts)
var stdout = ''
var stderr = ''
var child = fork('./node_modules/.bin/npm', ['install','deco-ride-share-demo','--save'], opts)
if (child.stderr) {
child.stderr.on('data', function (chunk) {
stderr += chunk
})
}
if (child.stdout) {
child.stdout.on('data', function (chunk) {
stdout += chunk
})
}
child.on('error', cb)
child.on('close', function (code) {
cb(null, code, stdout, stderr)
})
return child
}
}
// npm.run(['install', `${name}@${version}`, '—save'], {cwd: path}, (err) => {
//
// })
export default npm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment