-
Notifications
You must be signed in to change notification settings - Fork 2
/
check-version.js
50 lines (36 loc) · 1.19 KB
/
check-version.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
const package = require('./package.json')
const current_version = `${process.version.substr(1,process.version.length)}`,
expected_version = `${package.engines.node.substr(2,package.engines.node.length)}`;
if(!compare(current_version,expected_version)){
console.error(`Node 8.10.0 or later is required.`);
process.exit(1);
}
// comparing node version
function compare(a, b) {
if (a === b) {
return true;
}
var a_components = a.split(".");
var b_components = b.split(".");
var len = Math.min(a_components.length, b_components.length);
// loop while the components are equal
for (var i = 0; i < len; i++) {
// A bigger than B
if (parseInt(a_components[i]) > parseInt(b_components[i])) {
return true;
}
// B bigger than A
if (parseInt(a_components[i]) < parseInt(b_components[i])) {
return false;
}
}
// If one's a prefix of the other, the longer one is greater.
if (a_components.length >= b_components.length) {
return true;
}
if (a_components.length < b_components.length) {
return false;
}
// Otherwise they are the same.
return true;
}