Merge branch 'release'
This commit is contained in:
commit
171bb7ad96
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')
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ import { Connector, EntityDict } from 'oak-domain/lib/types';
|
|||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
|
||||
export declare function startup<ED extends EntityDict & BaseEntityDict, FrontCxt extends SyncContext<ED>, Cxt extends BackendRuntimeContext<ED>>(path: string, connector: Connector<ED, FrontCxt>, omitWatchers?: boolean, omitTimers?: boolean, routine?: (context: AsyncContext<ED>) => Promise<void>): Promise<(() => Promise<void>) | undefined>;
|
||||
export declare function startup<ED extends EntityDict & BaseEntityDict, FrontCxt extends SyncContext<ED>, Cxt extends BackendRuntimeContext<ED>>(path: string, connector: Connector<ED, FrontCxt>, omitWatchers?: boolean, omitTimers?: boolean, routine?: (context: AsyncContext<ED>) => Promise<void>): Promise<(() => Promise<any>) | any>;
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
@ -147,7 +148,7 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
|
|||
auth: {
|
||||
type: "basic",
|
||||
username: ui?.username || "admin",
|
||||
password: bcryptjs_1.default.hashSync(passwordForAdminUI, 10), // 使用 bcrypt 加密密码
|
||||
password: bcryptjs_1.default.hashSync(passwordForAdminUI, 10), // 必须使用 bcrypt 加密之后的密码
|
||||
},
|
||||
mode: process.env.NODE_ENV === 'production' ? "production" : "development", // 根据环境设置模式
|
||||
});
|
||||
|
|
@ -159,8 +160,9 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
|
|||
await appLoader.execStartRoutines();
|
||||
if (routine) {
|
||||
// 如果传入了routine,执行完成后就结束
|
||||
await appLoader.execRoutine(routine);
|
||||
return;
|
||||
const result = await appLoader.execRoutine(routine);
|
||||
await appLoader.unmount();
|
||||
return result;
|
||||
}
|
||||
// 否则启动服务器模式
|
||||
koa.use(async (ctx, next) => {
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
|
|||
"server:init": "${serverInitScript}",
|
||||
"server:start": "${serverStartWatchScript}",
|
||||
"server:ana": "cross-env ENABLE_TRACE=true cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node --stack-size=65500 scripts/analysis.js",
|
||||
"postinstall": "npm run make:dep"
|
||||
"postinstall": "npm run make:dep",
|
||||
"upgrade:locale": "node scripts/upgradeI18n.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
25
lib/utils.js
25
lib/utils.js
|
|
@ -1,6 +1,8 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.randomString = exports.deWeight = exports.formatJsonByFile = exports.union = exports.intersect = exports.difference = exports.getStr = exports.findJson = void 0;
|
||||
exports.checkNodeVersion = exports.randomString = exports.deWeight = exports.formatJsonByFile = exports.union = exports.intersect = exports.difference = exports.getStr = exports.findJson = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
||||
/**
|
||||
* @name 从一组路径里查找到所有json文件
|
||||
* @export
|
||||
|
|
@ -113,3 +115,24 @@ function randomString(length) {
|
|||
return result;
|
||||
}
|
||||
exports.randomString = randomString;
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
exports.checkNodeVersion = checkNodeVersion;
|
||||
|
|
|
|||
10
package.json
10
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@xuchangzju/oak-cli",
|
||||
"version": "4.0.24",
|
||||
"version": "4.0.25",
|
||||
"description": "client for oak framework",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
|
|
@ -60,7 +60,7 @@
|
|||
"babel-loader": "^8.2.3",
|
||||
"babel-plugin-named-asset-import": "^0.3.8",
|
||||
"babel-preset-react-app": "^10.0.1",
|
||||
"bcrypt": "^5.1.1",
|
||||
"bcryptjs": "^3.0.2",
|
||||
"bfj": "^7.0.2",
|
||||
"browser-assert": "^1.2.1",
|
||||
"browserify-sign": "4.2.2",
|
||||
|
|
@ -112,7 +112,7 @@
|
|||
"lodash": "^4.17.21",
|
||||
"mini-css-extract-plugin": "^2.5.3",
|
||||
"node-watch": "^0.7.4",
|
||||
"oak-backend-base": "^4.1.20",
|
||||
"oak-backend-base": "^4.1.21",
|
||||
"oak-domain": "^5.1.27",
|
||||
"oak-frontend-base": "^5.3.34",
|
||||
"parse-asn1": "5.1.6",
|
||||
|
|
@ -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) => {
|
||||
|
|
@ -50,7 +53,7 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
|||
omitWatchers?: boolean,
|
||||
omitTimers?: boolean,
|
||||
routine?: (context: AsyncContext<ED>) => Promise<void>,
|
||||
): Promise<(() => Promise<void>) | undefined> {
|
||||
): Promise<(() => Promise<any>) | any> {
|
||||
const serverConfiguration: ServerConfiguration = require(join(
|
||||
path,
|
||||
'lib',
|
||||
|
|
@ -172,7 +175,7 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
|||
auth: {
|
||||
type: "basic", // 使用基本认证,生产建议关闭或换成自定义 auth
|
||||
username: ui?.username || "admin",
|
||||
password: bcrypt.hashSync(passwordForAdminUI, 10), // 使用 bcrypt 加密密码
|
||||
password: bcrypt.hashSync(passwordForAdminUI, 10), // 必须使用 bcrypt 加密之后的密码
|
||||
},
|
||||
mode: process.env.NODE_ENV === 'production' ? "production" : "development", // 根据环境设置模式
|
||||
});
|
||||
|
|
@ -196,8 +199,9 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
|||
await appLoader.execStartRoutines();
|
||||
if (routine) {
|
||||
// 如果传入了routine,执行完成后就结束
|
||||
await appLoader.execRoutine(routine);
|
||||
return;
|
||||
const result = await appLoader.execRoutine(routine);
|
||||
await appLoader.unmount();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 否则启动服务器模式
|
||||
|
|
|
|||
|
|
@ -111,7 +111,8 @@ export function packageJsonContent({
|
|||
"server:init": "${serverInitScript}",
|
||||
"server:start": "${serverStartWatchScript}",
|
||||
"server:ana": "cross-env ENABLE_TRACE=true cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node --stack-size=65500 scripts/analysis.js",
|
||||
"postinstall": "npm run make:dep"
|
||||
"postinstall": "npm run make:dep",
|
||||
"upgrade:locale": "node scripts/upgradeI18n.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
|
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
const { checkI18n, checkAndUpdateI18n } = require('oak-backend-base/lib/routines/i18n.js');
|
||||
|
||||
const { startup } = require('@xuchangzju/oak-cli/lib/server/start');
|
||||
const simpleConnector = require('../lib/config/connector').default;
|
||||
const pwd = process.cwd();
|
||||
|
||||
startup(pwd, simpleConnector, true, true, checkAndUpdateI18n)
|
||||
.then(
|
||||
(result) => {
|
||||
process.exit(0);
|
||||
}
|
||||
);
|
||||
Loading…
Reference in New Issue