From bbda55851b7ac1ce685bcbd68bd45cfd7a3b0e41 Mon Sep 17 00:00:00 2001 From: pqcqaq <905739777@qq.com> Date: Mon, 18 Aug 2025 14:08:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E9=99=90=E5=88=B6=E4=B8=8E=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmrc | 1 + lib/index.js | 16 ++-------------- lib/server/start.js | 1 + lib/utils.d.ts | 6 ++++++ lib/utils.js | 23 +++++++++++++++++++++++ package.json | 4 ++++ src/index.ts | 19 ++----------------- src/server/start.ts | 5 ++++- src/utils.ts | 30 ++++++++++++++++++++++++++++++ 9 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..4fd0219 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +engine-strict=true \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 069315d..3eb2f60 100755 --- a/lib/index.js +++ b/lib/index.js @@ -13,6 +13,7 @@ const clean_1 = tslib_1.__importDefault(require("./clean")); const config_1 = require("./config"); const tip_style_1 = require("./tip-style"); const rename_1 = require("./rename"); +const utils_1 = require("./utils"); /** * @name 未知参数错误提示 * @param {string} methodName @@ -29,20 +30,7 @@ function enhanceErrorMessages(methodName, log) { process.exit(-1); }; } -const currentNodeVersion = process.versions.node; -const semver = currentNodeVersion.split('.'); -const major = semver[0]; -const minNodeVersion = 16; -if (Number(major) < minNodeVersion) { - console.error('You are running Node ' + - currentNodeVersion + - '.\n' + - 'Create React App requires Node ' + - minNodeVersion + - ' or higher. \n' + - 'Please update your version of Node.'); - process.exit(-1); -} +(0, utils_1.checkNodeVersion)(); commander_1.default.version(config_1.CLI_VERSION, '-v, --version').usage(' [options]'); commander_1.default .command('make:domain') diff --git a/lib/server/start.js b/lib/server/start.js index f6c6429..b698149 100644 --- a/lib/server/start.js +++ b/lib/server/start.js @@ -23,6 +23,7 @@ const koa_mount_1 = tslib_1.__importDefault(require("koa-mount")); const chalk_1 = tslib_1.__importDefault(require("chalk")); const utils_1 = require("../utils"); const bcryptjs_1 = tslib_1.__importDefault(require("bcryptjs")); +(0, utils_1.checkNodeVersion)(); const socketAdminUI = (0, path_1.join)(__dirname, '../../ui/socket-admin'); const DATA_SUBSCRIBE_NAMESPACE = '/dsn'; const SOCKET_NAMESPACE = '/sn'; diff --git a/lib/utils.d.ts b/lib/utils.d.ts index 2b94a7b..3392efa 100644 --- a/lib/utils.d.ts +++ b/lib/utils.d.ts @@ -64,3 +64,9 @@ export declare function deWeight(arr: Array | Set, type: any): Set=20.0.0", + "npm": ">=10.0.0" } } diff --git a/src/index.ts b/src/index.ts index f4ad0c6..d688298 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ import clean from './clean'; import { CLI_VERSION, CLI_NAME } from './config'; import { error, warn } from './tip-style'; import { rename } from './rename'; +import { checkNodeVersion } from './utils'; /** * @name 未知参数错误提示 @@ -28,23 +29,7 @@ function enhanceErrorMessages(methodName: string, log: Function) { }; } -const currentNodeVersion = process.versions.node; -const semver = currentNodeVersion.split('.'); -const major = semver[0]; -const minNodeVersion = 16; - -if (Number(major) < minNodeVersion) { - console.error( - 'You are running Node ' + - currentNodeVersion + - '.\n' + - 'Create React App requires Node ' + - minNodeVersion + - ' or higher. \n' + - 'Please update your version of Node.' - ); - process.exit(-1); -} +checkNodeVersion() program.version(CLI_VERSION, '-v, --version').usage(' [options]'); diff --git a/src/server/start.ts b/src/server/start.ts index d97b8b4..e1afd75 100644 --- a/src/server/start.ts +++ b/src/server/start.ts @@ -23,9 +23,11 @@ import { instrument } from "@socket.io/admin-ui"; import serve from 'koa-static'; import mount from 'koa-mount'; import chalk from 'chalk'; -import { randomString } from '../utils'; +import { checkNodeVersion, randomString } from '../utils'; import bcrypt from 'bcryptjs'; +checkNodeVersion() + const socketAdminUI = join(__dirname, '../../ui/socket-admin'); const DATA_SUBSCRIBE_NAMESPACE = '/dsn'; @@ -33,6 +35,7 @@ const SOCKET_NAMESPACE = '/sn'; const SERVER_SUBSCRIBER_NAMESPACE = process.env.OAK_SSUB_NAMESPACE || '/ssub'; const ExceptionMask = '内部不可知错误'; + function concat(...paths: string[]) { return paths.reduce( (prev, current) => { diff --git a/src/utils.ts b/src/utils.ts index a18c51d..f5d9743 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,6 @@ +import chalk from "chalk" + /** * @name 从一组路径里查找到所有json文件 * @export @@ -111,4 +113,32 @@ export function randomString(length: number): string { result += chars[randomIndex]; } return result; +} + +/** + * @name 检查当前nodejs运行时版本 + * @export + * @throws 当版本不满足最低要求时抛出异常 + */ +export function checkNodeVersion(){ + const currentNodeVersion = process.versions.node; + const semver = currentNodeVersion.split('.'); + const major = semver[0]; + const minNodeVersion = 20; + + if (Number(major) < minNodeVersion) { + console.error( + chalk.yellow( + 'You are running Node ' + + currentNodeVersion + '.\n' + ) + + chalk.red( + 'Oak-cli requires Node ' + + minNodeVersion + + ' or higher. \n' + + 'Please update your version of Node.' + ) + ); + process.exit(-1); + } } \ No newline at end of file