check-node-version
Advanced tools
Comparing version 2.1.0 to 3.0.0
48
bin.js
@@ -22,22 +22,26 @@ #!/usr/bin/env node | ||
function logResult(result) { | ||
// report installed versions | ||
function printInstalledVersion(name, info) { | ||
if (info.version) { | ||
console.log(name + ": " + info.version); | ||
} | ||
if (info.notfound) { | ||
console.error(name + ': not installed'); | ||
} | ||
if (info.error) { | ||
logVersionError(name, info.error); | ||
} | ||
} | ||
function printVersions(result, print) { | ||
Object.keys(PROGRAMS).forEach(function(name) { | ||
var info = result[name]; | ||
if (info.version) { | ||
console.log(name + ": " + info.version); | ||
var info = result.versions[name]; | ||
var isSatisfied = info.isSatisfied; | ||
// report installed version | ||
if (print || !isSatisfied) { | ||
printInstalledVersion(name, info); | ||
} | ||
if (info.notfound) { | ||
console.error(name + ': not installed'); | ||
} | ||
if (info.error) { | ||
logVersionError(name, info.error); | ||
} | ||
}); | ||
// display any non-compliant versions | ||
Object.keys(PROGRAMS).forEach(function(name) { | ||
if (result[name].isSatisfied === false) { | ||
var raw = result[name].wanted.raw; | ||
var range = result[name].wanted.range; | ||
// display any non-compliant versions | ||
if (!isSatisfied) { | ||
var raw = info.wanted.raw; | ||
var range = info.wanted.range; | ||
console.log("Error: Wanted " + name + " version " + raw + " (" + range +")"); | ||
@@ -51,7 +55,7 @@ console.log(PROGRAMS[name].getInstallInstructions(raw)); | ||
alias: { | ||
"quiet": "q", | ||
"print": "p", | ||
"help": "h", | ||
}, | ||
boolean: [ | ||
"quiet", | ||
"print", | ||
"help", | ||
@@ -99,6 +103,4 @@ ], | ||
} | ||
if ( ! argv.quiet) { | ||
logResult(result); | ||
} | ||
printVersions(result, argv.print); | ||
process.exit(result.isSatisfied ? 0 : 1); | ||
}); |
43
index.js
@@ -54,3 +54,3 @@ "use strict"; | ||
return callback(null, { | ||
version: stdin.toString().trim(), | ||
version: stdin.toString().split('\n')[0].trim(), | ||
}); | ||
@@ -102,3 +102,3 @@ } | ||
}); | ||
parallel(commands, function(err, versions) { | ||
parallel(commands, function(err, versionsResult) { | ||
if (err) { | ||
@@ -108,30 +108,29 @@ callback(err); | ||
else { | ||
var retval = mapValues(PROGRAMS, function(program, name) { | ||
var name = name; | ||
var versions = mapValues(PROGRAMS, function(program, name) { | ||
var programInfo = {}; | ||
if (versions[name].error) { | ||
programInfo.error = versions[name].error; | ||
if (versionsResult[name].error) { | ||
programInfo.error = versionsResult[name].error; | ||
} | ||
if (versions[name].version) { | ||
programInfo.version = semver(versions[name].version); | ||
if (versionsResult[name].version) { | ||
programInfo.version = semver(versionsResult[name].version); | ||
} | ||
if (versions[name].notfound) { | ||
programInfo.notfound = versions[name].notfound; | ||
if (versionsResult[name].notfound) { | ||
programInfo.notfound = versionsResult[name].notfound; | ||
} | ||
programInfo.isSatisfied = true; | ||
if (wanted[name]) { | ||
programInfo.wanted = new semver.Range(wanted[name]); | ||
programInfo.isSatisfied = programInfo.version && semver.satisfies( | ||
programInfo.version, | ||
programInfo.wanted | ||
) || false; | ||
programInfo.isSatisfied = !! ( | ||
programInfo.version && | ||
semver.satisfies(programInfo.version, programInfo.wanted) | ||
); | ||
} | ||
return programInfo; | ||
}, {}); | ||
retval.isSatisfied = Object.keys(wanted).reduce(function(memo, name) { | ||
if (retval[name].isSatisfied !== false) { | ||
return memo; | ||
} | ||
return false; | ||
}, true); | ||
callback(null, retval); | ||
}); | ||
callback(null, { | ||
versions: versions, | ||
isSatisfied: Object.keys(wanted).every(function(name) { | ||
return versions[name].isSatisfied; | ||
}), | ||
}); | ||
} | ||
@@ -138,0 +137,0 @@ }); |
{ | ||
"name": "check-node-version", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Check installed versions of node and npm", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,5 +45,4 @@ # check-node-version | ||
-q, --quiet | ||
Don't output anything. Exit with an error code if a version | ||
is not satisfied, otherwise exit with code 0. | ||
-p, --print | ||
Print installed versions. | ||
@@ -56,40 +55,54 @@ -h, --help | ||
#### Get installed versions | ||
#### Check for node 6, failing | ||
When no versions are given, the current node, npm, and yarn versions are | ||
printed out. | ||
Check for node 6, but have 8.2.1 installed. | ||
``` | ||
$ check-node-version | ||
node: v0.12.7 | ||
npm: v2.14.10 | ||
yarn: v0.21.3 | ||
$ check-node-version --node 6 | ||
node: 8.2.1 | ||
Error: Wanted node version 6 (>=6.0.0 <7.0.0) | ||
To install node, run `nvm install 6` or see https://nodejs.org/ | ||
$ echo $? | ||
1 | ||
``` | ||
#### Check for node 6, passing | ||
If all versions match, there is no output: | ||
``` | ||
$ check-node-version --node 6 | ||
$ echo $? | ||
0 | ||
``` | ||
#### Check for `node@4` and `npm@2.14` | ||
#### Check for node *and* npm | ||
You can check versions of any combinations of `node`, `npm`, and `yarn` | ||
at one time. | ||
``` | ||
$ check-node-version --node 4 --npm 2.14 | ||
node: v0.12.7 | ||
npm: v2.14.10 | ||
yarn: v0.21.3 | ||
Error: Wanted node version "4" (>=4.0.0 <5.0.0) | ||
To install node, run `nvm install 4` or check https://nodejs.org/ | ||
$ echo $? | ||
1 | ||
``` | ||
#### Check for `node@4` and `npm@2.14`, `yarn` not installed | ||
#### Check for `node@4` and `npm@2.14` | ||
You can check for the version of yarn: | ||
``` | ||
$ check-node-version --node 4 --npm 2.14 | ||
$ check-node-version --yarn 0.17.1 | ||
``` | ||
#### Print installed versions | ||
Use the `--print` option to print all currently installed versions, even | ||
if the version checks match. | ||
``` | ||
$ check-node-version --print --node 0.12 | ||
node: v0.12.7 | ||
npm: v2.14.10 | ||
yarn: not installed | ||
Error: Wanted node version "4" (>=4.0.0 <5.0.0) | ||
To install node, run `nvm install 4` or check https://nodejs.org/ | ||
yarn: v0.21.3 | ||
$ echo $? | ||
1 | ||
0 | ||
``` | ||
@@ -96,0 +109,0 @@ |
57
test.js
@@ -28,8 +28,7 @@ "use strict"; | ||
t.ifError(err); | ||
t.ok(result.node); | ||
t.ok(result.node.version); | ||
t.ok(result.npm); | ||
t.ok(result.npm.version); | ||
t.ok(result.yarn); | ||
t.ok(result.yarn.version); | ||
t.ok(result.versions.node); | ||
t.ok(result.versions.node.version); | ||
t.ok(result.versions.npm); | ||
t.ok(result.versions.npm.version); | ||
t.ok(result.versions.yarn); | ||
t.ok(result.isSatisfied); | ||
@@ -50,7 +49,7 @@ t.end(); | ||
t.ifError(err); | ||
t.ok(result.node); | ||
t.ok(result.node.version); | ||
t.equal(result.node.version.raw, version); | ||
t.equal(result.node.wanted.range, version); | ||
t.equal(result.node.isSatisfied, true); | ||
t.ok(result.versions.node); | ||
t.ok(result.versions.node.version); | ||
t.equal(result.versions.node.version.raw, version); | ||
t.equal(result.versions.node.wanted.range, version); | ||
t.equal(result.versions.node.isSatisfied, true); | ||
t.equal(result.isSatisfied, true); | ||
@@ -71,6 +70,6 @@ t.end(); | ||
t.ifError(err); | ||
t.ok(result.node); | ||
t.equal(result.node.version.raw, version); | ||
t.equal(result.node.wanted.range, "6.9.9"); | ||
t.equal(result.node.isSatisfied, false); | ||
t.ok(result.versions.node); | ||
t.equal(result.versions.node.version.raw, version); | ||
t.equal(result.versions.node.wanted.range, "6.9.9"); | ||
t.equal(result.versions.node.isSatisfied, false); | ||
t.equal(result.isSatisfied, false); | ||
@@ -92,9 +91,9 @@ t.end(); | ||
t.ifError(err); | ||
t.ok(result.node); | ||
t.equal(result.node.version.raw, version); | ||
t.equal(result.node.wanted.range, version); | ||
t.equal(result.node.isSatisfied, true); | ||
t.ok(result.versions.node); | ||
t.equal(result.versions.node.version.raw, version); | ||
t.equal(result.versions.node.wanted.range, version); | ||
t.equal(result.versions.node.isSatisfied, true); | ||
t.equal(result.isSatisfied, true); | ||
t.equal(result.yarn.version, undefined); | ||
t.ok(result.yarn.error); | ||
t.equal(result.versions.yarn.version, undefined); | ||
t.ok(result.versions.yarn.error); | ||
t.end(); | ||
@@ -115,8 +114,8 @@ }); | ||
t.ifError(err); | ||
t.ok(result.node); | ||
t.equal(result.node.version.raw, "7.0.0"); | ||
t.equal(result.node.wanted.range, "6.9.9"); | ||
t.equal(result.node.isSatisfied, false); | ||
t.equal(result.yarn.version, undefined); | ||
t.ok(result.yarn.error); | ||
t.ok(result.versions.node); | ||
t.equal(result.versions.node.version.raw, "7.0.0"); | ||
t.equal(result.versions.node.wanted.range, "6.9.9"); | ||
t.equal(result.versions.node.isSatisfied, false); | ||
t.equal(result.versions.yarn.version, undefined); | ||
t.ok(result.versions.yarn.error); | ||
t.equal(result.isSatisfied, false); | ||
@@ -138,4 +137,4 @@ t.end(); | ||
t.ifError(err); | ||
t.equal(result.yarn.version, undefined); | ||
t.equal(result.yarn.wanted.range, "1.1.1"); | ||
t.equal(result.versions.yarn.version, undefined); | ||
t.equal(result.versions.yarn.wanted.range, "1.1.1"); | ||
t.equal(result.isSatisfied, false); | ||
@@ -142,0 +141,0 @@ t.end(); |
@@ -21,7 +21,6 @@ Usage: check-node-version [OPTIONS] | ||
-q, --quiet | ||
Don't output anything. Exit with an error code if a version | ||
is not satisfied, otherwise exit with code 0. | ||
-p, --print | ||
Print installed versions. | ||
-h, --help | ||
Print this message. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14654
9
132