@strategy-lab/cli 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/strategy-lab.mjs +21 -1
- package/dist/main.js +146 -141
- package/package.json +2 -2
package/bin/strategy-lab.mjs
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
const { engines } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
5
|
+
const required = engines.node;
|
|
6
|
+
const minimum = /^>=(\d+)\.(\d+)\.(\d+)$/.exec(required);
|
|
7
|
+
if (!minimum) throw new Error(`无法识别 Strategy Lab CLI 声明的 Node.js 最低版本:${required}`);
|
|
8
|
+
|
|
9
|
+
const actual = process.versions.node;
|
|
10
|
+
const comparison = actual
|
|
11
|
+
.split('.', 3)
|
|
12
|
+
.reduce(
|
|
13
|
+
(result, component, index) => result || parseInt(component, 10) - Number(minimum[index + 1]),
|
|
14
|
+
0,
|
|
15
|
+
);
|
|
16
|
+
if (comparison < 0 || (comparison === 0 && actual.includes('-'))) {
|
|
17
|
+
process.stderr.write(`Strategy Lab CLI 需要 Node.js ${required};当前版本是 ${actual}。\n`);
|
|
18
|
+
process.exitCode = 1;
|
|
19
|
+
} else {
|
|
20
|
+
// 低版本必须先收到版本诊断,不能加载 CLI 的依赖。
|
|
21
|
+
await import('@strategy-lab/cli/run');
|
|
22
|
+
}
|