UNPKG

1.15 kBJavaScriptView Raw
1// #!/usr/bin/env node
2var nps = require('path')
3var child = require('child_process')
4var chalk = require('chalk')
5
6var over = require('../lib/lib/utils/overwrite-require')
7var _console = require('../lib/lib/utils/console').default
8var info = over.getInfo()
9var optionalDependencies = require(nps.join(info.path.rootPath, 'package.json')).optionalDependencies || {}
10
11function uninstall(pkg) {
12 var arr = pkg.split(/(?=@)/)
13 arr.length > 1 && arr.pop()
14 if (!optionalDependencies[arr.join('')]) {
15 console.warn(chalk.red.bold(' Error: '), '`' + arr.join('') + '`', 'is not be installed')
16 return
17 }
18 var cmd = 'npm uninstall ' + pkg + ' --save-optional'
19 console.log(' running: ', chalk.yellow.bold(cmd))
20 var output = child.execSync(cmd, { cwd: info.path.rootPath })
21 console.log(output.toString())
22}
23
24module.exports = function use(pkgs) {
25 if (info.type === 'local') {
26 console.log(
27 chalk.read.bold(' ERROR: Picidae is in local position, you should run `npm uninstall ' + pkgs.join(' ') + ' --save`!\n')
28 )
29 }
30 else {
31 pkgs.forEach(uninstall)
32 }
33 process.exit()
34}