-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck.js
24 lines (20 loc) · 795 Bytes
/
check.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
module.exports = function(v) {
var package = require('./package.json');
var version = package.version.split('.').map(function(x) { return parseInt(x); });
var installedVersion = ('' + v).split('.').map(function(x) { return parseInt(x); });
var valid = true;
for (var i = 0; i < installedVersion.length; i++) {
if (installedVersion[i] != installedVersion[i]) {
throw "Invalid version: v" + installedVersion.join('.');
}
if (installedVersion[i] < version[i]) {
valid = false;
break;
}
}
if (!valid) {
var message = "Error: this package requires NPM v" + version.join('.') +
". You have v" + installedVersion.join('.') + " installed.";
throw message;
}
};