-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpackage-test.js
69 lines (64 loc) · 1.8 KB
/
package-test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const package = require('./package.json');
const packageTheme = require('./themes/mew5/package.json');
const packageJson = require('package-json');
const SAFE_TIME = 1000 * 1 * 60 * 60 * 24 * 7; //7days
const EXCEPTIONS = [];
const CUSTOM_DIST = {
['babel-core']: 'bridge'
};
const runCheck = (packages) => {
return new Promise((resolve) => {
const ALL_PACKAGES = Object.assign(
{},
packages.dependencies,
packages.devDependencies
);
const names = Object.keys(ALL_PACKAGES);
let updatesFound = false;
const looper = () => {
if (!names.length) {
if (updatesFound) {
resolve(false);
return;
} //process.exit(1);
else {
resolve(true);
return;
} //process.exit(0);
}
const _name = names.shift();
if (EXCEPTIONS.includes(_name)) return looper();
packageJson(_name, {
fullMetadata: true,
allVersions: true
})
.then(info => {
const latestVersion = info['dist-tags'][CUSTOM_DIST[_name] || 'latest'];
const latestVersionTime = info['time'][latestVersion];
if (
![latestVersion, `^${latestVersion}`, `~${latestVersion}`].includes(ALL_PACKAGES[_name]) &&
new Date(latestVersionTime).getTime() < new Date().getTime() - SAFE_TIME
) {
console.error(
'new update found',
_name,
ALL_PACKAGES[_name],
latestVersion,
latestVersionTime
);
updatesFound = true;
}
})
.then(looper);
};
looper();
});
};
runCheck(package)
.then(res1 => {
runCheck(packageTheme)
.then(res2 => {
if (!res1 || !res2) process.exit(1);
else process.exit(0);
});
});