-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckver
More file actions
executable file
·32 lines (25 loc) · 850 Bytes
/
checkver
File metadata and controls
executable file
·32 lines (25 loc) · 850 Bytes
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
#!/usr/bin/env node
var op = process.argv[2].match(/^([gl])([te])$/);
var wanted = (process.argv[3] || '').split('.');
var version = process.versions.node.split('.');
if(!op || wanted.length != 3) {
console.log([
'usage:',
process.argv[0].replace(/.*\//, ''),
process.argv[1].replace(/.*\//, ''),
'op',
'x.y.z'
].join(' '));
console.log('\nCompare Node.js version.');
console.log('Following op codes determine whether it must be:\n');
console.log('\tgt\tGreater than x.y.z.');
console.log('\tge\tGreater than or equal to x.y.z.');
console.log('\tlt\tLess than x.y.z.');
console.log('\tle\tLess than or equal to x.y.z.');
process.exit(1);
}
for(var i = 0; i < 3; ++i) {
if(+version[i] > +wanted[i]) process.exit(+(op[1] != 'g'));
if(+version[i] < +wanted[i]) process.exit(+(op[1] == 'g'));
}
process.exit(+(op[2] != 'e'));