This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
cli.js
executable file
·52 lines (43 loc) · 1.46 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
var npmPkgr = require('./');
var argv = require('minimist')(process.argv.slice(2));
if (argv.version) {
console.log(require('./package.json').version);
process.exit(0);
}
npmPkgr({
cwd: process.cwd(),
args: process.argv.slice(2).filter(removeArgs.bind(null, {
'--strategy': { expectsValue: false },
'--show-npm-output': { expectsValue: false },
'--symlinks': { expectsValue: true },
'--cachepath': { expectsValue: true }
})),
strategy: argv.strategy,
npmIo: argv['show-npm-output'] ? 'inherit' : null,
symlinks: argv.symlinks ? argv.symlinks.split(',') : null,
cachepath: argv.cachepath ? argv.cachepath.split(',') : null
}, end);
function removeArgs(argsToRemove, argName, argIndex, argsArr) {
var removeCurrentArg = typeof argsToRemove[argName] !== 'undefined';
var removePreviousArg = (
argIndex > 0 &&
argName.indexOf('--') !== 0 &&
typeof argsToRemove[argsArr[argIndex - 1]] !== 'undefined' &&
argsToRemove[argsArr[argIndex - 1]].expectsValue === true
);
return !(removeCurrentArg || removePreviousArg);
}
function end(err, res) {
if (err) {
console.error(err);
console.log();
console.error('An error occured while `npm-pkgr` ran.')
console.error('You will find an `npm-debug.log` in `%s` if `npm install` failed', process.cwd());
process.exit(1);
}
console.log('Packages installed in %s', res.node_modules);
if (!res.npm) {
console.log('`npm install` was not used');
}
}