feat: 添加版本限制与检查
This commit is contained in:
parent
342ad61fc0
commit
bbda55851b
16
lib/index.js
16
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('<command> [options]');
|
||||
commander_1.default
|
||||
.command('make:domain')
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -64,3 +64,9 @@ export declare function deWeight(arr: Array<any> | Set<any>, type: any): Set<any
|
|||
* @returns {string}
|
||||
*/
|
||||
export declare function randomString(length: number): string;
|
||||
/**
|
||||
* @name 检查当前nodejs运行时版本
|
||||
* @export
|
||||
* @throws 当版本不满足最低要求时抛出异常
|
||||
*/
|
||||
export declare function checkNodeVersion(): void;
|
||||
|
|
|
|||
23
lib/utils.js
23
lib/utils.js
|
|
@ -8,6 +8,9 @@ exports.union = union;
|
|||
exports.formatJsonByFile = formatJsonByFile;
|
||||
exports.deWeight = deWeight;
|
||||
exports.randomString = randomString;
|
||||
exports.checkNodeVersion = checkNodeVersion;
|
||||
const tslib_1 = require("tslib");
|
||||
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
||||
/**
|
||||
* @name 从一组路径里查找到所有json文件
|
||||
* @export
|
||||
|
|
@ -112,3 +115,23 @@ function randomString(length) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @name 检查当前nodejs运行时版本
|
||||
* @export
|
||||
* @throws 当版本不满足最低要求时抛出异常
|
||||
*/
|
||||
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_1.default.yellow('You are running Node ' +
|
||||
currentNodeVersion + '.\n') +
|
||||
chalk_1.default.red('Oak-cli requires Node ' +
|
||||
minNodeVersion +
|
||||
' or higher. \n' +
|
||||
'Please update your version of Node.'));
|
||||
process.exit(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,5 +154,9 @@
|
|||
"webpack-manifest-plugin": "^4.0.2",
|
||||
"webpackbar": "^7.0.0",
|
||||
"workbox-webpack-plugin": "^6.4.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0",
|
||||
"npm": ">=10.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
src/index.ts
19
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('<command> [options]');
|
||||
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
30
src/utils.ts
30
src/utils.ts
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
import chalk from "chalk"
|
||||
|
||||
/**
|
||||
* @name 从一组路径里查找到所有json文件
|
||||
* @export
|
||||
|
|
@ -112,3 +114,31 @@ export function randomString(length: number): string {
|
|||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue