Skip to content

Commit 29efca4

Browse files
authored
Add node preFlight checks to CLI (#2892)
* Add a new file preFlightChecks to contain check * Add a preAction hook to run the checks before invoking any command
1 parent b3b90c8 commit 29efca4

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎package-lock.json‎

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/cli/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { build } from './src/cmd/build.js';
88
import { deploy } from './src/cmd/deploy.js';
99
import { init } from './src/cmd/init.js';
1010
import { serve } from './src/cmd/serve.js';
11+
import { preFlightChecks } from './src/util/preFlightChecks.js';
1112
import packageJson from './package.json' with { type: 'json' };
1213

1314
const CLI_VERSION = packageJson.version;
@@ -23,6 +24,9 @@ function printHeader() {
2324
return '';
2425
}
2526

27+
program
28+
.hook('preAction', () => preFlightChecks());
29+
2630
program
2731
.addHelpText('beforeAll', printHeader())
2832
.showHelpAfterError('(run "markbind --help" to list commands)')

‎packages/cli/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"fs-extra": "^9.0.1",
4646
"live-server": "1.2.1",
4747
"lodash": "^4.17.15",
48+
"semver": "^7.7.4",
4849
"url-parse": "^1.5.10",
4950
"winston": "^3.19.0",
5051
"winston-daily-rotate-file": "^5.0.0"
@@ -53,6 +54,7 @@
5354
"@babel/core": "^7.29.0",
5455
"@babel/preset-env": "^7.29.0",
5556
"@babel/preset-typescript": "^7.28.5",
57+
"@types/semver": "^7.7.1",
5658
"@types/jest": "^29.4.6",
5759
"@types/lodash": "^4.17.15",
5860
"@types/url-parse": "^1.4.8",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as semver from 'semver';
2+
import * as logger from './logger.js';
3+
import packageJson from '../../package.json' with { type: 'json' };
4+
5+
const CLI_VERSION = packageJson.version;
6+
const REQUIRED_NODE_VERSION = '22.12.0';
7+
8+
function checkNode() {
9+
const nodeVersion = process.version;
10+
const version = semver.coerce(nodeVersion);
11+
12+
if (version === null) {
13+
logger.warn('Unknown version of node detected.');
14+
return;
15+
}
16+
if (semver.lt(version, REQUIRED_NODE_VERSION)) {
17+
logger.error(
18+
`Markbind ${CLI_VERSION} requires node >=${REQUIRED_NODE_VERSION}. `
19+
+ 'Please update node or use an older version of Markbind!',
20+
);
21+
process.exit(1);
22+
}
23+
}
24+
25+
/**
26+
* Performs pre-usage checks to ensure the application will run as expected.
27+
* This method may exit the process if checks fail.
28+
*/
29+
export function preFlightChecks() {
30+
checkNode();
31+
}

0 commit comments

Comments
 (0)