-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathnode_version_check.js
25 lines (20 loc) · 1.21 KB
/
node_version_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
25
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2022 Posit Software, PBC. All rights reserved.
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
*--------------------------------------------------------------------------------------------*/
const fs = require('fs');
const version = process.versions.node;
const currentVersionString = `Node version: ${version}`;
const major = parseInt(version.split('.')[0]);
const minor = parseInt(version.split('.')[1]);
const recommendedVersion = fs.readFileSync('.nvmrc').toString().trim();
const recommendedMajor = parseInt(recommendedVersion.split('.')[0]);
const recommendedMinor = parseInt(recommendedVersion.split('.')[1]);
if (major === recommendedMajor && minor === recommendedMinor) {
console.log(currentVersionString);
} else if (major === recommendedMajor) {
console.log(`${currentVersionString} (${recommendedVersion} is recommended)`);
} else { // mismatched major version of node, print a warning to the terminal in red
console.warn(`\x1b[31m${currentVersionString} may not be supported\x1b[0m`);
console.warn(`\x1b[31mConsider using node version ${recommendedVersion}\x1b[0m`);
}