@_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,43 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { resolve } from "@tc/utils/path";
|
|
3
|
+
import { getAllFilesInFolder } from "@tc/utils/getAllFilesInFolder";
|
|
4
|
+
//#region packages/core/loader/config.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!configMap.default || !configMap[envKey]) {
|
|
38
|
-
console.error(!configMap.default
|
|
39
|
-
? "[excption] Missing default configuration"
|
|
40
|
-
: "[excption] Missing [env] configuration");
|
|
41
|
-
}
|
|
42
|
-
app.config = envConfig;
|
|
6
|
+
* config loader 只处理一级
|
|
7
|
+
*
|
|
8
|
+
* @param app 加载 xx/config/ 下的文件
|
|
9
|
+
* config/config.default.js
|
|
10
|
+
*/
|
|
11
|
+
var config_default = (app) => {
|
|
12
|
+
const files = getAllFilesInFolder(app.baseDir, "config");
|
|
13
|
+
const frameFile = getAllFilesInFolder(app.frameBaseDir, "config");
|
|
14
|
+
const envKey = app.envs.get();
|
|
15
|
+
const configMap = {
|
|
16
|
+
default: false,
|
|
17
|
+
/**
|
|
18
|
+
* @type {typeof envKey}
|
|
19
|
+
*/
|
|
20
|
+
[envKey]: false
|
|
21
|
+
};
|
|
22
|
+
let envConfig = {};
|
|
23
|
+
Object.keys(configMap).forEach((k) => {
|
|
24
|
+
const configPath = [...frameFile, ...files].filter((f) => f.includes(k));
|
|
25
|
+
if (configPath.length) {
|
|
26
|
+
configMap[k] = true;
|
|
27
|
+
const configFile = configPath.reduce((preData, currentPath) => ({
|
|
28
|
+
...preData,
|
|
29
|
+
...__require(resolve(currentPath))
|
|
30
|
+
}), {});
|
|
31
|
+
envConfig = [envConfig, configFile][k === "default" ? "reduceRight" : "reduce"]((o, c) => ({
|
|
32
|
+
...o,
|
|
33
|
+
...c
|
|
34
|
+
}), {});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!configMap.default || !configMap[envKey]) console.error(!configMap.default ? "[excption] Missing default configuration" : "[excption] Missing [env] configuration");
|
|
38
|
+
app.config = envConfig;
|
|
43
39
|
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { config_default as default };
|
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getAppPaths } from "../paths.js";
|
|
3
|
+
import { runFileFn } from "@tc/utils";
|
|
4
|
+
import { loadFileFn } from "@tc/utils/loadFile";
|
|
5
|
+
import { resolve as resolve$1 } from "@tc/utils/path";
|
|
6
|
+
//#region packages/core/loader/controller.ts
|
|
5
7
|
/**
|
|
6
8
|
* 加载 xx/app/controller 文件夹下所有文件,可通过'app.controller.${目录}.'},访问
|
|
7
9
|
*
|
|
8
10
|
例子:
|
|
9
|
-
|
|
11
|
+
app/controller
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
|-- cuStom-moduLe
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
|-- custom-midd Leware.js
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
app.controller = getAppPaths(app).reduce((preData, currentPath) => ({
|
|
30
|
-
...preData,
|
|
31
|
-
...loadFileFn(currentPath, 'controller', {
|
|
32
|
-
loadFileCallback: (file) => {
|
|
33
|
-
const Controller = runFileFn(require(resolve(file)))(app);
|
|
34
|
-
return new Controller();
|
|
35
|
-
},
|
|
36
|
-
}),
|
|
37
|
-
}), {});
|
|
17
|
+
=> app.controller.customModule. customMiddleware
|
|
18
|
+
*
|
|
19
|
+
* @param app
|
|
20
|
+
*/
|
|
21
|
+
var controller_default = (app) => {
|
|
22
|
+
/**
|
|
23
|
+
* 接收的是 (app) => class xxx{}
|
|
24
|
+
*/
|
|
25
|
+
app.controller = getAppPaths(app).reduce((preData, currentPath) => ({
|
|
26
|
+
...preData,
|
|
27
|
+
...loadFileFn(currentPath, "controller", { loadFileCallback: (file) => {
|
|
28
|
+
return new (runFileFn(__require(resolve$1(file)))(app))();
|
|
29
|
+
} })
|
|
30
|
+
}), {});
|
|
38
31
|
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { controller_default as default };
|
|
@@ -1,39 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { resolve } from "../../utils/path.js";
|
|
1
|
+
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
3
2
|
import { getAppPaths } from "../paths.js";
|
|
4
|
-
import { runFileFn } from "
|
|
3
|
+
import { runFileFn } from "@tc/utils";
|
|
4
|
+
import { loadFileFn } from "@tc/utils/loadFile";
|
|
5
|
+
import { resolve as resolve$1 } from "@tc/utils/path";
|
|
6
|
+
//#region packages/core/loader/extend.ts
|
|
5
7
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(async () => {
|
|
28
|
-
app.extends[fileName] = await exs;
|
|
29
|
-
})();
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
app.extends[fileName] = exs;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
}),
|
|
37
|
-
});
|
|
38
|
-
});
|
|
8
|
+
* extend loader 扩展 koa app属性 只加载一级
|
|
9
|
+
*
|
|
10
|
+
* 加载 xx/app/extend 文件,可通过 'app.extends.${文件}' 访问
|
|
11
|
+
*/
|
|
12
|
+
var extend_default = (app) => {
|
|
13
|
+
app.extends = { ...app.extends };
|
|
14
|
+
getAppPaths(app).forEach((currentPath) => {
|
|
15
|
+
loadFileFn(currentPath, "extend", { processingFileCallback: ((fileName, filePath, isDir) => {
|
|
16
|
+
if (!isDir) {
|
|
17
|
+
for (const key in app) if (key === fileName) {
|
|
18
|
+
console.log("\x1B[31m%s\x1B[0m", `[extend loader error] name:${fileName} is already in app`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const exs = runFileFn(__require(resolve$1(filePath)))(app);
|
|
22
|
+
if (exs instanceof Promise) (async () => {
|
|
23
|
+
app.extends[fileName] = await exs;
|
|
24
|
+
})();
|
|
25
|
+
else app.extends[fileName] = exs;
|
|
26
|
+
}
|
|
27
|
+
}) });
|
|
28
|
+
});
|
|
39
29
|
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { extend_default as default };
|
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getAppPaths } from
|
|
3
|
-
import { runFileFn } from
|
|
1
|
+
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getAppPaths } from "../paths.js";
|
|
3
|
+
import { runFileFn } from "@tc/utils";
|
|
4
|
+
import { loadFileFn } from "@tc/utils/loadFile";
|
|
5
|
+
//#region packages/core/loader/middleware.ts
|
|
4
6
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// });
|
|
27
|
-
// app.middlewares = { ...frameMiddlewares, ...businessMiddlewares };
|
|
28
|
-
app.middlewares = getAppPaths(app).reduce((preData, currentPath) => {
|
|
29
|
-
const middlewares = loadFileFn(currentPath, 'middleware', {
|
|
30
|
-
loadFileCallback: (path) => {
|
|
31
|
-
return runFileFn(require(path))(app);
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
return { ...preData, ...middlewares };
|
|
35
|
-
}, {});
|
|
7
|
+
*
|
|
8
|
+
* middleware loader
|
|
9
|
+
*
|
|
10
|
+
* @param app
|
|
11
|
+
*
|
|
12
|
+
* 加载 xx/app/middleware 文件夹下所有文件,可通过 'app.middleware.${目录}.${文件}' 访问
|
|
13
|
+
*/
|
|
14
|
+
var middleware_default = (app) => {
|
|
15
|
+
/**
|
|
16
|
+
* xx/app/middleware/a/a.js -> app.middleware.a.a =
|
|
17
|
+
* require('app/middleware/a/a.js')(app)
|
|
18
|
+
*/
|
|
19
|
+
app.middlewares = getAppPaths(app).reduce((preData, currentPath) => {
|
|
20
|
+
const middlewares = loadFileFn(currentPath, "middleware", { loadFileCallback: (path) => {
|
|
21
|
+
return runFileFn(__require(path))(app);
|
|
22
|
+
} });
|
|
23
|
+
return {
|
|
24
|
+
...preData,
|
|
25
|
+
...middlewares
|
|
26
|
+
};
|
|
27
|
+
}, {});
|
|
36
28
|
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { middleware_default as default };
|
|
@@ -1,127 +1,106 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { sep } from "path";
|
|
3
|
+
import { loadFileFn } from "@tc/utils/loadFile";
|
|
4
|
+
import _ from "lodash";
|
|
5
|
+
//#region packages/core/loader/model.ts
|
|
4
6
|
/**
|
|
5
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
// 数据进行继承
|
|
43
|
-
modelConfig.forEach((config) => {
|
|
44
|
-
const { model, project } = config;
|
|
45
|
-
for (const key in project) {
|
|
46
|
-
const projectConfig = project[key];
|
|
47
|
-
if (projectConfig) {
|
|
48
|
-
project[key] = etendsObj(model, projectConfig);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return modelConfig;
|
|
7
|
+
*
|
|
8
|
+
* @param app
|
|
9
|
+
*/
|
|
10
|
+
var modelLoader = (app) => {
|
|
11
|
+
/**
|
|
12
|
+
* @type {ModelConfig}
|
|
13
|
+
*/
|
|
14
|
+
const modelConfig = [];
|
|
15
|
+
loadFileFn(app.baseDir, "model", {
|
|
16
|
+
/**
|
|
17
|
+
* 1.遍历当前文件夹
|
|
18
|
+
* 2.根据路径区分 model | project
|
|
19
|
+
* 3.根据不同的 类型后去key
|
|
20
|
+
*/
|
|
21
|
+
loadFileCallback: (file) => {
|
|
22
|
+
if (file.indexOf(`model${sep}index.js`) === -1) {
|
|
23
|
+
const filePathChunk = file.split(sep);
|
|
24
|
+
if (filePathChunk[filePathChunk.length - 2] === "project") {
|
|
25
|
+
const modelKey = filePathChunk[filePathChunk.length - 3];
|
|
26
|
+
const projectKey = filePathChunk[filePathChunk.length - 1]?.split(".")[0];
|
|
27
|
+
if (modelKey && projectKey) setProject(modelConfig, modelKey, projectKey, file);
|
|
28
|
+
} else {
|
|
29
|
+
const modelKey = filePathChunk[filePathChunk.length - 2];
|
|
30
|
+
if (modelKey) setModel(modelConfig, modelKey, file);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} });
|
|
34
|
+
modelConfig.forEach((config) => {
|
|
35
|
+
const { model, project } = config;
|
|
36
|
+
for (const key in project) {
|
|
37
|
+
const projectConfig = project[key];
|
|
38
|
+
if (projectConfig) project[key] = etendsObj(model, projectConfig);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return modelConfig;
|
|
53
42
|
};
|
|
54
43
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
*
|
|
45
|
+
* @param model
|
|
46
|
+
* @param project
|
|
47
|
+
*/
|
|
59
48
|
function etendsObj(model, project) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// 新增
|
|
76
|
-
for (let index = 0; index < projectValue.length; index++) {
|
|
77
|
-
const projectItem = projectValue[index];
|
|
78
|
-
const modelItem = modelValue.find((m) => m.key === projectItem.key);
|
|
79
|
-
if (!modelItem) {
|
|
80
|
-
result.push(projectItem);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
49
|
+
return _.mergeWith({}, model, project, function customizer(modelValue, projectValue) {
|
|
50
|
+
if (Array.isArray(modelValue) && Array.isArray(projectValue)) {
|
|
51
|
+
let result = [];
|
|
52
|
+
for (let index = 0; index < modelValue.length; index++) {
|
|
53
|
+
const modelItem = modelValue[index];
|
|
54
|
+
const projectItem = projectValue.find((p) => p.key === modelItem.key);
|
|
55
|
+
result.push(projectItem ? etendsObj(modelItem, projectItem) : modelItem);
|
|
56
|
+
}
|
|
57
|
+
for (let index = 0; index < projectValue.length; index++) {
|
|
58
|
+
const projectItem = projectValue[index];
|
|
59
|
+
if (!modelValue.find((m) => m.key === projectItem.key)) result.push(projectItem);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
86
64
|
}
|
|
87
65
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
66
|
+
*
|
|
67
|
+
* 副作用函数
|
|
68
|
+
* @param config
|
|
69
|
+
* @param modelKey
|
|
70
|
+
* @param key
|
|
71
|
+
* @param file
|
|
72
|
+
*/
|
|
73
|
+
var setProject = (config, modelKey, key, file) => {
|
|
74
|
+
const currentModel = setModel(config, modelKey);
|
|
75
|
+
const projectItem = {
|
|
76
|
+
key,
|
|
77
|
+
modelKey,
|
|
78
|
+
...__require(file)
|
|
79
|
+
};
|
|
80
|
+
currentModel.project[key] = projectItem;
|
|
103
81
|
};
|
|
104
82
|
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
83
|
+
*
|
|
84
|
+
* 副作用函数
|
|
85
|
+
* @param config
|
|
86
|
+
* @param key
|
|
87
|
+
* @param filePath
|
|
88
|
+
*/
|
|
89
|
+
var setModel = (config, key, filePath) => {
|
|
90
|
+
let modelItem = config.find((i) => i.model.key === key);
|
|
91
|
+
if (!modelItem) {
|
|
92
|
+
const newModel = {
|
|
93
|
+
model: { key },
|
|
94
|
+
project: { key }
|
|
95
|
+
};
|
|
96
|
+
config.push(newModel);
|
|
97
|
+
modelItem = newModel;
|
|
98
|
+
}
|
|
99
|
+
if (filePath) modelItem.model = {
|
|
100
|
+
...__require(filePath),
|
|
101
|
+
key
|
|
102
|
+
};
|
|
103
|
+
return modelItem;
|
|
126
104
|
};
|
|
127
|
-
|
|
105
|
+
//#endregion
|
|
106
|
+
export { modelLoader as default };
|
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getAppPaths } from "../paths.js";
|
|
3
|
+
import { loadFileFn } from "@tc/utils/loadFile";
|
|
4
|
+
import { resolve } from "@tc/utils/path";
|
|
5
|
+
//#region packages/core/loader/router-schema.ts
|
|
4
6
|
/**
|
|
5
|
-
|
|
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
|
-
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
|
+
getAppPaths(app).forEach((currentPath) => {
|
|
24
|
+
loadFileFn(currentPath, "router-schema", { preProcessingFileCallback(file) {
|
|
25
|
+
routerSchema = {
|
|
26
|
+
...routerSchema,
|
|
27
|
+
...__require(resolve(file))
|
|
28
|
+
};
|
|
29
|
+
} });
|
|
30
|
+
});
|
|
31
|
+
app.routerSchema = routerSchema;
|
|
33
32
|
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { router_schema_default as default };
|