@_tc/template-core 0.0.1-bate.29 → 0.0.1-bate.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/_virtual/_rolldown/runtime.js +37 -0
- package/cjs/app/controller/base.js +28 -20
- package/cjs/app/controller/project.js +59 -49
- package/cjs/app/controller/view.js +14 -13
- package/cjs/app/data/signKey.js +23 -4
- package/cjs/app/extend/db.js +6 -10
- package/cjs/app/extend/generateErrorMessage.js +15 -13
- package/cjs/app/extend/logger.js +34 -71
- package/cjs/app/extend/parsingParamsOnUrl.js +21 -21
- package/cjs/app/extend/render-view.js +23 -22
- package/cjs/app/middleware/api-params-verify.js +61 -61
- package/cjs/app/middleware/api-sign-verify.js +22 -27
- package/cjs/app/middleware/error-handle.js +31 -32
- package/cjs/app/middleware/project-handler.js +20 -20
- package/cjs/app/middleware.js +30 -56
- package/cjs/app/router/project.js +9 -7
- package/cjs/app/router/view.js +6 -4
- package/cjs/app/router-schema/project.js +15 -32
- package/cjs/app/service/bese.js +16 -16
- package/cjs/app/service/project.js +32 -41
- package/cjs/app/type.js +1 -2
- package/cjs/app/typings.js +1 -2
- package/cjs/bundler/dev.js +16 -16
- package/cjs/bundler/index.js +16 -16
- package/cjs/bundler/prod.js +18 -17
- package/cjs/bundler/utils.js +144 -212
- package/cjs/index.js +25 -18
- package/cjs/packages/core/env.js +26 -24
- package/cjs/packages/core/index.js +101 -113
- package/cjs/packages/core/loader/config.js +39 -43
- package/cjs/packages/core/loader/controller.js +25 -32
- package/cjs/packages/core/loader/extend.js +29 -39
- package/cjs/packages/core/loader/middleware.js +28 -36
- package/cjs/packages/core/loader/model.js +98 -123
- package/cjs/packages/core/loader/router-schema.js +32 -33
- package/cjs/packages/core/loader/router.js +46 -61
- package/cjs/packages/core/loader/service.js +21 -22
- package/cjs/packages/core/paths.js +8 -6
- package/cjs/packages/core/types.js +1 -2
- package/cjs/packages/utils/getAllFilesInFolder.js +12 -43
- package/cjs/packages/utils/getAllFnReturnValue.js +1 -6
- package/cjs/packages/utils/index.js +11 -20
- package/cjs/packages/utils/loadFile.js +52 -62
- package/cjs/packages/utils/path.js +25 -58
- package/cjs/packages/utils/runFileFn.js +5 -4
- package/esm/_virtual/_rolldown/runtime.js +32 -0
- package/esm/app/controller/base.js +27 -20
- package/esm/app/controller/project.js +58 -41
- package/esm/app/controller/view.js +13 -11
- package/esm/app/data/signKey.js +10 -1
- package/esm/app/extend/db.js +6 -8
- package/esm/app/extend/generateErrorMessage.js +14 -11
- package/esm/app/extend/logger.js +33 -36
- package/esm/app/extend/parsingParamsOnUrl.js +20 -19
- package/esm/app/extend/render-view.js +18 -15
- package/esm/app/middleware/api-params-verify.js +58 -55
- package/esm/app/middleware/api-sign-verify.js +20 -21
- package/esm/app/middleware/error-handle.js +30 -30
- package/esm/app/middleware/project-handler.js +19 -18
- package/esm/app/middleware.js +22 -47
- package/esm/app/router/project.js +8 -5
- package/esm/app/router/view.js +5 -2
- package/esm/app/router-schema/project.js +14 -30
- package/esm/app/service/bese.js +13 -10
- package/esm/app/service/project.js +31 -33
- package/esm/app/type.js +0 -1
- package/esm/app/typings.js +0 -1
- package/esm/bundler/dev.js +15 -14
- package/esm/bundler/index.js +13 -11
- package/esm/bundler/prod.js +17 -15
- package/esm/bundler/utils.js +136 -169
- package/esm/index.js +16 -11
- package/esm/packages/core/env.js +25 -22
- package/esm/packages/core/index.js +98 -106
- package/esm/packages/core/loader/config.js +39 -41
- package/esm/packages/core/loader/controller.js +25 -30
- package/esm/packages/core/loader/extend.js +28 -36
- package/esm/packages/core/loader/middleware.js +28 -34
- package/esm/packages/core/loader/model.js +97 -118
- package/esm/packages/core/loader/router-schema.js +32 -31
- package/esm/packages/core/loader/router.js +44 -55
- package/esm/packages/core/loader/service.js +21 -20
- package/esm/packages/core/paths.js +7 -4
- package/esm/packages/core/types.js +0 -1
- package/esm/packages/utils/getAllFilesInFolder.js +8 -5
- package/esm/packages/utils/getAllFnReturnValue.js +0 -6
- package/esm/packages/utils/index.js +5 -4
- package/esm/packages/utils/loadFile.js +44 -58
- package/esm/packages/utils/path.js +23 -22
- package/esm/packages/utils/runFileFn.js +4 -1
- package/package.json +10 -8
- package/cjs/app/controller/base.d.ts +0 -12
- package/cjs/app/controller/project.d.ts +0 -10
- package/cjs/app/controller/view.d.ts +0 -7
- package/cjs/app/data/signKey.d.ts +0 -1
- package/cjs/app/extend/db.d.ts +0 -2
- package/cjs/app/extend/generateErrorMessage.d.ts +0 -7
- package/cjs/app/extend/logger.d.ts +0 -11
- package/cjs/app/extend/parsingParamsOnUrl.d.ts +0 -2
- package/cjs/app/extend/render-view.d.ts +0 -3
- package/cjs/app/middleware/api-params-verify.d.ts +0 -4
- package/cjs/app/middleware/api-sign-verify.d.ts +0 -4
- package/cjs/app/middleware/error-handle.d.ts +0 -4
- package/cjs/app/middleware/project-handler.d.ts +0 -4
- package/cjs/app/middleware.d.ts +0 -3
- package/cjs/app/router/project.d.ts +0 -4
- package/cjs/app/router/view.d.ts +0 -4
- package/cjs/app/router-schema/project.d.ts +0 -3
- package/cjs/app/service/bese.d.ts +0 -10
- package/cjs/app/service/project.d.ts +0 -27
- package/cjs/app/type.d.ts +0 -2
- package/cjs/app/typings.d.ts +0 -50
- package/cjs/bundler/dev.d.ts +0 -1
- package/cjs/bundler/index.d.ts +0 -1
- package/cjs/bundler/prod.d.ts +0 -1
- package/cjs/bundler/utils.d.ts +0 -9
- package/cjs/index.d.ts +0 -28
- package/cjs/packages/core/env.d.ts +0 -15
- package/cjs/packages/core/index.d.ts +0 -6
- package/cjs/packages/core/loader/config.d.ts +0 -9
- package/cjs/packages/core/loader/controller.d.ts +0 -17
- package/cjs/packages/core/loader/extend.d.ts +0 -8
- package/cjs/packages/core/loader/middleware.d.ts +0 -11
- package/cjs/packages/core/loader/model.d.ts +0 -36
- package/cjs/packages/core/loader/router-schema.d.ts +0 -18
- package/cjs/packages/core/loader/router.d.ts +0 -8
- package/cjs/packages/core/loader/service.d.ts +0 -17
- package/cjs/packages/core/paths.d.ts +0 -11
- package/cjs/packages/core/types.d.ts +0 -74
- package/cjs/packages/utils/getAllFilesInFolder.d.ts +0 -9
- package/cjs/packages/utils/getAllFnReturnValue.d.ts +0 -0
- package/cjs/packages/utils/index.d.ts +0 -4
- package/cjs/packages/utils/loadFile.d.ts +0 -20
- package/cjs/packages/utils/path.d.ts +0 -24
- package/cjs/packages/utils/runFileFn.d.ts +0 -5
- package/cjs/typings/type.d.ts +0 -4
- package/cjs/typings/type.js +0 -2
- package/esm/app/controller/base.d.ts +0 -13
- package/esm/app/controller/project.d.ts +0 -11
- package/esm/app/controller/view.d.ts +0 -8
- package/esm/app/data/signKey.d.ts +0 -2
- package/esm/app/extend/db.d.ts +0 -3
- package/esm/app/extend/generateErrorMessage.d.ts +0 -8
- package/esm/app/extend/logger.d.ts +0 -12
- package/esm/app/extend/parsingParamsOnUrl.d.ts +0 -3
- package/esm/app/extend/render-view.d.ts +0 -4
- package/esm/app/middleware/api-params-verify.d.ts +0 -5
- package/esm/app/middleware/api-sign-verify.d.ts +0 -5
- package/esm/app/middleware/error-handle.d.ts +0 -5
- package/esm/app/middleware/project-handler.d.ts +0 -5
- package/esm/app/middleware.d.ts +0 -4
- package/esm/app/router/project.d.ts +0 -5
- package/esm/app/router/view.d.ts +0 -5
- package/esm/app/router-schema/project.d.ts +0 -4
- package/esm/app/service/bese.d.ts +0 -11
- package/esm/app/service/project.d.ts +0 -28
- package/esm/app/type.d.ts +0 -3
- package/esm/app/typings.d.ts +0 -51
- package/esm/bundler/dev.d.ts +0 -2
- package/esm/bundler/index.d.ts +0 -2
- package/esm/bundler/prod.d.ts +0 -2
- package/esm/bundler/utils.d.ts +0 -10
- package/esm/index.d.ts +0 -29
- package/esm/packages/core/env.d.ts +0 -16
- package/esm/packages/core/index.d.ts +0 -7
- package/esm/packages/core/loader/config.d.ts +0 -10
- package/esm/packages/core/loader/controller.d.ts +0 -18
- package/esm/packages/core/loader/extend.d.ts +0 -9
- package/esm/packages/core/loader/middleware.d.ts +0 -12
- package/esm/packages/core/loader/model.d.ts +0 -37
- package/esm/packages/core/loader/router-schema.d.ts +0 -19
- package/esm/packages/core/loader/router.d.ts +0 -9
- package/esm/packages/core/loader/service.d.ts +0 -18
- package/esm/packages/core/paths.d.ts +0 -12
- package/esm/packages/core/types.d.ts +0 -75
- package/esm/packages/utils/getAllFilesInFolder.d.ts +0 -10
- package/esm/packages/utils/getAllFnReturnValue.d.ts +0 -1
- package/esm/packages/utils/index.d.ts +0 -5
- package/esm/packages/utils/loadFile.d.ts +0 -21
- package/esm/packages/utils/path.d.ts +0 -25
- package/esm/packages/utils/runFileFn.d.ts +0 -6
- package/esm/typings/type.d.ts +0 -5
- package/esm/typings/type.js +0 -1
package/esm/bundler/utils.js
CHANGED
|
@@ -1,180 +1,147 @@
|
|
|
1
|
+
import { resolve as resolve$1 } from "../packages/utils/path.js";
|
|
2
|
+
import "../packages/utils/index.js";
|
|
1
3
|
import path from "path";
|
|
2
4
|
import * as glob from "glob";
|
|
3
5
|
import { build } from "vite";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
import { copyFileSync, existsSync, readFileSync, readdirSync, rmdirSync, unlinkSync, writeFileSync } from "fs";
|
|
7
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
8
|
+
//#region bundler/utils.ts
|
|
9
|
+
var base = process.cwd();
|
|
10
|
+
var framePath = path.resolve(__dirname, "../../");
|
|
11
|
+
var frameNodePath = path.resolve(__dirname, "../");
|
|
12
|
+
var frameFEPath = path.resolve(framePath, "./fe/frontend");
|
|
13
|
+
var runPath = path.resolve(base, ".");
|
|
14
|
+
var runFEPath = path.resolve(runPath, "./frontend");
|
|
13
15
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
input[key] = path.resolve(base, fileHtml);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// for (const file of readdirSync(base)) {
|
|
63
|
-
// if (!file.endsWith(".html")) continue;
|
|
64
|
-
// const key = path.basename(file, ".html");
|
|
65
|
-
// input[key] = path.resolve(base, file);
|
|
66
|
-
// }
|
|
67
|
-
return input;
|
|
16
|
+
*
|
|
17
|
+
* 寻找 frontend\/**\/*.entry.[j|t]s(x)?
|
|
18
|
+
* 生成入口
|
|
19
|
+
*/
|
|
20
|
+
function entries() {
|
|
21
|
+
console.log("frameFEPath: ", frameFEPath);
|
|
22
|
+
console.log("runFEPath: ", runFEPath);
|
|
23
|
+
/**
|
|
24
|
+
* 所有包含 entry 的文件
|
|
25
|
+
*/
|
|
26
|
+
const files = [frameFEPath, runFEPath].reduce((o, fileDir) => {
|
|
27
|
+
const fileType = [
|
|
28
|
+
"js",
|
|
29
|
+
"jsx",
|
|
30
|
+
"ts",
|
|
31
|
+
"tsx"
|
|
32
|
+
].map((fileExtension) => resolve$1(fileDir, "/**", "/*." + fileExtension));
|
|
33
|
+
const files = glob.sync(fileType).filter((fileName) => fileName.includes(".entry.")).filter((fileName) => !fileName.includes(".d.ts"));
|
|
34
|
+
return [...o, ...files];
|
|
35
|
+
}, []);
|
|
36
|
+
const input = {};
|
|
37
|
+
if (!files.length) return input;
|
|
38
|
+
/**
|
|
39
|
+
* 查找 file 同级是否存在 .html 文件
|
|
40
|
+
* 如果存在直接使用 如果不存在 生成一份
|
|
41
|
+
*/
|
|
42
|
+
let templateHtml;
|
|
43
|
+
for (let index = 0; index < files.length; index++) {
|
|
44
|
+
const filePath = files[index];
|
|
45
|
+
const fileDIr = path.resolve(filePath, "../");
|
|
46
|
+
const fileHtml = glob.sync(resolve$1(fileDIr, "*.html"))[0];
|
|
47
|
+
if (!fileHtml) {
|
|
48
|
+
if (!templateHtml) templateHtml = readFileSync(path.resolve(frameNodePath, "./app/view/entry.tpl"), "utf-8");
|
|
49
|
+
const scriptStr = filePath.split(path.sep).at(-1);
|
|
50
|
+
const content = templateHtml.replace(`<!-- {{InsertScript}} -->`, `<script type="module" src="./${scriptStr}"><\/script>`);
|
|
51
|
+
const htmlName = fileDIr.split(path.sep).at(-1);
|
|
52
|
+
const htmlPath = path.join(fileDIr, htmlName + ".html");
|
|
53
|
+
writeFileSync(htmlPath, content);
|
|
54
|
+
input[htmlName] = htmlPath;
|
|
55
|
+
} else {
|
|
56
|
+
const key = path.basename(fileHtml, ".html");
|
|
57
|
+
input[key] = path.resolve(base, fileHtml);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return input;
|
|
68
61
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// 放在框架路径比较保险
|
|
72
|
-
return path.join(frameNodePath, "./app/public/dist");
|
|
62
|
+
function outDir() {
|
|
63
|
+
return path.join(frameNodePath, "./app/public/dist");
|
|
73
64
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
building = false;
|
|
91
|
-
});
|
|
92
|
-
console.log(`watching ${runFEPath}/...`);
|
|
65
|
+
var watchFiles = async (callback) => {
|
|
66
|
+
const watcher = (await import("chokidar")).watch(runFEPath, {
|
|
67
|
+
ignored: /(^|[\/\\])\../,
|
|
68
|
+
persistent: true,
|
|
69
|
+
ignoreInitial: true
|
|
70
|
+
});
|
|
71
|
+
let building = false;
|
|
72
|
+
watcher.on("change", async (filePath) => {
|
|
73
|
+
if (building) return;
|
|
74
|
+
building = true;
|
|
75
|
+
console.log(`changed: ${filePath}`);
|
|
76
|
+
await callback?.();
|
|
77
|
+
console.log("rebuild done");
|
|
78
|
+
building = false;
|
|
79
|
+
});
|
|
80
|
+
console.log(`watching ${runFEPath}/...`);
|
|
93
81
|
};
|
|
94
82
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
*
|
|
84
|
+
* 1. 在 build 结束后
|
|
85
|
+
* 2. 获取输出目录下的html文件
|
|
86
|
+
* 3. 移动内部的html 至 输出目录的根节点
|
|
87
|
+
*/
|
|
100
88
|
function flattenHtmlPlugin(suffix = ".html") {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
for (const dir of parents) {
|
|
141
|
-
if (dir && dir !== ".") {
|
|
142
|
-
const fullPath = path.join(feDir, dir);
|
|
143
|
-
delEmptyDir(fullPath);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* ------------------
|
|
148
|
-
*/
|
|
149
|
-
// 输出最终的 文件路径
|
|
150
|
-
const endFiles = glob.sync("**/*" + suffix, { cwd: feDir });
|
|
151
|
-
for (const f of endFiles) {
|
|
152
|
-
console.log("final file path -----> ", f);
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
};
|
|
89
|
+
return {
|
|
90
|
+
name: "flatten-html",
|
|
91
|
+
apply: "build",
|
|
92
|
+
closeBundle() {
|
|
93
|
+
const feDir = outDir();
|
|
94
|
+
if (!existsSync(feDir)) return;
|
|
95
|
+
const htmlFiles = glob.sync("**/*.html", { cwd: feDir });
|
|
96
|
+
for (const file of htmlFiles) {
|
|
97
|
+
const src = path.join(feDir, file);
|
|
98
|
+
let fileOName = path.basename(file, ".html");
|
|
99
|
+
const entrySuffix = ".entry";
|
|
100
|
+
if (fileOName.indexOf(entrySuffix) === -1) fileOName = fileOName + entrySuffix;
|
|
101
|
+
const fileName = fileOName + suffix;
|
|
102
|
+
const dest = path.join(feDir, fileName);
|
|
103
|
+
if (src !== dest) {
|
|
104
|
+
copyFileSync(src, dest);
|
|
105
|
+
unlinkSync(src);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const parents = [...new Set(htmlFiles.map((f) => path.dirname(f)))].sort().reverse();
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* 删除空的目录
|
|
112
|
+
*/
|
|
113
|
+
const delEmptyDir = (pathStr) => {
|
|
114
|
+
if (!(existsSync(pathStr) ? readdirSync(pathStr) : [1]).length) {
|
|
115
|
+
rmdirSync(pathStr);
|
|
116
|
+
const pa = pathStr.split(path.sep).slice(0, -1);
|
|
117
|
+
pa.length && delEmptyDir(pa.join(path.sep));
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
for (const dir of parents) if (dir && dir !== ".") delEmptyDir(path.join(feDir, dir));
|
|
121
|
+
/**
|
|
122
|
+
* ------------------
|
|
123
|
+
*/
|
|
124
|
+
const endFiles = glob.sync("**/*" + suffix, { cwd: feDir });
|
|
125
|
+
for (const f of endFiles) console.log("final file path -----> ", f);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
156
128
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
resolve: {
|
|
174
|
-
alias: {
|
|
175
|
-
// 需要配置打包后的文件地址
|
|
176
|
-
"@tc/ui-react": path.resolve(__dirname, "../../fe/packages/ui/react/"),
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
});
|
|
129
|
+
var VBuildFE = async (input) => {
|
|
130
|
+
await build({
|
|
131
|
+
configFile: false,
|
|
132
|
+
base: "dist",
|
|
133
|
+
plugins: [
|
|
134
|
+
(await import("@vitejs/plugin-react")).default(),
|
|
135
|
+
flattenHtmlPlugin(".tpl"),
|
|
136
|
+
tailwindcss()
|
|
137
|
+
],
|
|
138
|
+
build: {
|
|
139
|
+
outDir: outDir(),
|
|
140
|
+
emptyOutDir: true,
|
|
141
|
+
rollupOptions: { input }
|
|
142
|
+
},
|
|
143
|
+
resolve: { alias: { "@tc/ui-react": path.resolve(__dirname, "../../fe/packages/ui/react/") } }
|
|
144
|
+
});
|
|
180
145
|
};
|
|
146
|
+
//#endregion
|
|
147
|
+
export { VBuildFE, entries, outDir, watchFiles };
|
package/esm/index.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./app/
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import base_default from "./app/controller/base.js";
|
|
2
|
+
import bese_default from "./app/service/bese.js";
|
|
3
|
+
import { start } from "@tc/core";
|
|
4
|
+
import { resolve } from "@tc/utils";
|
|
5
|
+
import modelLoader from "@tc/core/loader/model";
|
|
6
|
+
//#region index.ts
|
|
7
|
+
var serverStart = (options) => {
|
|
8
|
+
return start({
|
|
9
|
+
...options,
|
|
10
|
+
frameBaseDir: resolve(__dirname, ".")
|
|
11
|
+
});
|
|
8
12
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
var baseFn = {
|
|
14
|
+
baseControllerFn: base_default,
|
|
15
|
+
baseServiceFn: bese_default
|
|
12
16
|
};
|
|
13
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
export { baseFn, modelLoader, serverStart };
|
package/esm/packages/core/env.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
//#region packages/core/env.ts
|
|
2
|
+
var env_default = () => {
|
|
3
|
+
return {
|
|
4
|
+
isLocal() {
|
|
5
|
+
return process.env._ENV === "local";
|
|
6
|
+
},
|
|
7
|
+
isBate() {
|
|
8
|
+
return process.env._ENV === "bate";
|
|
9
|
+
},
|
|
10
|
+
isProd() {
|
|
11
|
+
return process.env._ENV === "prod";
|
|
12
|
+
},
|
|
13
|
+
get() {
|
|
14
|
+
return process.env._ENV ?? "local";
|
|
15
|
+
},
|
|
16
|
+
getEnvKeys() {
|
|
17
|
+
return {
|
|
18
|
+
local: "local",
|
|
19
|
+
bate: "bate",
|
|
20
|
+
prod: "prod"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
23
24
|
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { env_default as default };
|
|
@@ -1,109 +1,101 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./
|
|
3
|
-
import "
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import configLoader from "./loader/config.js";
|
|
11
|
-
import extendLoader from "./loader/extend.js";
|
|
1
|
+
import { __require } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import env_default from "./env.js";
|
|
3
|
+
import middleware_default from "./loader/middleware.js";
|
|
4
|
+
import router_schema_default from "./loader/router-schema.js";
|
|
5
|
+
import router_default from "./loader/router.js";
|
|
6
|
+
import controller_default from "./loader/controller.js";
|
|
7
|
+
import service_default from "./loader/service.js";
|
|
8
|
+
import config_default from "./loader/config.js";
|
|
9
|
+
import extend_default from "./loader/extend.js";
|
|
12
10
|
import modelLoader from "./loader/model.js";
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
return app;
|
|
11
|
+
import { runFileFn } from "@tc/utils";
|
|
12
|
+
import Koa from "koa";
|
|
13
|
+
import { resolve as resolve$1 } from "@tc/utils/path";
|
|
14
|
+
//#region packages/core/index.ts
|
|
15
|
+
var loaderModel = modelLoader;
|
|
16
|
+
var start = (options = {}) => {
|
|
17
|
+
const app = new Koa();
|
|
18
|
+
const { frameBaseDir: _frameBaseDir, ..._options } = options;
|
|
19
|
+
app.options = _options;
|
|
20
|
+
const baseDir = app.baseDir = process.cwd();
|
|
21
|
+
const frameBaseDir = app.frameBaseDir = _frameBaseDir ?? resolve$1(__dirname, "..");
|
|
22
|
+
app.businessPath = resolve$1(baseDir, "app");
|
|
23
|
+
app.framePath = resolve$1(frameBaseDir, "app");
|
|
24
|
+
app.paths = [{
|
|
25
|
+
type: "frame",
|
|
26
|
+
path: app.framePath
|
|
27
|
+
}, {
|
|
28
|
+
type: "business",
|
|
29
|
+
path: app.businessPath
|
|
30
|
+
}];
|
|
31
|
+
app.envs = env_default();
|
|
32
|
+
console.log(`-- [start] env: ${app.envs.get()} --`);
|
|
33
|
+
/**
|
|
34
|
+
* 第一个挂载
|
|
35
|
+
* 方便后续 所有带有app的方法中可以通过 app.config 获取配置
|
|
36
|
+
*/
|
|
37
|
+
config_default(app);
|
|
38
|
+
console.log(`-- [start] loader config done --`);
|
|
39
|
+
/**
|
|
40
|
+
* 第二个挂载 扩展的方法
|
|
41
|
+
* 因不确定会在何处调用 app.[extendFN]
|
|
42
|
+
* 所以需要调高挂载顺序
|
|
43
|
+
*/
|
|
44
|
+
extend_default(app);
|
|
45
|
+
console.log(`-- [start] loader extend done --`);
|
|
46
|
+
/**
|
|
47
|
+
* 参数校验规则,在中间件之前即可
|
|
48
|
+
*/
|
|
49
|
+
router_schema_default(app);
|
|
50
|
+
console.log(`-- [start] loader routerSchema done --`);
|
|
51
|
+
/**
|
|
52
|
+
* service 在 controller 之前即可
|
|
53
|
+
* 以下俩loader在router前即可
|
|
54
|
+
*/
|
|
55
|
+
service_default(app);
|
|
56
|
+
console.log(`-- [start] loader service done --`);
|
|
57
|
+
controller_default(app);
|
|
58
|
+
console.log(`-- [start] loader controller done --`);
|
|
59
|
+
/**
|
|
60
|
+
* 挂载中间件文件
|
|
61
|
+
*/
|
|
62
|
+
middleware_default(app);
|
|
63
|
+
console.log(`-- [start] loader middleware done --`);
|
|
64
|
+
mountMiddleware(app);
|
|
65
|
+
router_default(app);
|
|
66
|
+
console.log(`-- [start] loader router done --`);
|
|
67
|
+
try {
|
|
68
|
+
const _p = app.config.port || process.env.PORT || "8080";
|
|
69
|
+
const port = parseInt(_p + "", 10);
|
|
70
|
+
const host = process.env.IP || "0.0.0.0";
|
|
71
|
+
app.listen(port, host);
|
|
72
|
+
console.log(`Server port:${port}`);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error(error);
|
|
75
|
+
}
|
|
76
|
+
return app;
|
|
81
77
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
if (!loaded && lastError) {
|
|
105
|
-
console.log(`-- [error] loader ${pathInfo.type} appMiddlerare middleware.(ts|js) error -- (${pathInfo.path})`);
|
|
106
|
-
console.log(lastError);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
78
|
+
var mountMiddleware = (app) => {
|
|
79
|
+
app.paths.forEach((pathInfo) => {
|
|
80
|
+
let loaded = false;
|
|
81
|
+
let lastError = void 0;
|
|
82
|
+
for (const fileSymbol of ["ts", "js"]) {
|
|
83
|
+
const fileName = `middleware.${fileSymbol}`;
|
|
84
|
+
try {
|
|
85
|
+
runFileFn(__require(resolve$1(pathInfo.path, fileName)))?.(app);
|
|
86
|
+
console.log(`-- [start] loader ${pathInfo.type} appMiddlerare ${fileName} done -- (${pathInfo.path})`);
|
|
87
|
+
loaded = true;
|
|
88
|
+
break;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const err = error;
|
|
91
|
+
if (!(err?.code === "MODULE_NOT_FOUND" && typeof err?.message === "string" && err.message.includes(fileName))) lastError = error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!loaded && lastError) {
|
|
95
|
+
console.log(`-- [error] loader ${pathInfo.type} appMiddlerare middleware.(ts|js) error -- (${pathInfo.path})`);
|
|
96
|
+
console.log(lastError);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
109
99
|
};
|
|
100
|
+
//#endregion
|
|
101
|
+
export { loaderModel, start };
|