feat: show a message to upgrade node when needed (#999)

This commit is contained in:
Li Kang
2022-11-11 14:11:33 +01:00
committed by GitHub
parent 72e400f368
commit caa417464e
7 changed files with 40 additions and 7 deletions

View File

@@ -27,7 +27,7 @@ If the proposal includes new designs or bigger changes, please be prepared to di
### Prerequisites
- [Node.js](https://nodejs.org/) 10+ and [yarn](https://yarnpkg.com) 1.9.4 installed
- [Node.js](https://nodejs.org/) 18.10.0+ and [yarn](https://yarnpkg.com) 1+ installed
### Project structure

View File

@@ -1,11 +1,10 @@
#!/usr/bin/env node
const yargs = require('yargs');
const importCwd = require('import-cwd');
const checkNodeVersion = require('../utils/checkNodeVersion');
const pkg = require('../package.json');
// const build = require('@nebula.js/cli-build/command');
// const create = require('@nebula.js/cli-create/command');
// const serve = require('@nebula.js/cli-serve/command');
// const sense = require('@nebula.js/cli-sense/command');
checkNodeVersion(pkg);
yargs.usage('nebula <command> [options]');

View File

@@ -15,6 +15,9 @@
"files": [
"lib"
],
"engines": {
"node": ">=18.10.0"
},
"bin": {
"nebula": "lib/index.js"
},

View File

@@ -0,0 +1,28 @@
function checkNodeVersion(pkg) {
if (pkg.engines && pkg.engines.node) {
const minVersion = pkg.engines.node.replace('>=', '');
const [minMajor, minMinor, minPatch] = minVersion.split('.').map(Number);
const currentVersion = process.versions.node;
const [currentMajor, currentMinor, currentPatch] = currentVersion.split('.').map(Number);
let validVersion = true;
if (currentMajor < minMajor) {
validVersion = false;
} else if (currentMajor === minMajor) {
if (currentMinor < minMinor) {
validVersion = false;
}
if (currentMinor === minMinor && currentPatch < minPatch) {
validVersion = false;
}
}
if (!validVersion) {
// eslint-disable-next-line no-console
console.error(`${pkg.name} requires NodeJS >= ${minVersion}, but you are using NodeJS ${currentVersion}.`);
process.exit(1);
}
}
}
module.exports = checkNodeVersion;

View File

@@ -10,7 +10,7 @@
"keywords": ["qlik", "nebula", "stardust"],
"files": ["dist"],
"engines": {
"node": ">=18"
"node": ">=18.10.0"
},
"main": "dist/<%= name %>.js",
"module": "dist/<%= name %>.esm.js",

View File

@@ -10,7 +10,7 @@
"keywords": ["qlik", "nebula", "stardust"],
"files": ["dist"],
"engines": {
"node": ">=18"
"node": ">=18.10.0"
},
"main": "dist/<%= name %>.js",
"module": "dist/<%= name %>.esm.js",

View File

@@ -20,6 +20,9 @@
"dist",
"lib"
],
"engines": {
"node": ">=18.10.0"
},
"scripts": {
"build": "cross-env NODE_ENV=production DEFAULTS=true webpack --config ./lib/webpack.build.js",
"build:dev": "cross-env NODE_ENV=development DEFAULTS=true webpack --config ./lib/webpack.build.js",