-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
check-upgrade.js
55 lines (47 loc) · 1.56 KB
/
check-upgrade.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
53
54
55
// check deps version in all skeleton package.json files
const fs = require('fs');
const readline = require('readline');
const glob = require('glob');
const ncu = require('npm-check-updates');
const files = glob.sync('*/package.json');
const semver = require('semver')
let p = Promise.resolve();
for (let file of files) {
p = p.then(() => checkFile(file));
}
async function checkFile(file) {
console.log('\n' + file);
const deps = {};
return new Promise((resolve, reject) => {
const rl = readline.createInterface({
input: fs.createReadStream(file, 'utf8'), // turn stream into lines
crlfDelay: Infinity // be nice to Windows \r\n line break
});
rl.on('line', line => {
// ignore empty line
line = line.trim();
if (!line) return;
const m = line.match(/^\s*"([^"]+)":\s*"([^\w][^"]+)",?\s*$/);
if (!m) return;
if (m[2].match(/\d+\./)) deps[m[1]] = m[2];
});
rl.on('close', () => {
ncu.run({packageData: JSON.stringify({dependencies: deps})})
.then(
upgrade => {
Object.keys(upgrade).forEach(name => {
const version = upgrade[name];
// const major = semver.minVersion(version).major;
console.log(`${name} ${deps[name]} ==> ${version}`);
// if (major > semver.minVersion(deps[name]).major) {
// Only highlight major upgrade
// console.log(`${name} ${deps[name]} ==> ^${major}.0.0 (latest is ${version})`);
// }
});
resolve();
},
reject
)
});
});
}