增加koa-logger 日志中间件

This commit is contained in:
wkj 2024-12-10 12:09:56 +08:00
parent 4bfafa31d3
commit 71fbc88306
21 changed files with 66 additions and 44 deletions

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.default = build;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
@ -154,3 +153,4 @@ 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)`)}`); (0, tip_style_1.Error)(`${(0, tip_style_1.error)(`target could only be web or mp(wechatMp) or rn(native)`)}`);
} }
} }
exports.default = build;

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.default = run;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
@ -49,3 +48,4 @@ async function run(options) {
process.exit(-1); process.exit(-1);
} }
} }
exports.default = run;

View File

@ -1,7 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.create = create; exports.update = exports.create = void 0;
exports.update = update;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const ts = tslib_1.__importStar(require("typescript")); const ts = tslib_1.__importStar(require("typescript"));
const fs_1 = require("fs"); const fs_1 = require("fs");
@ -241,7 +240,7 @@ async function create(dirName, cmd) {
} }
// 获取package.json内容 // 获取package.json内容
const packageJson = (0, template_1.packageJsonContent)({ const packageJson = (0, template_1.packageJsonContent)({
name: DEFAULT_PROJECT_NAME, // 后面再统一rename name: DEFAULT_PROJECT_NAME,
version, version,
description, description,
cliName: config_1.CLI_NAME, cliName: config_1.CLI_NAME,
@ -264,6 +263,7 @@ async function create(dirName, cmd) {
(0, tip_style_1.Error)((0, tip_style_1.error)(err)); (0, tip_style_1.Error)((0, tip_style_1.error)(err));
} }
} }
exports.create = create;
async function update(dirName, subDirName, cmd) { async function update(dirName, subDirName, cmd) {
const isDev = cmd.dev ? true : false; const isDev = cmd.dev ? true : false;
try { try {
@ -290,3 +290,4 @@ async function update(dirName, subDirName, cmd) {
console.error((0, tip_style_1.error)(err.message)); console.error((0, tip_style_1.error)(err.message));
} }
} }
exports.update = update;

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateCompilerConfig = CreateCompilerConfig; exports.CreateCompilerConfig = void 0;
/** /**
* 创建一个oak编译器配置 * 创建一个oak编译器配置
* @param raw 原始配置 * @param raw 原始配置
@ -11,6 +11,7 @@ function CreateCompilerConfig(raw) {
// 在这里可以做配置的预处理 // 在这里可以做配置的预处理
return raw; return raw;
} }
exports.CreateCompilerConfig = CreateCompilerConfig;
/** /**
* 将compiler.js中的模块导出使用以下形式 * 将compiler.js中的模块导出使用以下形式
* module.exports = CreateComilerConfig({}) * module.exports = CreateComilerConfig({})

View File

@ -1,3 +1,5 @@
/// <reference types="node" />
/// <reference types="node" />
import { PathLike } from 'fs'; import { PathLike } from 'fs';
import { checkFileExistsAndCreateType } from './enum'; import { checkFileExistsAndCreateType } from './enum';
/** /**

View File

@ -1,15 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.readDirPath = readDirPath; exports.checkFileExistsAndCreate = exports.checkFileExists = exports.copyFolder = exports.readFile = exports.writeFile = exports.deleteFolderRecursive = exports.parseJsonFile = exports.parseJsonFiles = exports.readDirGetFile = exports.readDirPath = void 0;
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 fs_1 = require("fs");
const path_1 = require("path"); const path_1 = require("path");
const enum_1 = require("./enum"); const enum_1 = require("./enum");
@ -34,6 +25,7 @@ function readDirPath(entry) {
} }
return pathList; return pathList;
} }
exports.readDirPath = readDirPath;
/** /**
* @name 读取指定目录的文件不进行深度遍历只获取根目录 * @name 读取指定目录的文件不进行深度遍历只获取根目录
* @export * @export
@ -44,6 +36,7 @@ function readDirGetFile(entry) {
const dirInfo = (0, fs_1.readdirSync)(entry); const dirInfo = (0, fs_1.readdirSync)(entry);
return dirInfo; return dirInfo;
} }
exports.readDirGetFile = readDirGetFile;
/** /**
* @name 解析json文件(数组) * @name 解析json文件(数组)
* @export * @export
@ -58,6 +51,7 @@ function parseJsonFiles(arr) {
} }
return result; return result;
} }
exports.parseJsonFiles = parseJsonFiles;
/** /**
* @name 解析单个文件json * @name 解析单个文件json
* @export * @export
@ -73,6 +67,7 @@ function parseJsonFile(file) {
return; return;
} }
} }
exports.parseJsonFile = parseJsonFile;
/** /**
* @name 删除文件夹 * @name 删除文件夹
* @export * @export
@ -102,6 +97,7 @@ function deleteFolderRecursive(entry) {
// console.log("文件夹不存在"); // console.log("文件夹不存在");
} }
} }
exports.deleteFolderRecursive = deleteFolderRecursive;
; ;
function writeFile(path, data) { function writeFile(path, data) {
try { try {
@ -112,6 +108,7 @@ function writeFile(path, data) {
(0, tip_style_1.Error)((0, tip_style_1.error)('文件写入失败')); (0, tip_style_1.Error)((0, tip_style_1.error)('文件写入失败'));
} }
} }
exports.writeFile = writeFile;
function readFile(path, options) { function readFile(path, options) {
try { try {
const data = (0, fs_1.readFileSync)(path, options); const data = (0, fs_1.readFileSync)(path, options);
@ -122,6 +119,7 @@ function readFile(path, options) {
(0, tip_style_1.Error)((0, tip_style_1.error)('文件读取失败')); (0, tip_style_1.Error)((0, tip_style_1.error)('文件读取失败'));
} }
} }
exports.readFile = readFile;
/** /**
* @name 拷贝文件夹 * @name 拷贝文件夹
* @export * @export
@ -183,6 +181,7 @@ function copyFolder(currentDir, targetDir, overwrite = false) {
throw new global.Error(`需要copy的文件夹不存在: ${currentDir}`); throw new global.Error(`需要copy的文件夹不存在: ${currentDir}`);
} }
} }
exports.copyFolder = copyFolder;
/** /**
* @name 检测文件/文件夹是否存在 * @name 检测文件/文件夹是否存在
* @export * @export
@ -192,6 +191,7 @@ function copyFolder(currentDir, targetDir, overwrite = false) {
function checkFileExists(path) { function checkFileExists(path) {
return (0, fs_1.existsSync)(path); return (0, fs_1.existsSync)(path);
} }
exports.checkFileExists = checkFileExists;
/** /**
* @name 检测文件/文件夹是否存在不存在则创建 * @name 检测文件/文件夹是否存在不存在则创建
* @export * @export
@ -217,3 +217,4 @@ function checkFileExistsAndCreate(path, data, type = enum_1.checkFileExistsAndCr
throw new global.Error(`${path} already exists!`); throw new global.Error(`${path} already exists!`);
} }
} }
exports.checkFileExistsAndCreate = checkFileExistsAndCreate;

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.default = make;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
@ -25,3 +24,4 @@ async function make(cmd, rebuild) {
process.exit(-1); process.exit(-1);
} }
} }
exports.default = make;

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.default = make;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
@ -21,3 +20,4 @@ async function make() {
process.exit(-1); process.exit(-1);
} }
} }
exports.default = make;

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.default = make;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const localeBuilder_1 = tslib_1.__importDefault(require("oak-domain/lib/compiler/localeBuilder")); const localeBuilder_1 = tslib_1.__importDefault(require("oak-domain/lib/compiler/localeBuilder"));
@ -19,3 +18,4 @@ async function make(cmd) {
process.exit(-1); process.exit(-1);
} }
} }
exports.default = make;

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.default = make;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
@ -31,3 +30,4 @@ async function make(cmd, watch) {
process.exit(-1); process.exit(-1);
} }
} }
exports.default = make;

View File

@ -1,7 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.renameProject = renameProject; exports.rename = exports.renameProject = void 0;
exports.rename = rename;
const path_1 = require("path"); const path_1 = require("path");
const fs_1 = require("fs"); const fs_1 = require("fs");
const editTemplate_1 = require("@react-native-community/cli/build/commands/init/editTemplate"); const editTemplate_1 = require("@react-native-community/cli/build/commands/init/editTemplate");
@ -43,10 +42,12 @@ async function renameProject(dir, name, title, placeholderName, placeholderTitle
process.chdir(cwd); 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)}`)}`); (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) { async function rename(cmd) {
const { projectName, displayName } = cmd; const { projectName, displayName } = cmd;
// todo 取native/android下的name和title作为placeholder再调用renameProject // todo 取native/android下的name和title作为placeholder再调用renameProject
} }
exports.rename = rename;
/* changePlaceholderInTemplate({ /* changePlaceholderInTemplate({
projectName: 'taicang', projectName: 'taicang',
projectTitle: '太藏', projectTitle: '太藏',

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.default = run;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
@ -60,3 +59,4 @@ async function run(options) {
process.exit(-1); process.exit(-1);
} }
} }
exports.default = run;

View File

@ -1,3 +1,4 @@
/// <reference path="../../src/typings/polyfill.d.ts" />
import { EntityDict } from 'oak-domain/lib/types'; import { EntityDict } from 'oak-domain/lib/types';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext'; import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.initialize = initialize; exports.initialize = void 0;
/// <reference path="../typings/polyfill.d.ts" /> /// <reference path="../typings/polyfill.d.ts" />
const oak_backend_base_1 = require("oak-backend-base"); const oak_backend_base_1 = require("oak-backend-base");
async function initialize(path) { async function initialize(path) {
@ -10,3 +10,4 @@ async function initialize(path) {
await appLoader.unmount(); await appLoader.unmount();
console.log('data initialized'); console.log('data initialized');
} }
exports.initialize = initialize;

View File

@ -1,3 +1,4 @@
/// <reference path="../../src/typings/polyfill.d.ts" />
import './polyfill'; import './polyfill';
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext'; import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
import { Connector, EntityDict } from 'oak-domain/lib/types'; import { Connector, EntityDict } from 'oak-domain/lib/types';

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.startup = startup; exports.startup = void 0;
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
/// <reference path="../typings/polyfill.d.ts" /> /// <reference path="../typings/polyfill.d.ts" />
require("./polyfill"); require("./polyfill");
@ -9,6 +9,7 @@ const path_1 = require("path");
const koa_1 = tslib_1.__importDefault(require("koa")); const koa_1 = tslib_1.__importDefault(require("koa"));
const koa_router_1 = tslib_1.__importDefault(require("koa-router")); const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
const koa_body_1 = tslib_1.__importDefault(require("koa-body")); const koa_body_1 = tslib_1.__importDefault(require("koa-body"));
const koa_logger_1 = tslib_1.__importDefault(require("koa-logger"));
const oak_backend_base_1 = require("oak-backend-base"); const oak_backend_base_1 = require("oak-backend-base");
const types_1 = require("oak-domain/lib/types"); const types_1 = require("oak-domain/lib/types");
const cluster_adapter_1 = require("@socket.io/cluster-adapter"); const cluster_adapter_1 = require("@socket.io/cluster-adapter");
@ -37,6 +38,8 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
]; ];
const corsMethods = ['PUT', 'POST', 'GET', 'DELETE', 'OPTIONS']; const corsMethods = ['PUT', 'POST', 'GET', 'DELETE', 'OPTIONS'];
const koa = new koa_1.default(); const koa = new koa_1.default();
// 使用 koa-logger 中间件打印日志
koa.use((0, koa_logger_1.default)());
// socket // socket
const httpServer = (0, http_1.createServer)(koa.callback()); const httpServer = (0, http_1.createServer)(koa.callback());
const socketOption = { const socketOption = {
@ -48,7 +51,7 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
} }
: serverConfiguration.cors : serverConfiguration.cors
? { ? {
origin: serverConfiguration.cors.origin, //socket.io配置cors origin是支持数组和字符串 origin: serverConfiguration.cors.origin,
allowedHeaders: [ allowedHeaders: [
...corsHeaders.concat(connector.getCorsHeader()), ...corsHeaders.concat(connector.getCorsHeader()),
...(serverConfiguration.cors.headers || []), ...(serverConfiguration.cors.headers || []),
@ -241,3 +244,4 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
}; };
return shutdown; return shutdown;
} }
exports.startup = startup;

View File

@ -1,3 +1,4 @@
/// <reference types="node" />
export type LogFormatterProp = { export type LogFormatterProp = {
level: "info" | "warn" | "error"; level: "info" | "warn" | "error";
caller: NodeJS.CallSite | null; caller: NodeJS.CallSite | null;

View File

@ -1,16 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.packageJsonContent = packageJsonContent; exports.oakConfigContentWithWeb = exports.oakConfigContentWithWeChatMp = exports.appJsonContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigWebJsonContent = exports.tsConfigMpJsonContent = exports.tsConfigPathsJsonContent = exports.tsConfigBuildPathsJsonContent = exports.tsConfigBuildJsonContent = exports.tsConfigJsonContent = exports.packageJsonContent = void 0;
exports.tsConfigJsonContent = tsConfigJsonContent;
exports.tsConfigBuildJsonContent = tsConfigBuildJsonContent;
exports.tsConfigBuildPathsJsonContent = tsConfigBuildPathsJsonContent;
exports.tsConfigPathsJsonContent = tsConfigPathsJsonContent;
exports.tsConfigMpJsonContent = tsConfigMpJsonContent;
exports.tsConfigWebJsonContent = tsConfigWebJsonContent;
exports.projectConfigContentWithWeChatMp = projectConfigContentWithWeChatMp;
exports.appJsonContentWithWeChatMp = appJsonContentWithWeChatMp;
exports.oakConfigContentWithWeChatMp = oakConfigContentWithWeChatMp;
exports.oakConfigContentWithWeb = oakConfigContentWithWeb;
const child_process_1 = require("child_process"); const child_process_1 = require("child_process");
const fs_1 = require("fs"); const fs_1 = require("fs");
const path_1 = require("path"); const path_1 = require("path");
@ -311,6 +301,7 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
`; `;
// _moduleAliases用于lib内运行时的模块声明重载之后require的路径还会保留@project需要这样的方式来进行路径alias // _moduleAliases用于lib内运行时的模块声明重载之后require的路径还会保留@project需要这样的方式来进行路径alias
} }
exports.packageJsonContent = packageJsonContent;
function tsConfigJsonContent() { function tsConfigJsonContent() {
return `{ return `{
"extends": "./tsconfig.paths.json", "extends": "./tsconfig.paths.json",
@ -362,6 +353,7 @@ function tsConfigJsonContent() {
] ]
}`; }`;
} }
exports.tsConfigJsonContent = tsConfigJsonContent;
function tsConfigBuildJsonContent() { function tsConfigBuildJsonContent() {
return `{ return `{
"extends": "./tsconfig.build.paths.json", "extends": "./tsconfig.build.paths.json",
@ -401,6 +393,7 @@ function tsConfigBuildJsonContent() {
] ]
}`; }`;
} }
exports.tsConfigBuildJsonContent = tsConfigBuildJsonContent;
function tsConfigBuildPathsJsonContent() { function tsConfigBuildPathsJsonContent() {
return `{ return `{
"compilerOptions": { "compilerOptions": {
@ -420,6 +413,7 @@ function tsConfigBuildPathsJsonContent() {
} }
}`; }`;
} }
exports.tsConfigBuildPathsJsonContent = tsConfigBuildPathsJsonContent;
function tsConfigPathsJsonContent() { function tsConfigPathsJsonContent() {
return `{ return `{
"compilerOptions": { "compilerOptions": {
@ -439,6 +433,7 @@ function tsConfigPathsJsonContent() {
} }
}`; }`;
} }
exports.tsConfigPathsJsonContent = tsConfigPathsJsonContent;
function tsConfigMpJsonContent() { function tsConfigMpJsonContent() {
return `{ return `{
"extends": "./tsconfig.paths.json", "extends": "./tsconfig.paths.json",
@ -486,6 +481,7 @@ function tsConfigMpJsonContent() {
] ]
}`; }`;
} }
exports.tsConfigMpJsonContent = tsConfigMpJsonContent;
function tsConfigWebJsonContent() { function tsConfigWebJsonContent() {
return `{ return `{
"extends": "./tsconfig.paths.json", "extends": "./tsconfig.paths.json",
@ -535,6 +531,7 @@ function tsConfigWebJsonContent() {
] ]
}`; }`;
} }
exports.tsConfigWebJsonContent = tsConfigWebJsonContent;
function projectConfigContentWithWeChatMp(oakConfigName, projectname, miniVersion) { function projectConfigContentWithWeChatMp(oakConfigName, projectname, miniVersion) {
return `{ return `{
"description": "项目配置文件", "description": "项目配置文件",
@ -610,6 +607,7 @@ function projectConfigContentWithWeChatMp(oakConfigName, projectname, miniVersio
} }
}`; }`;
} }
exports.projectConfigContentWithWeChatMp = projectConfigContentWithWeChatMp;
function appJsonContentWithWeChatMp(isDev) { function appJsonContentWithWeChatMp(isDev) {
const pages = [ const pages = [
'@project/pages/store/list/index', '@project/pages/store/list/index',
@ -633,15 +631,18 @@ function appJsonContentWithWeChatMp(isDev) {
"sitemapLocation": "sitemap.json" "sitemapLocation": "sitemap.json"
}`; }`;
} }
exports.appJsonContentWithWeChatMp = appJsonContentWithWeChatMp;
function oakConfigContentWithWeChatMp() { function oakConfigContentWithWeChatMp() {
return `{ return `{
"theme": { "theme": {
} }
}`; }`;
} }
exports.oakConfigContentWithWeChatMp = oakConfigContentWithWeChatMp;
function oakConfigContentWithWeb() { function oakConfigContentWithWeb() {
return `{ return `{
"theme": { "theme": {
} }
}`; }`;
} }
exports.oakConfigContentWithWeb = oakConfigContentWithWeb;

View File

@ -1,12 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.findJson = findJson; exports.deWeight = exports.formatJsonByFile = exports.union = exports.intersect = exports.difference = exports.getStr = exports.findJson = void 0;
exports.getStr = getStr;
exports.difference = difference;
exports.intersect = intersect;
exports.union = union;
exports.formatJsonByFile = formatJsonByFile;
exports.deWeight = deWeight;
/** /**
* @name 从一组路径里查找到所有json文件 * @name 从一组路径里查找到所有json文件
* @export * @export
@ -24,6 +18,7 @@ function findJson(pathArr) {
} }
return result; return result;
} }
exports.findJson = findJson;
/** /**
* @name 已知前后文取中间文本 * @name 已知前后文取中间文本
* @export * @export
@ -37,6 +32,7 @@ function getStr(str, start, end) {
let res = str.match(reg); let res = str.match(reg);
return res ? res[1] : null; return res ? res[1] : null;
} }
exports.getStr = getStr;
/** /**
* @name 差集 * @name 差集
* @export * @export
@ -48,6 +44,7 @@ function getStr(str, start, end) {
function difference(current, target) { function difference(current, target) {
return new Set([...target].filter(x => !current.has(x))); return new Set([...target].filter(x => !current.has(x)));
} }
exports.difference = difference;
/** /**
* @name 获取交集 * @name 获取交集
* @export * @export
@ -59,6 +56,7 @@ function difference(current, target) {
function intersect(current, target) { function intersect(current, target) {
return new Set([...target].filter(x => current.has(x))); return new Set([...target].filter(x => current.has(x)));
} }
exports.intersect = intersect;
/** /**
* @name 获取并集 * @name 获取并集
* @export * @export
@ -70,6 +68,7 @@ function intersect(current, target) {
function union(current, target) { function union(current, target) {
return new Set([...current, ...target]); return new Set([...current, ...target]);
} }
exports.union = union;
/** /**
* @name 格式化json * @name 格式化json
* @export * @export
@ -80,6 +79,7 @@ function union(current, target) {
function formatJsonByFile(data) { function formatJsonByFile(data) {
return JSON.stringify(data, null, 2); return JSON.stringify(data, null, 2);
} }
exports.formatJsonByFile = formatJsonByFile;
/** /**
* @name 数组对象去重 * @name 数组对象去重
* @export * @export
@ -96,3 +96,4 @@ function deWeight(arr, type) {
} }
return new Set([...map.values()]); return new Set([...map.values()]);
} }
exports.deWeight = deWeight;

View File

@ -31,6 +31,7 @@
"@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@types/cross-spawn": "^6.0.2", "@types/cross-spawn": "^6.0.2",
"@types/inquirer": "^9.0.3", "@types/inquirer": "^9.0.3",
"@types/koa-logger": "^3.1.5",
"@types/koa-router": "^7.4.4", "@types/koa-router": "^7.4.4",
"@types/lodash": "^4.17.13", "@types/lodash": "^4.17.13",
"@types/node": "^20.6.0", "@types/node": "^20.6.0",
@ -94,6 +95,7 @@
"jest-watch-typeahead": "^1.0.0", "jest-watch-typeahead": "^1.0.0",
"koa": "^2.13.4", "koa": "^2.13.4",
"koa-body": "^5.0.0", "koa-body": "^5.0.0",
"koa-logger": "^3.2.1",
"koa-router": "^11.0.1", "koa-router": "^11.0.1",
"less": "^4.1.2", "less": "^4.1.2",
"less-loader": "^10.2.0", "less-loader": "^10.2.0",

View File

@ -5,6 +5,8 @@ import PathLib, { join } from 'path';
import Koa from 'koa'; import Koa from 'koa';
import KoaRouter from 'koa-router'; import KoaRouter from 'koa-router';
import KoaBody from 'koa-body'; import KoaBody from 'koa-body';
import logger from 'koa-logger';
import { AppLoader, getClusterInfo, ClusterAppLoader } from 'oak-backend-base'; import { AppLoader, getClusterInfo, ClusterAppLoader } from 'oak-backend-base';
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext'; import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
import { OakException, Connector, EntityDict, ClusterInfo } from 'oak-domain/lib/types'; import { OakException, Connector, EntityDict, ClusterInfo } from 'oak-domain/lib/types';
@ -55,6 +57,8 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
const corsMethods = ['PUT', 'POST', 'GET', 'DELETE', 'OPTIONS']; const corsMethods = ['PUT', 'POST', 'GET', 'DELETE', 'OPTIONS'];
const koa = new Koa(); const koa = new Koa();
// 使用 koa-logger 中间件打印日志
koa.use(logger());
// socket // socket
const httpServer = createServer(koa.callback()); const httpServer = createServer(koa.callback());
const socketOption: Partial<ServerOptions> = { const socketOption: Partial<ServerOptions> = {