-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-package.js
32 lines (28 loc) · 913 Bytes
/
install-package.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
/* global process */
var child_process = require('child_process');
var fs = require('fs');
var name = process.argv[2];
if (!name) {
console.log(
'Usage: npm run-script install-package <package>'
);
}
else {
child_process.exec(
'npm install --save ' + name,
function(error, stdout, stderr) {
if (stderr) {
return console.error(stderr);
}
if (error !== null) {
return console.error('exec error: ' + error);
}
// [email protected] node_modules/package-name
console.log(stdout);
var info = stdout.split(' ')[0].split('@');
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
pkg.ride.packages[info[0]] = '^' + info[1];
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2), 'utf8');
}
)
}