1 |
|
2 | var nps = require('path')
|
3 | var child = require('child_process')
|
4 | var chalk = require('chalk')
|
5 |
|
6 | var over = require('../lib/lib/utils/overwrite-require')
|
7 | var _console = require('../lib/lib/utils/console').default
|
8 | var info = over.getInfo()
|
9 | var optionalDependencies = require(nps.join(info.path.rootPath, 'package.json')).optionalDependencies || {}
|
10 |
|
11 | function 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 |
|
24 | module.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 | }
|