@_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
|
@@ -1,132 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const loadFile_1 = require("../../utils/loadFile");
|
|
8
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let path = require("path");
|
|
3
|
+
let _tc_utils_loadFile = require("@tc/utils/loadFile");
|
|
4
|
+
let lodash = require("lodash");
|
|
5
|
+
lodash = require_runtime.__toESM(lodash, 1);
|
|
6
|
+
//#region packages/core/loader/model.ts
|
|
9
7
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
modelConfig.forEach((config) => {
|
|
49
|
-
const { model, project } = config;
|
|
50
|
-
for (const key in project) {
|
|
51
|
-
const projectConfig = project[key];
|
|
52
|
-
if (projectConfig) {
|
|
53
|
-
project[key] = etendsObj(model, projectConfig);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return modelConfig;
|
|
8
|
+
*
|
|
9
|
+
* @param app
|
|
10
|
+
*/
|
|
11
|
+
var modelLoader = (app) => {
|
|
12
|
+
/**
|
|
13
|
+
* @type {ModelConfig}
|
|
14
|
+
*/
|
|
15
|
+
const modelConfig = [];
|
|
16
|
+
(0, _tc_utils_loadFile.loadFileFn)(app.baseDir, "model", {
|
|
17
|
+
/**
|
|
18
|
+
* 1.遍历当前文件夹
|
|
19
|
+
* 2.根据路径区分 model | project
|
|
20
|
+
* 3.根据不同的 类型后去key
|
|
21
|
+
*/
|
|
22
|
+
loadFileCallback: (file) => {
|
|
23
|
+
if (file.indexOf(`model${path.sep}index.js`) === -1) {
|
|
24
|
+
const filePathChunk = file.split(path.sep);
|
|
25
|
+
if (filePathChunk[filePathChunk.length - 2] === "project") {
|
|
26
|
+
const modelKey = filePathChunk[filePathChunk.length - 3];
|
|
27
|
+
const projectKey = filePathChunk[filePathChunk.length - 1]?.split(".")[0];
|
|
28
|
+
if (modelKey && projectKey) setProject(modelConfig, modelKey, projectKey, file);
|
|
29
|
+
} else {
|
|
30
|
+
const modelKey = filePathChunk[filePathChunk.length - 2];
|
|
31
|
+
if (modelKey) setModel(modelConfig, modelKey, file);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} });
|
|
35
|
+
modelConfig.forEach((config) => {
|
|
36
|
+
const { model, project } = config;
|
|
37
|
+
for (const key in project) {
|
|
38
|
+
const projectConfig = project[key];
|
|
39
|
+
if (projectConfig) project[key] = etendsObj(model, projectConfig);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return modelConfig;
|
|
58
43
|
};
|
|
59
44
|
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
*
|
|
46
|
+
* @param model
|
|
47
|
+
* @param project
|
|
48
|
+
*/
|
|
64
49
|
function etendsObj(model, project) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// 新增
|
|
81
|
-
for (let index = 0; index < projectValue.length; index++) {
|
|
82
|
-
const projectItem = projectValue[index];
|
|
83
|
-
const modelItem = modelValue.find((m) => m.key === projectItem.key);
|
|
84
|
-
if (!modelItem) {
|
|
85
|
-
result.push(projectItem);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
50
|
+
return lodash.default.mergeWith({}, model, project, function customizer(modelValue, projectValue) {
|
|
51
|
+
if (Array.isArray(modelValue) && Array.isArray(projectValue)) {
|
|
52
|
+
let result = [];
|
|
53
|
+
for (let index = 0; index < modelValue.length; index++) {
|
|
54
|
+
const modelItem = modelValue[index];
|
|
55
|
+
const projectItem = projectValue.find((p) => p.key === modelItem.key);
|
|
56
|
+
result.push(projectItem ? etendsObj(modelItem, projectItem) : modelItem);
|
|
57
|
+
}
|
|
58
|
+
for (let index = 0; index < projectValue.length; index++) {
|
|
59
|
+
const projectItem = projectValue[index];
|
|
60
|
+
if (!modelValue.find((m) => m.key === projectItem.key)) result.push(projectItem);
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
91
65
|
}
|
|
92
66
|
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
67
|
+
*
|
|
68
|
+
* 副作用函数
|
|
69
|
+
* @param config
|
|
70
|
+
* @param modelKey
|
|
71
|
+
* @param key
|
|
72
|
+
* @param file
|
|
73
|
+
*/
|
|
74
|
+
var setProject = (config, modelKey, key, file) => {
|
|
75
|
+
const currentModel = setModel(config, modelKey);
|
|
76
|
+
const projectItem = {
|
|
77
|
+
key,
|
|
78
|
+
modelKey,
|
|
79
|
+
...require(file)
|
|
80
|
+
};
|
|
81
|
+
currentModel.project[key] = projectItem;
|
|
108
82
|
};
|
|
109
83
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
84
|
+
*
|
|
85
|
+
* 副作用函数
|
|
86
|
+
* @param config
|
|
87
|
+
* @param key
|
|
88
|
+
* @param filePath
|
|
89
|
+
*/
|
|
90
|
+
var setModel = (config, key, filePath) => {
|
|
91
|
+
let modelItem = config.find((i) => i.model.key === key);
|
|
92
|
+
if (!modelItem) {
|
|
93
|
+
const newModel = {
|
|
94
|
+
model: { key },
|
|
95
|
+
project: { key }
|
|
96
|
+
};
|
|
97
|
+
config.push(newModel);
|
|
98
|
+
modelItem = newModel;
|
|
99
|
+
}
|
|
100
|
+
if (filePath) modelItem.model = {
|
|
101
|
+
...require(filePath),
|
|
102
|
+
key
|
|
103
|
+
};
|
|
104
|
+
return modelItem;
|
|
131
105
|
};
|
|
132
|
-
|
|
106
|
+
//#endregion
|
|
107
|
+
module.exports = modelLoader;
|
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
require("../../../_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_packages_core_paths = require("../paths.js");
|
|
3
|
+
let _tc_utils_loadFile = require("@tc/utils/loadFile");
|
|
4
|
+
let _tc_utils_path = require("@tc/utils/path");
|
|
5
|
+
//#region packages/core/loader/router-schema.ts
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
app.routerSchema = routerSchema;
|
|
7
|
+
*
|
|
8
|
+
* router-schema loader 只处理一级
|
|
9
|
+
*
|
|
10
|
+
* @param app
|
|
11
|
+
*
|
|
12
|
+
* xx/app/router-schema/**.js
|
|
13
|
+
*
|
|
14
|
+
* 输出:
|
|
15
|
+
* app.routerSchema = {
|
|
16
|
+
* [api1]: jsonSchema
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var router_schema_default = (app) => {
|
|
22
|
+
let routerSchema = {};
|
|
23
|
+
require_packages_core_paths.getAppPaths(app).forEach((currentPath) => {
|
|
24
|
+
(0, _tc_utils_loadFile.loadFileFn)(currentPath, "router-schema", { preProcessingFileCallback(file) {
|
|
25
|
+
routerSchema = {
|
|
26
|
+
...routerSchema,
|
|
27
|
+
...require((0, _tc_utils_path.resolve)(file))
|
|
28
|
+
};
|
|
29
|
+
} });
|
|
30
|
+
});
|
|
31
|
+
app.routerSchema = routerSchema;
|
|
35
32
|
};
|
|
33
|
+
//#endregion
|
|
34
|
+
module.exports = router_schema_default;
|
|
@@ -1,63 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const paths_1 = require("../paths");
|
|
10
|
-
const utils_1 = require("../../utils/index.js");
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_packages_core_paths = require("../paths.js");
|
|
3
|
+
let _tc_utils = require("@tc/utils");
|
|
4
|
+
let _tc_utils_loadFile = require("@tc/utils/loadFile");
|
|
5
|
+
let _tc_utils_path = require("@tc/utils/path");
|
|
6
|
+
let koa_router = require("koa-router");
|
|
7
|
+
koa_router = require_runtime.__toESM(koa_router, 1);
|
|
8
|
+
//#region packages/core/loader/router.ts
|
|
11
9
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
const executionResults = routerGuard?.(ctx);
|
|
49
|
-
if (executionResults) {
|
|
50
|
-
ctx.redirect(executionResults ?? "/");
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
ctx.status = 404;
|
|
54
|
-
ctx.body = "notFound";
|
|
55
|
-
}
|
|
56
|
-
// throw new Error();
|
|
57
|
-
return;
|
|
58
|
-
// await next();
|
|
59
|
-
});
|
|
60
|
-
app.use(router.routes()); // koa 注入路由 中间件
|
|
61
|
-
app.use(router.allowedMethods()); // 允许所有请求方式
|
|
62
|
-
app.currentUseRouter = router;
|
|
10
|
+
* reouter loader
|
|
11
|
+
*
|
|
12
|
+
* 解析 xx/app/router/下的所有文件 加载到 koa-router上
|
|
13
|
+
*/
|
|
14
|
+
var router_default = (app) => {
|
|
15
|
+
const router = new koa_router.default();
|
|
16
|
+
let routerGuard;
|
|
17
|
+
try {
|
|
18
|
+
const businessPath = require_packages_core_paths.getAppPath(app, "business");
|
|
19
|
+
if (businessPath) routerGuard = (0, _tc_utils.runFileFn)(require((0, _tc_utils_path.resolve)(businessPath, "router-guard.js")))(app);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.info("-- [router-guard] -- not router-guard.js file");
|
|
22
|
+
}
|
|
23
|
+
require_packages_core_paths.getAppPaths(app).forEach((currentPath) => {
|
|
24
|
+
(0, _tc_utils_loadFile.loadFileFn)(currentPath, "router", { preProcessingFileCallback: (filePath) => {
|
|
25
|
+
/**
|
|
26
|
+
* module.export = (app,router) => {
|
|
27
|
+
* router.get('/xxx/xxxx', app.controller)
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
(0, _tc_utils.runFileFn)(require((0, _tc_utils_path.resolve)(filePath)))(app, router);
|
|
31
|
+
} });
|
|
32
|
+
});
|
|
33
|
+
router.get("(.*)", async (ctx, _next) => {
|
|
34
|
+
console.info("\x1B[31m%s\x1B[0m", `-- notFound path: ${ctx.path} --`);
|
|
35
|
+
ctx.status = 302;
|
|
36
|
+
const executionResults = routerGuard?.(ctx);
|
|
37
|
+
if (executionResults) ctx.redirect(executionResults ?? "/");
|
|
38
|
+
else {
|
|
39
|
+
ctx.status = 404;
|
|
40
|
+
ctx.body = "notFound";
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
app.use(router.routes());
|
|
44
|
+
app.use(router.allowedMethods());
|
|
45
|
+
app.currentUseRouter = router;
|
|
63
46
|
};
|
|
47
|
+
//#endregion
|
|
48
|
+
module.exports = router_default;
|
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
require("../../../_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_packages_core_paths = require("../paths.js");
|
|
3
|
+
let _tc_utils = require("@tc/utils");
|
|
4
|
+
let _tc_utils_loadFile = require("@tc/utils/loadFile");
|
|
5
|
+
//#region packages/core/loader/service.ts
|
|
6
6
|
/**
|
|
7
7
|
* 加载 xx/app/service 文件夹下所有文件 可通过'app.service.${目录}..},访问
|
|
8
8
|
*
|
|
9
9
|
例子:
|
|
10
|
-
|
|
10
|
+
app/service
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
|-- cuStom-moduLe
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|-- custom-midd Leware.js
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
}),
|
|
29
|
-
}), {});
|
|
16
|
+
=> app.service.customModule. customMiddleware
|
|
17
|
+
*
|
|
18
|
+
* @param app
|
|
19
|
+
*/
|
|
20
|
+
var service_default = (app) => {
|
|
21
|
+
app.service = require_packages_core_paths.getAppPaths(app).reduce((preData, currentPath) => ({
|
|
22
|
+
...preData,
|
|
23
|
+
...(0, _tc_utils_loadFile.loadFileFn)(currentPath, "service", { loadFileCallback: (file) => {
|
|
24
|
+
return new ((0, _tc_utils.runFileFn)(require(file))(app))();
|
|
25
|
+
} })
|
|
26
|
+
}), {});
|
|
30
27
|
};
|
|
28
|
+
//#endregion
|
|
29
|
+
module.exports = service_default;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.getAppPaths = getAppPaths;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
//#region packages/core/paths.ts
|
|
5
4
|
function getAppPath(app, type) {
|
|
6
|
-
|
|
5
|
+
return app.paths?.find((p) => p.type === type)?.path;
|
|
7
6
|
}
|
|
8
7
|
function getAppPaths(app) {
|
|
9
|
-
|
|
8
|
+
return (app.paths ?? []).map((p) => p.path);
|
|
10
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.getAppPath = getAppPath;
|
|
12
|
+
exports.getAppPaths = getAppPaths;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
require("../../_virtual/_rolldown/runtime.js");
|
|
@@ -1,45 +1,14 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.getAllFilesInFolder = void 0;
|
|
37
|
-
const path_1 = require("./path");
|
|
38
|
-
const glob = __importStar(require("glob"));
|
|
39
|
-
const getAllFilesInFolder = (...paths) => {
|
|
40
|
-
const filePath = (0, path_1.resolve)(...paths);
|
|
41
|
-
const fileList = glob.sync((0, path_1.resolve)(filePath, "**", "*.js"));
|
|
42
|
-
const tFileList = glob.sync((0, path_1.resolve)(filePath, "**", "*.ts")).filter(f => f.indexOf('.d.ts') === -1);
|
|
43
|
-
return [...fileList, ...tFileList];
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_packages_utils_path = require("./path.js");
|
|
4
|
+
let glob = require("glob");
|
|
5
|
+
glob = require_runtime.__toESM(glob, 1);
|
|
6
|
+
//#region packages/utils/getAllFilesInFolder.ts
|
|
7
|
+
var getAllFilesInFolder = (...paths) => {
|
|
8
|
+
const filePath = require_packages_utils_path.resolve(...paths);
|
|
9
|
+
const fileList = glob.sync(require_packages_utils_path.resolve(filePath, "**", "*.js"));
|
|
10
|
+
const tFileList = glob.sync(require_packages_utils_path.resolve(filePath, "**", "*.ts")).filter((f) => f.indexOf(".d.ts") === -1);
|
|
11
|
+
return [...fileList, ...tFileList];
|
|
44
12
|
};
|
|
13
|
+
//#endregion
|
|
45
14
|
exports.getAllFilesInFolder = getAllFilesInFolder;
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./path"), exports);
|
|
18
|
-
__exportStar(require("./loadFile"), exports);
|
|
19
|
-
__exportStar(require("./getAllFilesInFolder"), exports);
|
|
20
|
-
__exportStar(require("./runFileFn"), exports);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_packages_utils_path = require("./path.js");
|
|
4
|
+
const require_packages_utils_getAllFilesInFolder = require("./getAllFilesInFolder.js");
|
|
5
|
+
const require_packages_utils_loadFile = require("./loadFile.js");
|
|
6
|
+
const require_packages_utils_runFileFn = require("./runFileFn.js");
|
|
7
|
+
exports.getAllFilesInFolder = require_packages_utils_getAllFilesInFolder.getAllFilesInFolder;
|
|
8
|
+
exports.loadFileFn = require_packages_utils_loadFile.loadFileFn;
|
|
9
|
+
exports.resolve = require_packages_utils_path.resolve;
|
|
10
|
+
exports.runFileFn = require_packages_utils_runFileFn.runFileFn;
|
|
11
|
+
exports.splicing = require_packages_utils_path.splicing;
|