From 4522d623b198cb10d1302062f490ec140d5e4143 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Thu, 19 Jan 2017 23:57:43 +0200 Subject: [PATCH] Add default message when a node.js version is deprecated In method `verifyNodeVersion`, which is called at the beginning of each CLI, sometimes we have to inform the user that we'll stop support of specific range of Node.js versions in the next release. So add the logic in the method and each CLI can specify deprecated versions in case it has to. --- verify-node-version.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/verify-node-version.ts b/verify-node-version.ts index 1ece82b1..4d179d5f 100644 --- a/verify-node-version.ts +++ b/verify-node-version.ts @@ -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 */