Files
vue-cli/packages/@vue/cli/lib/util/installDeps.js
2017-12-28 22:32:17 -05:00

36 lines
823 B
JavaScript

const { spawn } = require('child_process')
module.exports = function installDeps (command, targetDir, deps) {
return new Promise((resolve, reject) => {
const args = []
if (command === 'npm') {
args.push('install', '--loglevel', 'error')
if (deps) {
args.push('--save-dev')
}
} else if (command === 'yarn') {
if (deps) {
args.push('add', '--dev')
}
} else {
throw new Error(`unknown package manager: ${command}`)
}
if (deps) {
args.push.apply(args, deps)
}
const child = spawn(command, args, {
cwd: targetDir,
stdio: 'inherit'
})
child.on('close', code => {
if (code !== 0) {
return reject(
`command failed: ${command} ${args.join(' ')}`
)
}
resolve()
})
})
}