Skip to content

Commit

Permalink
chore: script to bump supported node versions
Browse files Browse the repository at this point in the history
No change to node support, this just adds a script.

This adds a script to check that we correctly configure all supported
node versions, since we need to update quite a few spots (README.md,
package.json, travis, appveyor).

Issue shelljs/shelljs#873
Test: manual
  • Loading branch information
nfischer committed Dec 2, 2018
1 parent 062e50a commit 9c090d5
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -14,6 +14,7 @@ os:
- osx
script:
- npm test
- npm run check-node-support
after_success:
- npm run codecov -- -f coverage/lcov.info

Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,8 @@
commands, providing an easy solution for simple Unix-like, cross-platform
commands in npm package scripts.

`shx` is proudly tested on every node release since <!-- start minVersion -->`v4`<!-- stop minVersion -->!

## Difference Between ShellJS and shx

- **ShellJS:** Good for writing long scripts, all in JS, running via NodeJS (e.g. `node myScript.js`).
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -9,6 +9,7 @@
"lib"
],
"scripts": {
"check-node-support": "node scripts/check-node-support",
"prebuild": "rimraf lib",
"build": "babel src -d lib",
"build:watch": "npm run build -- -w",
Expand Down Expand Up @@ -59,6 +60,7 @@
"eslint": "^2.10.1",
"eslint-config-airbnb-base": "^3.0.1",
"eslint-plugin-import": "^1.8.0",
"js-yaml": "^3.12.0",
"mocha": "^5.2.0",
"nyc": "^11.0.0",
"rimraf": "^2.5.2",
Expand Down
88 changes: 88 additions & 0 deletions scripts/check-node-support.js
@@ -0,0 +1,88 @@
#!/usr/bin/env node

var assert = require('assert');
var path = require('path');

var yaml = require('js-yaml');

var shell = require('shelljs');

// This is the authoritative list of supported node versions.
var MIN_NODE_VERSION = 4;
var MAX_NODE_VERSION = 10;

function checkReadme(minNodeVersion) {
var start = '<!-- start minVersion -->';
var stop = '<!-- stop minVersion -->';
var formattedMinVersion = '`v' + minNodeVersion + '`';
var expectedReadmeRegex = new RegExp(
start + '\\s*' + formattedMinVersion + '\\s*' + stop, '');
var readme = path.join(__dirname, '..', 'README.md');
var match = shell.grep(expectedReadmeRegex, readme);
if (!match.toString()) {
var msg = 'Update README to specify the min supported version. Look for "'
+ start + '"';
throw new Error(msg);
}
}

function checkEngines(minNodeVersion, package) {
var expectedEnginesNode = '>=' + minNodeVersion;
if (package.engines.node !== expectedEnginesNode) {
var msg = 'Update package.json to fix the "engines" attribute';
throw new Error(msg);
}
}

function assertDeepEquals(arr1, arr2, msg) {
try {
assert.deepStrictEqual(arr1, arr2);
} catch (e) {
throw new Error(msg + '\n' + e);
}
}

function range(start, stop) {
var ret = [];
for (var i = start; i <= stop; i++) {
ret.push(i);
}
return ret;
}

function checkTravis(minNodeVersion, maxNodeVersion, travisYaml) {
var expectedTravisVersions = range(minNodeVersion, maxNodeVersion);
var msg = 'Check Travis node_js versions';
assertDeepEquals(travisYaml.node_js, expectedTravisVersions, msg);
}

function checkAppveyor(minNodeVersion, maxNodeVersion, appveyorYaml) {
var expectedAppveyorVersions = range(minNodeVersion, maxNodeVersion)
.map(function (num) {
return { nodejs_version: num.toString() };
})
.reverse(); // Arbitrarily, we store appveyor in reverse order.
var msg = 'Check Appveyor environment.matrix versions';
assertDeepEquals(appveyorYaml.environment.matrix, expectedAppveyorVersions,
msg);
}

try {
checkReadme(MIN_NODE_VERSION);

var package = require('../package.json');
checkEngines(MIN_NODE_VERSION, package);

var travisFileName = path.join(__dirname, '..', '.travis.yml');
var travisYaml = yaml.safeLoad(shell.cat(travisFileName));
checkTravis(MIN_NODE_VERSION, MAX_NODE_VERSION, travisYaml);

var appveyorFileName = path.join(__dirname, '..', 'appveyor.yml');
var appveyorYaml = yaml.safeLoad(shell.cat(appveyorFileName));
checkAppveyor(MIN_NODE_VERSION, MAX_NODE_VERSION, appveyorYaml);
} catch (e) {
console.error('Please check the files which declare our Node version');
console.error('support, as something is out-of-sync. This script failed');
console.error('specificaly because:');
throw e;
}

0 comments on commit 9c090d5

Please sign in to comment.