-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnpm-update.js
48 lines (43 loc) · 1.26 KB
/
npm-update.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
/* jshint esversion: 6 */
'use strict';
/*
| Update packages together with the package.json file
| https://github.com/npm/npm/issues/3417
*/
const stdlog = console.log.bind(console);
const requireWithCheck = module => {
try {
return require(module);
} catch (e) {
stdlog(`Please make sure that '${module}' module is present`);
stdlog("Eventually, install it with 'npm i <module name>'");
process.exit(e.code);
}
}
const fs = require('fs');
const chalk = requireWithCheck('chalk');
const cmd = requireWithCheck('node-cmd');
if (!process.stderr.isTTY) chalk.enabled = false;
fs.readFile('./package.json', 'utf8', (err, data) => {
let d = JSON.parse(data);
for (let key in d.dependencies) {
stdlog(chalk.green(`Updating dev package ${key}`));
cmd.get(
`npm install --save ${key}@latest`,
data => {
stdlog(chalk.green(`Package '${key}' updated.`));
}
);
}
for (let key in d.devDependencies) {
stdlog(chalk.blue(`Updating devDep package ${key}`));
cmd.run(`npm install --save-dev ${key}@latest`);
cmd.get(
`npm install --save-dev ${key}@latest`,
data => {
stdlog(chalk.blue(`Package '${key}' updated.`));
}
);
}
stdlog(chalk.yellow('Please wait, updates in progress'));
});