Merge branch 'dev' of gitea.51mars.com:Oak-Team/oak-cli into dev
This commit is contained in:
commit
79ca5322c5
|
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = build;
|
||||
const tslib_1 = require("tslib");
|
||||
const tip_style_1 = require("./tip-style");
|
||||
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
|
||||
|
|
@ -184,4 +185,3 @@ async function build(cmd) {
|
|||
(0, tip_style_1.Error)(`${(0, tip_style_1.error)(`target could only be web or mp(wechatMp) or rn(native)`)}`);
|
||||
}
|
||||
}
|
||||
exports.default = build;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = run;
|
||||
const tslib_1 = require("tslib");
|
||||
const tip_style_1 = require("./tip-style");
|
||||
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
|
||||
|
|
@ -48,4 +49,3 @@ async function run(options) {
|
|||
process.exit(-1);
|
||||
}
|
||||
}
|
||||
exports.default = run;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.update = exports.create = void 0;
|
||||
exports.create = create;
|
||||
exports.update = update;
|
||||
const tslib_1 = require("tslib");
|
||||
const ts = tslib_1.__importStar(require("typescript"));
|
||||
const fs_1 = require("fs");
|
||||
|
|
@ -242,7 +243,7 @@ async function create(dirName, cmd) {
|
|||
}
|
||||
// 获取package.json内容
|
||||
const packageJson = (0, template_1.packageJsonContent)({
|
||||
name: DEFAULT_PROJECT_NAME,
|
||||
name: DEFAULT_PROJECT_NAME, // 后面再统一rename
|
||||
version,
|
||||
description,
|
||||
cliName: config_1.CLI_NAME,
|
||||
|
|
@ -265,7 +266,6 @@ async function create(dirName, cmd) {
|
|||
(0, tip_style_1.Error)((0, tip_style_1.error)(err));
|
||||
}
|
||||
}
|
||||
exports.create = create;
|
||||
async function update(dirName, subDirName, cmd) {
|
||||
const isDev = cmd.dev ? true : false;
|
||||
try {
|
||||
|
|
@ -292,4 +292,3 @@ async function update(dirName, subDirName, cmd) {
|
|||
console.error((0, tip_style_1.error)(err.message));
|
||||
}
|
||||
}
|
||||
exports.update = update;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CreateCompilerConfig = void 0;
|
||||
exports.CreateCompilerConfig = CreateCompilerConfig;
|
||||
/**
|
||||
* 创建一个oak编译器配置
|
||||
* @param raw 原始配置
|
||||
|
|
@ -11,7 +11,6 @@ function CreateCompilerConfig(raw) {
|
|||
// 在这里可以做配置的预处理
|
||||
return raw;
|
||||
}
|
||||
exports.CreateCompilerConfig = CreateCompilerConfig;
|
||||
/**
|
||||
* 将compiler.js中的模块导出使用以下形式:
|
||||
* module.exports = CreateComilerConfig({})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import { PathLike } from 'fs';
|
||||
import { checkFileExistsAndCreateType } from './enum';
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,15 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.checkFileExistsAndCreate = exports.checkFileExists = exports.copyFolder = exports.readFile = exports.writeFile = exports.deleteFolderRecursive = exports.parseJsonFile = exports.parseJsonFiles = exports.readDirGetFile = exports.readDirPath = void 0;
|
||||
exports.readDirPath = readDirPath;
|
||||
exports.readDirGetFile = readDirGetFile;
|
||||
exports.parseJsonFiles = parseJsonFiles;
|
||||
exports.parseJsonFile = parseJsonFile;
|
||||
exports.deleteFolderRecursive = deleteFolderRecursive;
|
||||
exports.writeFile = writeFile;
|
||||
exports.readFile = readFile;
|
||||
exports.copyFolder = copyFolder;
|
||||
exports.checkFileExists = checkFileExists;
|
||||
exports.checkFileExistsAndCreate = checkFileExistsAndCreate;
|
||||
const fs_1 = require("fs");
|
||||
const path_1 = require("path");
|
||||
const enum_1 = require("./enum");
|
||||
|
|
@ -25,7 +34,6 @@ function readDirPath(entry) {
|
|||
}
|
||||
return pathList;
|
||||
}
|
||||
exports.readDirPath = readDirPath;
|
||||
/**
|
||||
* @name 读取指定目录的文件(不进行深度遍历,只获取根目录)
|
||||
* @export
|
||||
|
|
@ -36,7 +44,6 @@ function readDirGetFile(entry) {
|
|||
const dirInfo = (0, fs_1.readdirSync)(entry);
|
||||
return dirInfo;
|
||||
}
|
||||
exports.readDirGetFile = readDirGetFile;
|
||||
/**
|
||||
* @name 解析json文件(数组)
|
||||
* @export
|
||||
|
|
@ -51,7 +58,6 @@ function parseJsonFiles(arr) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
exports.parseJsonFiles = parseJsonFiles;
|
||||
/**
|
||||
* @name 解析单个文件json
|
||||
* @export
|
||||
|
|
@ -67,7 +73,6 @@ function parseJsonFile(file) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
exports.parseJsonFile = parseJsonFile;
|
||||
/**
|
||||
* @name 删除文件夹
|
||||
* @export
|
||||
|
|
@ -97,7 +102,6 @@ function deleteFolderRecursive(entry) {
|
|||
// console.log("文件夹不存在");
|
||||
}
|
||||
}
|
||||
exports.deleteFolderRecursive = deleteFolderRecursive;
|
||||
;
|
||||
function writeFile(path, data) {
|
||||
try {
|
||||
|
|
@ -108,7 +112,6 @@ function writeFile(path, data) {
|
|||
(0, tip_style_1.Error)((0, tip_style_1.error)('文件写入失败'));
|
||||
}
|
||||
}
|
||||
exports.writeFile = writeFile;
|
||||
function readFile(path, options) {
|
||||
try {
|
||||
const data = (0, fs_1.readFileSync)(path, options);
|
||||
|
|
@ -119,7 +122,6 @@ function readFile(path, options) {
|
|||
(0, tip_style_1.Error)((0, tip_style_1.error)('文件读取失败'));
|
||||
}
|
||||
}
|
||||
exports.readFile = readFile;
|
||||
/**
|
||||
* @name 拷贝文件夹
|
||||
* @export
|
||||
|
|
@ -181,7 +183,6 @@ function copyFolder(currentDir, targetDir, overwrite = false) {
|
|||
throw new global.Error(`需要copy的文件夹不存在: ${currentDir}`);
|
||||
}
|
||||
}
|
||||
exports.copyFolder = copyFolder;
|
||||
/**
|
||||
* @name 检测文件/文件夹是否存在
|
||||
* @export
|
||||
|
|
@ -191,7 +192,6 @@ exports.copyFolder = copyFolder;
|
|||
function checkFileExists(path) {
|
||||
return (0, fs_1.existsSync)(path);
|
||||
}
|
||||
exports.checkFileExists = checkFileExists;
|
||||
/**
|
||||
* @name 检测文件/文件夹是否存在,不存在则创建
|
||||
* @export
|
||||
|
|
@ -217,4 +217,3 @@ function checkFileExistsAndCreate(path, data, type = enum_1.checkFileExistsAndCr
|
|||
throw new global.Error(`${path} already exists!`);
|
||||
}
|
||||
}
|
||||
exports.checkFileExistsAndCreate = checkFileExistsAndCreate;
|
||||
|
|
|
|||
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')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = make;
|
||||
const tslib_1 = require("tslib");
|
||||
const tip_style_1 = require("./tip-style");
|
||||
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
|
||||
|
|
@ -21,4 +22,3 @@ async function make(cmd) {
|
|||
process.exit(-1);
|
||||
}
|
||||
}
|
||||
exports.default = make;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = make;
|
||||
const tslib_1 = require("tslib");
|
||||
const tip_style_1 = require("./tip-style");
|
||||
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
|
||||
|
|
@ -20,4 +21,3 @@ async function make() {
|
|||
process.exit(-1);
|
||||
}
|
||||
}
|
||||
exports.default = make;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = make;
|
||||
const tslib_1 = require("tslib");
|
||||
const tip_style_1 = require("./tip-style");
|
||||
const localeBuilder_1 = tslib_1.__importDefault(require("oak-domain/lib/compiler/localeBuilder"));
|
||||
|
|
@ -18,4 +19,3 @@ async function make(cmd) {
|
|||
process.exit(-1);
|
||||
}
|
||||
}
|
||||
exports.default = make;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = make;
|
||||
const tslib_1 = require("tslib");
|
||||
const tip_style_1 = require("./tip-style");
|
||||
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
|
||||
|
|
@ -30,4 +31,3 @@ async function make(cmd, watch) {
|
|||
process.exit(-1);
|
||||
}
|
||||
}
|
||||
exports.default = make;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.rename = exports.renameProject = void 0;
|
||||
exports.renameProject = renameProject;
|
||||
exports.rename = rename;
|
||||
const path_1 = require("path");
|
||||
const fs_1 = require("fs");
|
||||
const editTemplate_1 = require("@react-native-community/cli/build/commands/init/editTemplate");
|
||||
|
|
@ -44,7 +45,6 @@ async function renameProject(dir, name, title, placeholderName, placeholderTitle
|
|||
process.chdir(cwd);
|
||||
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Change project name to ${(0, tip_style_1.primary)(name)}, project title to ${(0, tip_style_1.primary)(title)}`)}`);
|
||||
}
|
||||
exports.renameProject = renameProject;
|
||||
async function rename(cmd) {
|
||||
const { oldName, newName, oldTitle, newTitle } = cmd;
|
||||
if (!oldName) {
|
||||
|
|
@ -65,4 +65,3 @@ async function rename(cmd) {
|
|||
}
|
||||
renameProject(process.cwd(), newName, newTitle, oldName, oldTitle);
|
||||
}
|
||||
exports.rename = rename;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = run;
|
||||
const tslib_1 = require("tslib");
|
||||
const tip_style_1 = require("./tip-style");
|
||||
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
|
||||
|
|
@ -59,4 +60,3 @@ async function run(options) {
|
|||
process.exit(-1);
|
||||
}
|
||||
}
|
||||
exports.default = run;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/// <reference path="../../src/typings/polyfill.d.ts" />
|
||||
import { EntityDict } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initialize = void 0;
|
||||
exports.initialize = initialize;
|
||||
/// <reference path="../typings/polyfill.d.ts" />
|
||||
const oak_backend_base_1 = require("oak-backend-base");
|
||||
async function initialize(path) {
|
||||
|
|
@ -10,4 +10,3 @@ async function initialize(path) {
|
|||
await appLoader.unmount();
|
||||
console.log('data initialized');
|
||||
}
|
||||
exports.initialize = initialize;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/// <reference path="../../src/typings/polyfill.d.ts" />
|
||||
import './polyfill';
|
||||
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
|
||||
import { Connector, EntityDict } from 'oak-domain/lib/types';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.startup = void 0;
|
||||
exports.startup = startup;
|
||||
const tslib_1 = require("tslib");
|
||||
/// <reference path="../typings/polyfill.d.ts" />
|
||||
require("./polyfill");
|
||||
|
|
@ -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';
|
||||
|
|
@ -63,7 +64,7 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
|
|||
}
|
||||
: serverConfiguration.cors
|
||||
? {
|
||||
origin: serverConfiguration.cors.origin,
|
||||
origin: serverConfiguration.cors.origin, //socket.io配置cors origin是支持数组和字符串
|
||||
allowedHeaders: [
|
||||
...corsHeaders.concat(connector.getCorsHeader()),
|
||||
...(serverConfiguration.cors.headers || []),
|
||||
|
|
@ -145,9 +146,9 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
|
|||
if (!ui?.disable) {
|
||||
(0, admin_ui_1.instrument)(io, {
|
||||
auth: {
|
||||
type: "basic",
|
||||
type: "basic", // 使用基本认证,生产建议关闭或换成自定义 auth
|
||||
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", // 根据环境设置模式
|
||||
});
|
||||
|
|
@ -367,4 +368,3 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
|
|||
};
|
||||
return shutdown;
|
||||
}
|
||||
exports.startup = startup;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/// <reference types="node" />
|
||||
export type LogFormatterProp = {
|
||||
level: "info" | "warn" | "error";
|
||||
caller: NodeJS.CallSite | null;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.updateCompilerJsContent = exports.oakConfigContentWithWeb = exports.oakConfigContentWithWeChatMp = exports.appJsonContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigWebJsonContent = exports.tsConfigMpJsonContent = exports.tsConfigPathsJsonContent = exports.tsConfigBuildJsonContent = exports.tsConfigJsonContent = exports.packageJsonContent = void 0;
|
||||
exports.packageJsonContent = packageJsonContent;
|
||||
exports.tsConfigJsonContent = tsConfigJsonContent;
|
||||
exports.tsConfigBuildJsonContent = tsConfigBuildJsonContent;
|
||||
exports.tsConfigPathsJsonContent = tsConfigPathsJsonContent;
|
||||
exports.tsConfigMpJsonContent = tsConfigMpJsonContent;
|
||||
exports.tsConfigWebJsonContent = tsConfigWebJsonContent;
|
||||
exports.projectConfigContentWithWeChatMp = projectConfigContentWithWeChatMp;
|
||||
exports.appJsonContentWithWeChatMp = appJsonContentWithWeChatMp;
|
||||
exports.oakConfigContentWithWeChatMp = oakConfigContentWithWeChatMp;
|
||||
exports.oakConfigContentWithWeb = oakConfigContentWithWeb;
|
||||
exports.updateCompilerJsContent = updateCompilerJsContent;
|
||||
const tslib_1 = require("tslib");
|
||||
const child_process_1 = require("child_process");
|
||||
const fs_1 = require("fs");
|
||||
|
|
@ -299,7 +309,6 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
|
|||
}
|
||||
`;
|
||||
}
|
||||
exports.packageJsonContent = packageJsonContent;
|
||||
function tsConfigJsonContent() {
|
||||
return `{
|
||||
"extends": "./tsconfig.paths.json",
|
||||
|
|
@ -351,7 +360,6 @@ function tsConfigJsonContent() {
|
|||
]
|
||||
}`;
|
||||
}
|
||||
exports.tsConfigJsonContent = tsConfigJsonContent;
|
||||
function tsConfigBuildJsonContent() {
|
||||
return `{
|
||||
"extends": "./tsconfig.build.paths.json",
|
||||
|
|
@ -391,7 +399,6 @@ function tsConfigBuildJsonContent() {
|
|||
]
|
||||
}`;
|
||||
}
|
||||
exports.tsConfigBuildJsonContent = tsConfigBuildJsonContent;
|
||||
function tsConfigPathsJsonContent(deps) {
|
||||
const paths = {
|
||||
"@project/*": [
|
||||
|
|
@ -420,7 +427,6 @@ function tsConfigPathsJsonContent(deps) {
|
|||
}
|
||||
}, null, '\t');
|
||||
}
|
||||
exports.tsConfigPathsJsonContent = tsConfigPathsJsonContent;
|
||||
function tsConfigMpJsonContent() {
|
||||
return `{
|
||||
"extends": "./tsconfig.paths.json",
|
||||
|
|
@ -468,7 +474,6 @@ function tsConfigMpJsonContent() {
|
|||
]
|
||||
}`;
|
||||
}
|
||||
exports.tsConfigMpJsonContent = tsConfigMpJsonContent;
|
||||
function tsConfigWebJsonContent() {
|
||||
return `{
|
||||
"extends": "./tsconfig.paths.json",
|
||||
|
|
@ -518,7 +523,6 @@ function tsConfigWebJsonContent() {
|
|||
]
|
||||
}`;
|
||||
}
|
||||
exports.tsConfigWebJsonContent = tsConfigWebJsonContent;
|
||||
function projectConfigContentWithWeChatMp(oakConfigName, projectname, miniVersion) {
|
||||
return `{
|
||||
"description": "项目配置文件",
|
||||
|
|
@ -594,7 +598,6 @@ function projectConfigContentWithWeChatMp(oakConfigName, projectname, miniVersio
|
|||
}
|
||||
}`;
|
||||
}
|
||||
exports.projectConfigContentWithWeChatMp = projectConfigContentWithWeChatMp;
|
||||
function appJsonContentWithWeChatMp(isDev) {
|
||||
const pages = [
|
||||
'@project/pages/store/list/index',
|
||||
|
|
@ -618,21 +621,18 @@ function appJsonContentWithWeChatMp(isDev) {
|
|||
"sitemapLocation": "sitemap.json"
|
||||
}`;
|
||||
}
|
||||
exports.appJsonContentWithWeChatMp = appJsonContentWithWeChatMp;
|
||||
function oakConfigContentWithWeChatMp() {
|
||||
return `{
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
}
|
||||
exports.oakConfigContentWithWeChatMp = oakConfigContentWithWeChatMp;
|
||||
function oakConfigContentWithWeb() {
|
||||
return `{
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
}
|
||||
exports.oakConfigContentWithWeb = oakConfigContentWithWeb;
|
||||
function updateCompilerJsContent(directory, deps) {
|
||||
const compilerJsPath = (0, path_1.join)(directory, 'configuration', 'compiler.js');
|
||||
(0, assert_1.default)((0, fs_1.existsSync)(compilerJsPath));
|
||||
|
|
@ -691,4 +691,3 @@ function updateCompilerJsContent(directory, deps) {
|
|||
(0, fs_1.writeFileSync)(compilerJsPath, code);
|
||||
}
|
||||
}
|
||||
exports.updateCompilerJsContent = updateCompilerJsContent;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
40
lib/utils.js
40
lib/utils.js
|
|
@ -1,6 +1,16 @@
|
|||
"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.findJson = findJson;
|
||||
exports.getStr = getStr;
|
||||
exports.difference = difference;
|
||||
exports.intersect = intersect;
|
||||
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
|
||||
|
|
@ -18,7 +28,6 @@ function findJson(pathArr) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
exports.findJson = findJson;
|
||||
/**
|
||||
* @name 已知前后文取中间文本
|
||||
* @export
|
||||
|
|
@ -32,7 +41,6 @@ function getStr(str, start, end) {
|
|||
let res = str.match(reg);
|
||||
return res ? res[1] : null;
|
||||
}
|
||||
exports.getStr = getStr;
|
||||
/**
|
||||
* @name 差集
|
||||
* @export
|
||||
|
|
@ -44,7 +52,6 @@ exports.getStr = getStr;
|
|||
function difference(current, target) {
|
||||
return new Set([...target].filter(x => !current.has(x)));
|
||||
}
|
||||
exports.difference = difference;
|
||||
/**
|
||||
* @name 获取交集
|
||||
* @export
|
||||
|
|
@ -56,7 +63,6 @@ exports.difference = difference;
|
|||
function intersect(current, target) {
|
||||
return new Set([...target].filter(x => current.has(x)));
|
||||
}
|
||||
exports.intersect = intersect;
|
||||
/**
|
||||
* @name 获取并集
|
||||
* @export
|
||||
|
|
@ -68,7 +74,6 @@ exports.intersect = intersect;
|
|||
function union(current, target) {
|
||||
return new Set([...current, ...target]);
|
||||
}
|
||||
exports.union = union;
|
||||
/**
|
||||
* @name 格式化json
|
||||
* @export
|
||||
|
|
@ -79,7 +84,6 @@ exports.union = union;
|
|||
function formatJsonByFile(data) {
|
||||
return JSON.stringify(data, null, 2);
|
||||
}
|
||||
exports.formatJsonByFile = formatJsonByFile;
|
||||
/**
|
||||
* @name 数组对象去重
|
||||
* @export
|
||||
|
|
@ -96,7 +100,6 @@ function deWeight(arr, type) {
|
|||
}
|
||||
return new Set([...map.values()]);
|
||||
}
|
||||
exports.deWeight = deWeight;
|
||||
/**
|
||||
* @name 随机字符串
|
||||
* @export
|
||||
|
|
@ -112,4 +115,23 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -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) => {
|
||||
|
|
@ -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", // 根据环境设置模式
|
||||
});
|
||||
|
|
|
|||
30
src/utils.ts
30
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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue