Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions verify-node-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,35 @@ var os = require("os"),
var versionsCausingFailure = ["0.10.34", "4.0.0", "4.2.0", "5.0.0"];
var minimumRequiredVersion = "4.2.1";

export function verifyNodeVersion(supportedVersionsRange: string, cliName: string): void {
export function verifyNodeVersion(supportedVersionsRange: string, cliName: string, deprecatedVersions?: string[]): void {
// The colors module should not be assigned to variable because the lint task will fail for not used variable.
require("colors");

var nodeVer = process.version.substr(1);
var nodeVer = process.version.substr(1),
isNodeVersionDeprecated = false;

if (versionsCausingFailure.indexOf(nodeVer) !== -1 || !semver.valid(nodeVer) || semver.lt(nodeVer, minimumRequiredVersion)) {
console.error(util.format("%sNode.js '%s' is not supported. To be able to work with %s CLI, install any Node.js version in the following range: %s.%s",
os.EOL, nodeVer, cliName, supportedVersionsRange, os.EOL).red.bold);
os.EOL, nodeVer, cliName, supportedVersionsRange, os.EOL).red.bold);
process.exit(1);
}

var checkSatisfied = semver.satisfies(nodeVer, supportedVersionsRange);
if (!checkSatisfied) {
console.log(util.format("%sSupport for Node.js %s is not verified. This CLI might not install or run properly.%s", os.EOL, nodeVer, os.EOL).yellow.bold);
if (deprecatedVersions) {
deprecatedVersions.forEach(version => {
if (semver.satisfies(nodeVer, version)) {
var message = os.EOL + "Support for Node.js " + version + " is deprecated and will be removed in the next release of " + cliName + ". Please, upgrade to the latest Node.js LTS version. " + os.EOL ;
console.warn(message.yellow.bold);
isNodeVersionDeprecated = true;
return false;
}
});
}

if (!isNodeVersionDeprecated) {
var checkSatisfied = semver.satisfies(nodeVer, supportedVersionsRange);
if (!checkSatisfied) {
console.log(util.format("%sSupport for Node.js %s is not verified. This CLI might not install or run properly.%s", os.EOL, nodeVer, os.EOL).yellow.bold);
}
}
}
/* tslint:enable */