@_tc/template-core 0.0.1-bate.37 → 0.0.1-bate.39
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/bundler/utils.js +13 -5
- package/cjs/packages/core/index.js +1 -1
- package/cjs/packages/core/loader/config.js +4 -2
- package/cjs/packages/core/loader/controller.js +2 -3
- package/cjs/packages/core/loader/extend.js +1 -2
- package/cjs/packages/core/loader/middleware.js +2 -3
- package/cjs/packages/core/loader/model.js +7 -3
- package/cjs/packages/core/loader/router-schema.js +4 -2
- package/cjs/packages/core/loader/router.js +10 -6
- package/cjs/packages/core/loader/service.js +2 -2
- package/cjs/packages/utils/runFileFn.js +46 -1
- package/esm/bundler/utils.js +13 -5
- package/esm/packages/core/index.js +1 -2
- package/esm/packages/core/loader/config.js +4 -3
- package/esm/packages/core/loader/controller.js +2 -4
- package/esm/packages/core/loader/extend.js +1 -3
- package/esm/packages/core/loader/middleware.js +2 -4
- package/esm/packages/core/loader/model.js +7 -4
- package/esm/packages/core/loader/router-schema.js +4 -3
- package/esm/packages/core/loader/router.js +10 -7
- package/esm/packages/core/loader/service.js +2 -3
- package/esm/packages/utils/runFileFn.js +47 -1
- package/fe/frontend/dash/Dashboard.js +11 -1
- package/fe/frontend/dash/dash.entry.js +19 -1
- package/fe/frontend/main.js +2 -0
- package/fe/frontend/widgets/common/CRUD/CRUD.js +1 -0
- package/fe/frontend/widgets/common/importComponent.js +1 -0
- package/fe/frontend/widgets/common/language.js +1 -0
- package/fe/frontend/widgets/common/menu.d.ts +12 -0
- package/fe/frontend/widgets/common/menu.js +21 -0
- package/fe/frontend/widgets/common/request.d.ts +3 -0
- package/fe/frontend/widgets/common/request.js +6 -0
- package/fe/frontend/widgets/components/BasePage/HeaderView.js +3 -1
- package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/PopFrom.js +15 -0
- package/fe/frontend/widgets/defaultPages/Schema/components/SchemaSearch/index.js +5 -0
- package/fe/frontend/widgets/defaultPages/Schema/components/SchemaTable/index.js +13 -1
- package/fe/frontend/widgets/defaultPages/Schema/data/eventInfo.js +4 -4
- package/fe/frontend/widgets/defaultPages/Schema/index.js +7 -0
- package/fe/frontend/widgets/defaultPages/Schema/schemaType.d.ts +9 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaEventBus.d.ts +19 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaEventBus.js +4 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaStore.d.ts +14 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaStore.js +2 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/schemaConversion.js +43 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/validator.d.ts +3 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/validator.js +5 -0
- package/fe/frontend/widgets/defaultPages/SidebarSlotPage/SidebarSlotContainer.js +7 -0
- package/fe/frontend/widgets/defaultPages/SidebarSlotPage/index.js +1 -0
- package/fe/frontend/widgets/defaultPages/SlotPage/index.js +2 -0
- package/fe/frontend/widgets/hooks/useCurrentMenuData.d.ts +8 -0
- package/fe/frontend/widgets/hooks/useCurrentMenuData.js +8 -0
- package/fe/frontend/widgets/store/mode.d.ts +3 -0
- package/fe/frontend/widgets/store/mode.js +1 -0
- package/fe/model/types/data/button.d.ts +9 -0
- package/fe/model/types/data/button.js +15 -0
- package/fe/model/types/data/component.d.ts +24 -0
- package/fe/model/types/data/component.js +10 -0
- package/fe/model/types/data/fetchInfo.d.ts +12 -0
- package/fe/model/types/data/schema.d.ts +51 -0
- package/fe/model/types/menuType.d.ts +29 -0
- package/fe/model/types/model.d.ts +13 -0
- package/fe/packages/common/i18n/default.d.ts +5 -0
- package/fe/packages/common/i18n/default.js +5 -0
- package/fe/packages/common/i18n/en-US.d.ts +5 -0
- package/fe/packages/common/i18n/en-US.js +5 -0
- package/fe/packages/common/i18n/index.d.ts +24 -0
- package/fe/packages/common/i18n/index.js +31 -0
- package/fe/packages/common/i18n/types.d.ts +24 -0
- package/fe/packages/ui/react/components/Button/Button.d.ts +33 -0
- package/fe/packages/ui/react/components/Button/Button.js +3 -0
- package/fe/packages/ui/react/components/Button/SumbitButton.d.ts +4 -0
- package/fe/packages/ui/react/components/Button/SumbitButton.js +4 -0
- package/fe/packages/ui/react/components/ConfirmDialog/ConfirmDialog.d.ts +8 -0
- package/fe/packages/ui/react/components/DataTable/index.d.ts +19 -0
- package/fe/packages/ui/react/components/DataTable/index.js +4 -0
- package/fe/packages/ui/react/components/Date/Calendar.d.ts +13 -0
- package/fe/packages/ui/react/components/Date/Calendar.js +10 -1
- package/fe/packages/ui/react/components/Date/Date.d.ts +11 -0
- package/fe/packages/ui/react/components/Date/Date.js +19 -0
- package/fe/packages/ui/react/components/Date/LocaleContext.d.ts +4 -0
- package/fe/packages/ui/react/components/Date/LocaleContext.js +4 -0
- package/fe/packages/ui/react/components/Date/LocaleProvider.d.ts +11 -0
- package/fe/packages/ui/react/components/Date/LocaleProvider.js +11 -0
- package/fe/packages/ui/react/components/Date/TimePicker.js +1 -0
- package/fe/packages/ui/react/components/Date/dateLocaleStore.d.ts +6 -0
- package/fe/packages/ui/react/components/Date/locales.d.ts +19 -0
- package/fe/packages/ui/react/components/Date/locales.js +9 -0
- package/fe/packages/ui/react/components/Drawer/Drawer.d.ts +6 -0
- package/fe/packages/ui/react/components/Dropdown/Dropdown.d.ts +1 -0
- package/fe/packages/ui/react/components/Form/Form.d.ts +6 -0
- package/fe/packages/ui/react/components/Form/FormItem.d.ts +21 -0
- package/fe/packages/ui/react/components/Form/FormItem.js +8 -1
- package/fe/packages/ui/react/components/Form/SchemaForm/data.js +1 -0
- package/fe/packages/ui/react/components/Form/SchemaForm/index.d.ts +93 -0
- package/fe/packages/ui/react/components/Form/SchemaForm/index.js +5 -1
- package/fe/packages/ui/react/components/ImagePreview/ImagePreview.js +8 -0
- package/fe/packages/ui/react/components/ImagePreview/PreviewImage.d.ts +3 -0
- package/fe/packages/ui/react/components/Input/Input.d.ts +22 -0
- package/fe/packages/ui/react/components/Input/Input.js +3 -0
- package/fe/packages/ui/react/components/InputNumber/InputNumber.d.ts +2 -0
- package/fe/packages/ui/react/components/Label/Label.d.ts +29 -0
- package/fe/packages/ui/react/components/Label/Label.js +2 -0
- package/fe/packages/ui/react/components/Menu/Menu.js +4 -0
- package/fe/packages/ui/react/components/Menu/SubMenu.d.ts +7 -0
- package/fe/packages/ui/react/components/Menu/SubMenu.js +46 -1
- package/fe/packages/ui/react/components/Menu/menuTypes.d.ts +1 -0
- package/fe/packages/ui/react/components/Message/Message.d.ts +7 -0
- package/fe/packages/ui/react/components/Message/Message.js +3 -0
- package/fe/packages/ui/react/components/Message/MessageManager.js +8 -0
- package/fe/packages/ui/react/components/Modal/Modal.d.ts +6 -0
- package/fe/packages/ui/react/components/Modal/Modal.js +1 -0
- package/fe/packages/ui/react/components/Modal/ModalManager.d.ts +12 -0
- package/fe/packages/ui/react/components/Modal/ModalManager.js +4 -1
- package/fe/packages/ui/react/components/Overlay/Overlay.d.ts +3 -0
- package/fe/packages/ui/react/components/Pagination/Pagination.d.ts +7 -0
- package/fe/packages/ui/react/components/Pagination/Pagination.js +8 -1
- package/fe/packages/ui/react/components/Popup/Popup.js +14 -2
- package/fe/packages/ui/react/components/Search/Search.d.ts +3 -0
- package/fe/packages/ui/react/components/Select/Select.d.ts +5 -0
- package/fe/packages/ui/react/components/Select/Select.js +4 -0
- package/fe/packages/ui/react/components/Skeleton/Skeleton.d.ts +15 -0
- package/fe/packages/ui/react/components/Skeleton/Skeleton.js +1 -1
- package/fe/packages/ui/react/components/TableSearch/TableSearch.d.ts +37 -0
- package/fe/packages/ui/react/components/TableSearch/TableSearch.js +4 -1
- package/fe/packages/ui/react/components/Textarea/Textarea.d.ts +46 -0
- package/fe/packages/ui/react/components/Textarea/Textarea.js +1 -0
- package/fe/packages/ui/react/components/Tooltip/Tooltip.d.ts +16 -0
- package/fe/packages/ui/react/components/Tooltip/Tooltip.js +8 -0
- package/fe/packages/ui/react/components/TreeSelect/TreeSelect.d.ts +6 -0
- package/fe/packages/ui/react/components/TreeSelect/TreeSelect.js +6 -0
- package/fe/packages/ui/react/components/Upload/Upload.d.ts +27 -0
- package/fe/packages/ui/react/components/breadcrumb/breadcrumb.js +9 -0
- package/fe/packages/ui/react/components/hooks/useDropdownPositioning.d.ts +6 -0
- package/fe/packages/ui/react/components/hooks/useDropdownPositioning.js +14 -0
- package/fe/packages/ui/react/components/hooks/useInputController.d.ts +3 -0
- package/fe/packages/ui/react/components/hooks/useInputController.js +7 -0
- package/fe/packages/ui/react/components/testPage/MenuTestPage.js +3 -0
- package/fe/packages/ui/react/components/testPage/index.js +26 -0
- package/fe/packages/ui/react/hooks/useExecuteOnce.d.ts +19 -1
- package/fe/packages/ui/react/hooks/useExecuteOnce.js +22 -1
- package/fe/packages/ui/react/hooks/useRefState.d.ts +12 -0
- package/fe/packages/ui/react/hooks/useRefState.js +1 -0
- package/fe/packages/ui/react/hooks/useWatch.d.ts +8 -0
- package/fe/packages/ui/react/i18n/I18nProvider.d.ts +18 -0
- package/fe/packages/ui/react/i18n/useI18n.d.ts +4 -0
- package/fe/packages/ui/react/i18n/useI18n.js +4 -0
- package/fe/packages/ui/react/index.js +2 -0
- package/fe/packages/ui/react/lib/export.d.ts +44 -0
- package/fe/packages/ui/react/lib/export.js +40 -0
- package/fe/packages/ui/react/lib/utils.d.ts +24 -0
- package/fe/packages/ui/react/lib/utils.js +25 -0
- package/fe/packages/ui/react/stores/breadcrumb.js +2 -0
- package/model/index.d.ts +2 -0
- package/model/types/data/button.d.ts +32 -0
- package/model/types/data/component.d.ts +61 -0
- package/model/types/data/fetchInfo.d.ts +20 -0
- package/model/types/data/schema.d.ts +98 -0
- package/model/types/data/search.d.ts +7 -0
- package/model/types/index.d.ts +2 -0
- package/model/types/menuType.d.ts +73 -0
- package/model/types/model.d.ts +33 -0
- package/model/types/test.d.ts +2 -0
- package/package.json +10 -7
- package/types/packages/utils/runFileFn.d.ts +5 -3
package/cjs/bundler/utils.js
CHANGED
|
@@ -7,17 +7,23 @@ let path = require("path");
|
|
|
7
7
|
path = require_runtime.__toESM(path);
|
|
8
8
|
let glob = require("glob");
|
|
9
9
|
glob = require_runtime.__toESM(glob);
|
|
10
|
+
let fs = require("fs");
|
|
10
11
|
let _tailwindcss_vite = require("@tailwindcss/vite");
|
|
11
12
|
_tailwindcss_vite = require_runtime.__toESM(_tailwindcss_vite);
|
|
12
|
-
let
|
|
13
|
+
let module$1 = require("module");
|
|
14
|
+
let url = require("url");
|
|
13
15
|
let vite = require("vite");
|
|
14
16
|
//#region bundler/utils.ts
|
|
17
|
+
var currentFile = typeof __filename === "string" ? __filename : (0, url.fileURLToPath)({}.url);
|
|
18
|
+
var currentDir = path.default.dirname(currentFile);
|
|
15
19
|
var base = process.cwd();
|
|
16
|
-
var
|
|
17
|
-
var
|
|
20
|
+
var requireFromFrame = (0, module$1.createRequire)(currentFile);
|
|
21
|
+
var framePath = path.default.resolve(currentDir, "../../");
|
|
22
|
+
var frameNodePath = path.default.resolve(currentDir, "../");
|
|
18
23
|
var frameFEPath = path.default.resolve(framePath, "./fe/frontend");
|
|
19
24
|
var runPath = path.default.resolve(base, ".");
|
|
20
25
|
var runFEPath = path.default.resolve(runPath, "./frontend");
|
|
26
|
+
var resolvePackageDir = (packageName) => path.default.dirname(requireFromFrame.resolve(`${packageName}/package.json`));
|
|
21
27
|
/**
|
|
22
28
|
*
|
|
23
29
|
* 寻找 frontend\/**\/*.entry.[j|t]s(x)?
|
|
@@ -145,7 +151,7 @@ function resolveAliasWithFallback(aliasList) {
|
|
|
145
151
|
];
|
|
146
152
|
return aliasList.reduce((o, [aliasName, aliasPath]) => {
|
|
147
153
|
const businessFilePath = aliasExtensions.map((ext) => path.default.resolve(runFEPath, aliasPath + ext)).find((filePath) => (0, fs.existsSync)(filePath));
|
|
148
|
-
let filePath = path.default.resolve(
|
|
154
|
+
let filePath = path.default.resolve(currentDir, "./defaultAlias");
|
|
149
155
|
if (businessFilePath) filePath = businessFilePath;
|
|
150
156
|
o[aliasName] = filePath;
|
|
151
157
|
return o;
|
|
@@ -168,7 +174,9 @@ var VBuildFE = async (input, OperatingEnv) => {
|
|
|
168
174
|
rollupOptions: { input }
|
|
169
175
|
},
|
|
170
176
|
resolve: { alias: {
|
|
171
|
-
"@tc/ui-react": path.default.resolve(
|
|
177
|
+
"@tc/ui-react": path.default.resolve(currentDir, "../../fe/packages/ui/react/"),
|
|
178
|
+
react: resolvePackageDir("react"),
|
|
179
|
+
"react-dom": resolvePackageDir("react-dom"),
|
|
172
180
|
...resolveAliasWithFallback([["$business/SchemaForm/data", "./extended/SchemaForm/data"]])
|
|
173
181
|
} }
|
|
174
182
|
});
|
|
@@ -90,7 +90,7 @@ var mountMiddleware = (app) => {
|
|
|
90
90
|
for (const fileSymbol of ["ts", "js"]) {
|
|
91
91
|
const fileName = `middleware.${fileSymbol}`;
|
|
92
92
|
try {
|
|
93
|
-
require_packages_utils_runFileFn.runFileFn(
|
|
93
|
+
require_packages_utils_runFileFn.runFileFn(require_packages_utils_path.resolve(pathInfo.path, fileName))?.(app);
|
|
94
94
|
console.log(`-- [init] loader ${pathInfo.type} appMiddlerare ${fileName} done -- (${pathInfo.path})`);
|
|
95
95
|
loaded = true;
|
|
96
96
|
break;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
require("../../../_virtual/_rolldown/runtime.js");
|
|
2
2
|
const require_packages_utils_path = require("../../utils/path.js");
|
|
3
3
|
const require_packages_utils_getAllFilesInFolder = require("../../utils/getAllFilesInFolder.js");
|
|
4
|
+
const require_packages_utils_runFileFn = require("../../utils/runFileFn.js");
|
|
5
|
+
require("../../utils/index.js");
|
|
4
6
|
//#region packages/core/loader/config.ts
|
|
5
7
|
/**
|
|
6
8
|
* config loader 只处理一级
|
|
7
9
|
*
|
|
8
10
|
* @param app 加载 xx/config/ 下的文件
|
|
9
|
-
* config/config.default.js
|
|
11
|
+
* config/config.default.(js|ts)
|
|
10
12
|
*/
|
|
11
13
|
var config_default = (app) => {
|
|
12
14
|
const files = require_packages_utils_getAllFilesInFolder.getAllFilesInFolder(app.baseDir, "config");
|
|
@@ -26,7 +28,7 @@ var config_default = (app) => {
|
|
|
26
28
|
configMap[k] = true;
|
|
27
29
|
const configFile = configPath.reduce((preData, currentPath) => ({
|
|
28
30
|
...preData,
|
|
29
|
-
...
|
|
31
|
+
...require_packages_utils_runFileFn.runFileFn(require_packages_utils_path.resolve(currentPath))
|
|
30
32
|
}), {});
|
|
31
33
|
envConfig = [envConfig, configFile][k === "default" ? "reduceRight" : "reduce"]((o, c) => ({
|
|
32
34
|
...o,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
require("../../../_virtual/_rolldown/runtime.js");
|
|
2
2
|
const require_packages_core_paths = require("../paths.js");
|
|
3
|
-
const require_packages_utils_path = require("../../utils/path.js");
|
|
4
3
|
const require_packages_utils_loadFile = require("../../utils/loadFile.js");
|
|
5
4
|
const require_packages_utils_runFileFn = require("../../utils/runFileFn.js");
|
|
6
5
|
require("../../utils/index.js");
|
|
@@ -13,7 +12,7 @@ app/controller
|
|
|
13
12
|
|
|
14
13
|
|-- cuStom-moduLe
|
|
15
14
|
|
|
16
|
-
|-- custom-midd Leware.js
|
|
15
|
+
|-- custom-midd Leware.(js|ts)
|
|
17
16
|
|
|
18
17
|
=> app.controller.customModule. customMiddleware
|
|
19
18
|
*
|
|
@@ -26,7 +25,7 @@ var controller_default = (app) => {
|
|
|
26
25
|
app.controller = require_packages_core_paths.getAppPaths(app).reduce((preData, currentPath) => ({
|
|
27
26
|
...preData,
|
|
28
27
|
...require_packages_utils_loadFile.loadFileFn(currentPath, "controller", { loadFileCallback: (file) => {
|
|
29
|
-
return new (require_packages_utils_runFileFn.runFileFn(
|
|
28
|
+
return new (require_packages_utils_runFileFn.runFileFn(file)(app))();
|
|
30
29
|
} })
|
|
31
30
|
}), {});
|
|
32
31
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
require("../../../_virtual/_rolldown/runtime.js");
|
|
2
2
|
const require_packages_core_paths = require("../paths.js");
|
|
3
|
-
const require_packages_utils_path = require("../../utils/path.js");
|
|
4
3
|
const require_packages_utils_loadFile = require("../../utils/loadFile.js");
|
|
5
4
|
const require_packages_utils_runFileFn = require("../../utils/runFileFn.js");
|
|
6
5
|
require("../../utils/index.js");
|
|
@@ -19,7 +18,7 @@ var extend_default = (app) => {
|
|
|
19
18
|
console.log("\x1B[31m%s\x1B[0m", `[extend loader error] name:${fileName} is already in app`);
|
|
20
19
|
return;
|
|
21
20
|
}
|
|
22
|
-
const exs = require_packages_utils_runFileFn.runFileFn(
|
|
21
|
+
const exs = require_packages_utils_runFileFn.runFileFn(filePath)(app);
|
|
23
22
|
if (exs instanceof Promise) (async () => {
|
|
24
23
|
app.extends[fileName] = await exs;
|
|
25
24
|
})();
|
|
@@ -14,12 +14,11 @@ require("../../utils/index.js");
|
|
|
14
14
|
*/
|
|
15
15
|
var middleware_default = (app) => {
|
|
16
16
|
/**
|
|
17
|
-
* xx/app/middleware/a/a.js -> app.middleware.a.a
|
|
18
|
-
* require('app/middleware/a/a.js')(app)
|
|
17
|
+
* xx/app/middleware/a/a.(js|ts) -> app.middleware.a.a
|
|
19
18
|
*/
|
|
20
19
|
app.middlewares = require_packages_core_paths.getAppPaths(app).reduce((preData, currentPath) => {
|
|
21
20
|
const middlewares = require_packages_utils_loadFile.loadFileFn(currentPath, "middleware", { loadFileCallback: (path) => {
|
|
22
|
-
return require_packages_utils_runFileFn.runFileFn(
|
|
21
|
+
return require_packages_utils_runFileFn.runFileFn(path)(app);
|
|
23
22
|
} });
|
|
24
23
|
return {
|
|
25
24
|
...preData,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
|
|
2
2
|
const require_packages_utils_loadFile = require("../../utils/loadFile.js");
|
|
3
|
+
const require_packages_utils_runFileFn = require("../../utils/runFileFn.js");
|
|
3
4
|
let path = require("path");
|
|
4
5
|
let lodash = require("lodash");
|
|
5
6
|
lodash = require_runtime.__toESM(lodash, 1);
|
|
@@ -20,7 +21,7 @@ var modelLoader = (app) => {
|
|
|
20
21
|
* 3.根据不同的 类型 获取key
|
|
21
22
|
*/
|
|
22
23
|
loadFileCallback: (file) => {
|
|
23
|
-
if (file
|
|
24
|
+
if (!isModelIndexFile(file)) {
|
|
24
25
|
const filePathChunk = file.split(path.sep);
|
|
25
26
|
if (filePathChunk[filePathChunk.length - 2] === "project") {
|
|
26
27
|
const modelKey = filePathChunk[filePathChunk.length - 3];
|
|
@@ -76,7 +77,7 @@ var setProject = (config, modelKey, key, file) => {
|
|
|
76
77
|
const projectItem = {
|
|
77
78
|
key,
|
|
78
79
|
modelKey,
|
|
79
|
-
...
|
|
80
|
+
...require_packages_utils_runFileFn.runFileFn(file)
|
|
80
81
|
};
|
|
81
82
|
currentModel.project[key] = projectItem;
|
|
82
83
|
};
|
|
@@ -98,10 +99,13 @@ var setModel = (config, key, filePath) => {
|
|
|
98
99
|
modelItem = newModel;
|
|
99
100
|
}
|
|
100
101
|
if (filePath) modelItem.model = {
|
|
101
|
-
...
|
|
102
|
+
...require_packages_utils_runFileFn.runFileFn(filePath),
|
|
102
103
|
key
|
|
103
104
|
};
|
|
104
105
|
return modelItem;
|
|
105
106
|
};
|
|
107
|
+
function isModelIndexFile(file) {
|
|
108
|
+
return file.indexOf(`model${path.sep}index.js`) !== -1 || file.indexOf(`model${path.sep}index.ts`) !== -1;
|
|
109
|
+
}
|
|
106
110
|
//#endregion
|
|
107
111
|
module.exports = modelLoader;
|
|
@@ -2,6 +2,8 @@ require("../../../_virtual/_rolldown/runtime.js");
|
|
|
2
2
|
const require_packages_core_paths = require("../paths.js");
|
|
3
3
|
const require_packages_utils_path = require("../../utils/path.js");
|
|
4
4
|
const require_packages_utils_loadFile = require("../../utils/loadFile.js");
|
|
5
|
+
const require_packages_utils_runFileFn = require("../../utils/runFileFn.js");
|
|
6
|
+
require("../../utils/index.js");
|
|
5
7
|
//#region packages/core/loader/router-schema.ts
|
|
6
8
|
/**
|
|
7
9
|
*
|
|
@@ -9,7 +11,7 @@ const require_packages_utils_loadFile = require("../../utils/loadFile.js");
|
|
|
9
11
|
*
|
|
10
12
|
* @param app
|
|
11
13
|
*
|
|
12
|
-
* xx/app/router-schema/**.js
|
|
14
|
+
* xx/app/router-schema/**.(js|ts)
|
|
13
15
|
*
|
|
14
16
|
* 输出:
|
|
15
17
|
* app.routerSchema = {
|
|
@@ -24,7 +26,7 @@ var router_schema_default = (app) => {
|
|
|
24
26
|
require_packages_utils_loadFile.loadFileFn(currentPath, "router-schema", { preProcessingFileCallback(file) {
|
|
25
27
|
routerSchema = {
|
|
26
28
|
...routerSchema,
|
|
27
|
-
...
|
|
29
|
+
...require_packages_utils_runFileFn.runFileFn(require_packages_utils_path.resolve(file))
|
|
28
30
|
};
|
|
29
31
|
} });
|
|
30
32
|
});
|
|
@@ -4,6 +4,7 @@ const require_packages_utils_path = require("../../utils/path.js");
|
|
|
4
4
|
const require_packages_utils_loadFile = require("../../utils/loadFile.js");
|
|
5
5
|
const require_packages_utils_runFileFn = require("../../utils/runFileFn.js");
|
|
6
6
|
require("../../utils/index.js");
|
|
7
|
+
let fs = require("fs");
|
|
7
8
|
let koa_router = require("koa-router");
|
|
8
9
|
koa_router = require_runtime.__toESM(koa_router, 1);
|
|
9
10
|
//#region packages/core/loader/router.ts
|
|
@@ -14,12 +15,15 @@ koa_router = require_runtime.__toESM(koa_router, 1);
|
|
|
14
15
|
*/
|
|
15
16
|
var router_default = (app) => {
|
|
16
17
|
let routerGuard;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const businessPath = require_packages_core_paths.getAppPath(app, "business");
|
|
19
|
+
if (businessPath) for (const fileName of ["router-guard.ts", "router-guard.js"]) {
|
|
20
|
+
const filePath = require_packages_utils_path.resolve(businessPath, fileName);
|
|
21
|
+
if ((0, fs.existsSync)(filePath)) {
|
|
22
|
+
routerGuard = require_packages_utils_runFileFn.runFileFn(filePath)(app);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
22
25
|
}
|
|
26
|
+
if (!routerGuard) console.info("-- [router-guard] -- not router-guard.(ts|js) file");
|
|
23
27
|
const routers = [];
|
|
24
28
|
require_packages_core_paths.getAppPaths(app).forEach((currentPath) => {
|
|
25
29
|
require_packages_utils_loadFile.loadFileFn(currentPath, "router", { preProcessingFileCallback: (filePath) => {
|
|
@@ -31,7 +35,7 @@ var router_default = (app) => {
|
|
|
31
35
|
* router.get('/xxx/xxxx', app.controller)
|
|
32
36
|
* }
|
|
33
37
|
*/
|
|
34
|
-
require_packages_utils_runFileFn.runFileFn(
|
|
38
|
+
require_packages_utils_runFileFn.runFileFn(require_packages_utils_path.resolve(filePath))(app, router);
|
|
35
39
|
} });
|
|
36
40
|
});
|
|
37
41
|
const BaseRouters = new koa_router.default();
|
|
@@ -12,7 +12,7 @@ app/service
|
|
|
12
12
|
|
|
13
13
|
|-- cuStom-moduLe
|
|
14
14
|
|
|
15
|
-
|-- custom-midd Leware.js
|
|
15
|
+
|-- custom-midd Leware.(js|ts)
|
|
16
16
|
|
|
17
17
|
=> app.service.customModule. customMiddleware
|
|
18
18
|
*
|
|
@@ -22,7 +22,7 @@ var service_default = (app) => {
|
|
|
22
22
|
app.service = require_packages_core_paths.getAppPaths(app).reduce((preData, currentPath) => ({
|
|
23
23
|
...preData,
|
|
24
24
|
...require_packages_utils_loadFile.loadFileFn(currentPath, "service", { loadFileCallback: (file) => {
|
|
25
|
-
return new (require_packages_utils_runFileFn.runFileFn(
|
|
25
|
+
return new (require_packages_utils_runFileFn.runFileFn(file)(app))();
|
|
26
26
|
} })
|
|
27
27
|
}), {});
|
|
28
28
|
};
|
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
let path = require("path");
|
|
4
|
+
let fs = require("fs");
|
|
3
5
|
//#region packages/utils/runFileFn.ts
|
|
4
|
-
var
|
|
6
|
+
var registeredTypeScriptLoader = false;
|
|
7
|
+
function runFileFn(fileOrModule) {
|
|
8
|
+
return getDefaultExport(typeof fileOrModule === "string" ? requireFile(fileOrModule) : fileOrModule);
|
|
9
|
+
}
|
|
10
|
+
function getDefaultExport(fileModule) {
|
|
11
|
+
if (fileModule && typeof fileModule === "object" && "default" in fileModule && fileModule.default !== void 0) return fileModule.default;
|
|
12
|
+
return fileModule;
|
|
13
|
+
}
|
|
14
|
+
function requireFile(file) {
|
|
15
|
+
try {
|
|
16
|
+
return require(file);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if ((0, path.extname)(file) !== ".ts" || !shouldRetryWithTypeScript(error)) throw error;
|
|
19
|
+
registerTypeScriptLoader();
|
|
20
|
+
delete require.cache[require.resolve(file)];
|
|
21
|
+
return require(file);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function shouldRetryWithTypeScript(error) {
|
|
25
|
+
const err = error;
|
|
26
|
+
const message = err?.message ?? "";
|
|
27
|
+
return err?.code === "ERR_UNKNOWN_FILE_EXTENSION" || err?.code === "ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX" || err?.name === "SyntaxError" || message.indexOf("Cannot use import statement outside a module") !== -1 || message.indexOf("Unexpected token 'export'") !== -1;
|
|
28
|
+
}
|
|
29
|
+
function registerTypeScriptLoader() {
|
|
30
|
+
if (registeredTypeScriptLoader) return;
|
|
31
|
+
const typescript = loadTypeScriptCompiler();
|
|
32
|
+
require.extensions[".ts"] = (module, filename) => {
|
|
33
|
+
const { outputText } = typescript.transpileModule((0, fs.readFileSync)(filename, "utf8"), { compilerOptions: {
|
|
34
|
+
module: typescript.ModuleKind.CommonJS,
|
|
35
|
+
target: typescript.ScriptTarget.ES2020,
|
|
36
|
+
esModuleInterop: true,
|
|
37
|
+
allowSyntheticDefaultImports: true
|
|
38
|
+
} });
|
|
39
|
+
module._compile(outputText, filename);
|
|
40
|
+
};
|
|
41
|
+
registeredTypeScriptLoader = true;
|
|
42
|
+
}
|
|
43
|
+
function loadTypeScriptCompiler() {
|
|
44
|
+
try {
|
|
45
|
+
return require("typescript");
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error(`Unable to load TypeScript file. Please install "typescript" or run with a TypeScript runtime. ${String(error)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
5
50
|
//#endregion
|
|
6
51
|
exports.runFileFn = runFileFn;
|
package/esm/bundler/utils.js
CHANGED
|
@@ -3,16 +3,22 @@ import "../packages/utils/index.js";
|
|
|
3
3
|
import { colorize, logJoinColorized, logRed, logWhite, logYellow } from "../packages/common/log/index.js";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import * as glob from "glob";
|
|
6
|
-
import tailwindcss from "@tailwindcss/vite";
|
|
7
6
|
import { copyFileSync, existsSync, readFileSync, readdirSync, rmdirSync, unlinkSync, writeFileSync } from "fs";
|
|
7
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
8
|
+
import { createRequire } from "module";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
8
10
|
import { build } from "vite";
|
|
9
11
|
//#region bundler/utils.ts
|
|
12
|
+
var currentFile = typeof __filename === "string" ? __filename : fileURLToPath(import.meta.url);
|
|
13
|
+
var currentDir = path.dirname(currentFile);
|
|
10
14
|
var base = process.cwd();
|
|
11
|
-
var
|
|
12
|
-
var
|
|
15
|
+
var requireFromFrame = createRequire(currentFile);
|
|
16
|
+
var framePath = path.resolve(currentDir, "../../");
|
|
17
|
+
var frameNodePath = path.resolve(currentDir, "../");
|
|
13
18
|
var frameFEPath = path.resolve(framePath, "./fe/frontend");
|
|
14
19
|
var runPath = path.resolve(base, ".");
|
|
15
20
|
var runFEPath = path.resolve(runPath, "./frontend");
|
|
21
|
+
var resolvePackageDir = (packageName) => path.dirname(requireFromFrame.resolve(`${packageName}/package.json`));
|
|
16
22
|
/**
|
|
17
23
|
*
|
|
18
24
|
* 寻找 frontend\/**\/*.entry.[j|t]s(x)?
|
|
@@ -140,7 +146,7 @@ function resolveAliasWithFallback(aliasList) {
|
|
|
140
146
|
];
|
|
141
147
|
return aliasList.reduce((o, [aliasName, aliasPath]) => {
|
|
142
148
|
const businessFilePath = aliasExtensions.map((ext) => path.resolve(runFEPath, aliasPath + ext)).find((filePath) => existsSync(filePath));
|
|
143
|
-
let filePath = path.resolve(
|
|
149
|
+
let filePath = path.resolve(currentDir, "./defaultAlias");
|
|
144
150
|
if (businessFilePath) filePath = businessFilePath;
|
|
145
151
|
o[aliasName] = filePath;
|
|
146
152
|
return o;
|
|
@@ -163,7 +169,9 @@ var VBuildFE = async (input, OperatingEnv) => {
|
|
|
163
169
|
rollupOptions: { input }
|
|
164
170
|
},
|
|
165
171
|
resolve: { alias: {
|
|
166
|
-
"@tc/ui-react": path.resolve(
|
|
172
|
+
"@tc/ui-react": path.resolve(currentDir, "../../fe/packages/ui/react/"),
|
|
173
|
+
react: resolvePackageDir("react"),
|
|
174
|
+
"react-dom": resolvePackageDir("react-dom"),
|
|
167
175
|
...resolveAliasWithFallback([["$business/SchemaForm/data", "./extended/SchemaForm/data"]])
|
|
168
176
|
} }
|
|
169
177
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __require } from "../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import env_default from "./env.js";
|
|
3
2
|
import { resolve } from "../utils/path.js";
|
|
4
3
|
import { runFileFn } from "../utils/runFileFn.js";
|
|
@@ -88,7 +87,7 @@ var mountMiddleware = (app) => {
|
|
|
88
87
|
for (const fileSymbol of ["ts", "js"]) {
|
|
89
88
|
const fileName = `middleware.${fileSymbol}`;
|
|
90
89
|
try {
|
|
91
|
-
runFileFn(
|
|
90
|
+
runFileFn(resolve(pathInfo.path, fileName))?.(app);
|
|
92
91
|
console.log(`-- [init] loader ${pathInfo.type} appMiddlerare ${fileName} done -- (${pathInfo.path})`);
|
|
93
92
|
loaded = true;
|
|
94
93
|
break;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import { resolve } from "../../utils/path.js";
|
|
3
2
|
import { getAllFilesInFolder } from "../../utils/getAllFilesInFolder.js";
|
|
3
|
+
import { runFileFn } from "../../utils/runFileFn.js";
|
|
4
|
+
import "../../utils/index.js";
|
|
4
5
|
//#region packages/core/loader/config.ts
|
|
5
6
|
/**
|
|
6
7
|
* config loader 只处理一级
|
|
7
8
|
*
|
|
8
9
|
* @param app 加载 xx/config/ 下的文件
|
|
9
|
-
* config/config.default.js
|
|
10
|
+
* config/config.default.(js|ts)
|
|
10
11
|
*/
|
|
11
12
|
var config_default = (app) => {
|
|
12
13
|
const files = getAllFilesInFolder(app.baseDir, "config");
|
|
@@ -26,7 +27,7 @@ var config_default = (app) => {
|
|
|
26
27
|
configMap[k] = true;
|
|
27
28
|
const configFile = configPath.reduce((preData, currentPath) => ({
|
|
28
29
|
...preData,
|
|
29
|
-
...
|
|
30
|
+
...runFileFn(resolve(currentPath))
|
|
30
31
|
}), {});
|
|
31
32
|
envConfig = [envConfig, configFile][k === "default" ? "reduceRight" : "reduce"]((o, c) => ({
|
|
32
33
|
...o,
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import { getAppPaths } from "../paths.js";
|
|
3
|
-
import { resolve } from "../../utils/path.js";
|
|
4
2
|
import { loadFileFn } from "../../utils/loadFile.js";
|
|
5
3
|
import { runFileFn } from "../../utils/runFileFn.js";
|
|
6
4
|
import "../../utils/index.js";
|
|
@@ -13,7 +11,7 @@ app/controller
|
|
|
13
11
|
|
|
14
12
|
|-- cuStom-moduLe
|
|
15
13
|
|
|
16
|
-
|-- custom-midd Leware.js
|
|
14
|
+
|-- custom-midd Leware.(js|ts)
|
|
17
15
|
|
|
18
16
|
=> app.controller.customModule. customMiddleware
|
|
19
17
|
*
|
|
@@ -26,7 +24,7 @@ var controller_default = (app) => {
|
|
|
26
24
|
app.controller = getAppPaths(app).reduce((preData, currentPath) => ({
|
|
27
25
|
...preData,
|
|
28
26
|
...loadFileFn(currentPath, "controller", { loadFileCallback: (file) => {
|
|
29
|
-
return new (runFileFn(
|
|
27
|
+
return new (runFileFn(file)(app))();
|
|
30
28
|
} })
|
|
31
29
|
}), {});
|
|
32
30
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import { getAppPaths } from "../paths.js";
|
|
3
|
-
import { resolve } from "../../utils/path.js";
|
|
4
2
|
import { loadFileFn } from "../../utils/loadFile.js";
|
|
5
3
|
import { runFileFn } from "../../utils/runFileFn.js";
|
|
6
4
|
import "../../utils/index.js";
|
|
@@ -19,7 +17,7 @@ var extend_default = (app) => {
|
|
|
19
17
|
console.log("\x1B[31m%s\x1B[0m", `[extend loader error] name:${fileName} is already in app`);
|
|
20
18
|
return;
|
|
21
19
|
}
|
|
22
|
-
const exs = runFileFn(
|
|
20
|
+
const exs = runFileFn(filePath)(app);
|
|
23
21
|
if (exs instanceof Promise) (async () => {
|
|
24
22
|
app.extends[fileName] = await exs;
|
|
25
23
|
})();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import { getAppPaths } from "../paths.js";
|
|
3
2
|
import { loadFileFn } from "../../utils/loadFile.js";
|
|
4
3
|
import { runFileFn } from "../../utils/runFileFn.js";
|
|
@@ -14,12 +13,11 @@ import "../../utils/index.js";
|
|
|
14
13
|
*/
|
|
15
14
|
var middleware_default = (app) => {
|
|
16
15
|
/**
|
|
17
|
-
* xx/app/middleware/a/a.js -> app.middleware.a.a
|
|
18
|
-
* require('app/middleware/a/a.js')(app)
|
|
16
|
+
* xx/app/middleware/a/a.(js|ts) -> app.middleware.a.a
|
|
19
17
|
*/
|
|
20
18
|
app.middlewares = getAppPaths(app).reduce((preData, currentPath) => {
|
|
21
19
|
const middlewares = loadFileFn(currentPath, "middleware", { loadFileCallback: (path) => {
|
|
22
|
-
return runFileFn(
|
|
20
|
+
return runFileFn(path)(app);
|
|
23
21
|
} });
|
|
24
22
|
return {
|
|
25
23
|
...preData,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import { loadFileFn } from "../../utils/loadFile.js";
|
|
2
|
+
import { runFileFn } from "../../utils/runFileFn.js";
|
|
3
3
|
import { sep } from "path";
|
|
4
4
|
import _ from "lodash";
|
|
5
5
|
//#region packages/core/loader/model.ts
|
|
@@ -19,7 +19,7 @@ var modelLoader = (app) => {
|
|
|
19
19
|
* 3.根据不同的 类型 获取key
|
|
20
20
|
*/
|
|
21
21
|
loadFileCallback: (file) => {
|
|
22
|
-
if (file
|
|
22
|
+
if (!isModelIndexFile(file)) {
|
|
23
23
|
const filePathChunk = file.split(sep);
|
|
24
24
|
if (filePathChunk[filePathChunk.length - 2] === "project") {
|
|
25
25
|
const modelKey = filePathChunk[filePathChunk.length - 3];
|
|
@@ -75,7 +75,7 @@ var setProject = (config, modelKey, key, file) => {
|
|
|
75
75
|
const projectItem = {
|
|
76
76
|
key,
|
|
77
77
|
modelKey,
|
|
78
|
-
...
|
|
78
|
+
...runFileFn(file)
|
|
79
79
|
};
|
|
80
80
|
currentModel.project[key] = projectItem;
|
|
81
81
|
};
|
|
@@ -97,10 +97,13 @@ var setModel = (config, key, filePath) => {
|
|
|
97
97
|
modelItem = newModel;
|
|
98
98
|
}
|
|
99
99
|
if (filePath) modelItem.model = {
|
|
100
|
-
...
|
|
100
|
+
...runFileFn(filePath),
|
|
101
101
|
key
|
|
102
102
|
};
|
|
103
103
|
return modelItem;
|
|
104
104
|
};
|
|
105
|
+
function isModelIndexFile(file) {
|
|
106
|
+
return file.indexOf(`model${sep}index.js`) !== -1 || file.indexOf(`model${sep}index.ts`) !== -1;
|
|
107
|
+
}
|
|
105
108
|
//#endregion
|
|
106
109
|
export { modelLoader as default };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import { getAppPaths } from "../paths.js";
|
|
3
2
|
import { resolve } from "../../utils/path.js";
|
|
4
3
|
import { loadFileFn } from "../../utils/loadFile.js";
|
|
4
|
+
import { runFileFn } from "../../utils/runFileFn.js";
|
|
5
|
+
import "../../utils/index.js";
|
|
5
6
|
//#region packages/core/loader/router-schema.ts
|
|
6
7
|
/**
|
|
7
8
|
*
|
|
@@ -9,7 +10,7 @@ import { loadFileFn } from "../../utils/loadFile.js";
|
|
|
9
10
|
*
|
|
10
11
|
* @param app
|
|
11
12
|
*
|
|
12
|
-
* xx/app/router-schema/**.js
|
|
13
|
+
* xx/app/router-schema/**.(js|ts)
|
|
13
14
|
*
|
|
14
15
|
* 输出:
|
|
15
16
|
* app.routerSchema = {
|
|
@@ -24,7 +25,7 @@ var router_schema_default = (app) => {
|
|
|
24
25
|
loadFileFn(currentPath, "router-schema", { preProcessingFileCallback(file) {
|
|
25
26
|
routerSchema = {
|
|
26
27
|
...routerSchema,
|
|
27
|
-
...
|
|
28
|
+
...runFileFn(resolve(file))
|
|
28
29
|
};
|
|
29
30
|
} });
|
|
30
31
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import { getAppPath, getAppPaths } from "../paths.js";
|
|
3
2
|
import { resolve } from "../../utils/path.js";
|
|
4
3
|
import { loadFileFn } from "../../utils/loadFile.js";
|
|
5
4
|
import { runFileFn } from "../../utils/runFileFn.js";
|
|
6
5
|
import "../../utils/index.js";
|
|
6
|
+
import { existsSync } from "fs";
|
|
7
7
|
import KoaRouter from "koa-router";
|
|
8
8
|
//#region packages/core/loader/router.ts
|
|
9
9
|
/**
|
|
@@ -13,12 +13,15 @@ import KoaRouter from "koa-router";
|
|
|
13
13
|
*/
|
|
14
14
|
var router_default = (app) => {
|
|
15
15
|
let routerGuard;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const businessPath = getAppPath(app, "business");
|
|
17
|
+
if (businessPath) for (const fileName of ["router-guard.ts", "router-guard.js"]) {
|
|
18
|
+
const filePath = resolve(businessPath, fileName);
|
|
19
|
+
if (existsSync(filePath)) {
|
|
20
|
+
routerGuard = runFileFn(filePath)(app);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
21
23
|
}
|
|
24
|
+
if (!routerGuard) console.info("-- [router-guard] -- not router-guard.(ts|js) file");
|
|
22
25
|
const routers = [];
|
|
23
26
|
getAppPaths(app).forEach((currentPath) => {
|
|
24
27
|
loadFileFn(currentPath, "router", { preProcessingFileCallback: (filePath) => {
|
|
@@ -30,7 +33,7 @@ var router_default = (app) => {
|
|
|
30
33
|
* router.get('/xxx/xxxx', app.controller)
|
|
31
34
|
* }
|
|
32
35
|
*/
|
|
33
|
-
runFileFn(
|
|
36
|
+
runFileFn(resolve(filePath))(app, router);
|
|
34
37
|
} });
|
|
35
38
|
});
|
|
36
39
|
const BaseRouters = new KoaRouter();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __require } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
1
|
import { getAppPaths } from "../paths.js";
|
|
3
2
|
import { loadFileFn } from "../../utils/loadFile.js";
|
|
4
3
|
import { runFileFn } from "../../utils/runFileFn.js";
|
|
@@ -12,7 +11,7 @@ app/service
|
|
|
12
11
|
|
|
13
12
|
|-- cuStom-moduLe
|
|
14
13
|
|
|
15
|
-
|-- custom-midd Leware.js
|
|
14
|
+
|-- custom-midd Leware.(js|ts)
|
|
16
15
|
|
|
17
16
|
=> app.service.customModule. customMiddleware
|
|
18
17
|
*
|
|
@@ -22,7 +21,7 @@ var service_default = (app) => {
|
|
|
22
21
|
app.service = getAppPaths(app).reduce((preData, currentPath) => ({
|
|
23
22
|
...preData,
|
|
24
23
|
...loadFileFn(currentPath, "service", { loadFileCallback: (file) => {
|
|
25
|
-
return new (runFileFn(
|
|
24
|
+
return new (runFileFn(file)(app))();
|
|
26
25
|
} })
|
|
27
26
|
}), {});
|
|
28
27
|
};
|
|
@@ -1,4 +1,50 @@
|
|
|
1
|
+
import { __require } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { extname } from "path";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
1
4
|
//#region packages/utils/runFileFn.ts
|
|
2
|
-
var
|
|
5
|
+
var registeredTypeScriptLoader = false;
|
|
6
|
+
function runFileFn(fileOrModule) {
|
|
7
|
+
return getDefaultExport(typeof fileOrModule === "string" ? requireFile(fileOrModule) : fileOrModule);
|
|
8
|
+
}
|
|
9
|
+
function getDefaultExport(fileModule) {
|
|
10
|
+
if (fileModule && typeof fileModule === "object" && "default" in fileModule && fileModule.default !== void 0) return fileModule.default;
|
|
11
|
+
return fileModule;
|
|
12
|
+
}
|
|
13
|
+
function requireFile(file) {
|
|
14
|
+
try {
|
|
15
|
+
return __require(file);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (extname(file) !== ".ts" || !shouldRetryWithTypeScript(error)) throw error;
|
|
18
|
+
registerTypeScriptLoader();
|
|
19
|
+
delete __require.cache[__require.resolve(file)];
|
|
20
|
+
return __require(file);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function shouldRetryWithTypeScript(error) {
|
|
24
|
+
const err = error;
|
|
25
|
+
const message = err?.message ?? "";
|
|
26
|
+
return err?.code === "ERR_UNKNOWN_FILE_EXTENSION" || err?.code === "ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX" || err?.name === "SyntaxError" || message.indexOf("Cannot use import statement outside a module") !== -1 || message.indexOf("Unexpected token 'export'") !== -1;
|
|
27
|
+
}
|
|
28
|
+
function registerTypeScriptLoader() {
|
|
29
|
+
if (registeredTypeScriptLoader) return;
|
|
30
|
+
const typescript = loadTypeScriptCompiler();
|
|
31
|
+
__require.extensions[".ts"] = (module, filename) => {
|
|
32
|
+
const { outputText } = typescript.transpileModule(readFileSync(filename, "utf8"), { compilerOptions: {
|
|
33
|
+
module: typescript.ModuleKind.CommonJS,
|
|
34
|
+
target: typescript.ScriptTarget.ES2020,
|
|
35
|
+
esModuleInterop: true,
|
|
36
|
+
allowSyntheticDefaultImports: true
|
|
37
|
+
} });
|
|
38
|
+
module._compile(outputText, filename);
|
|
39
|
+
};
|
|
40
|
+
registeredTypeScriptLoader = true;
|
|
41
|
+
}
|
|
42
|
+
function loadTypeScriptCompiler() {
|
|
43
|
+
try {
|
|
44
|
+
return __require("typescript");
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new Error(`Unable to load TypeScript file. Please install "typescript" or run with a TypeScript runtime. ${String(error)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
3
49
|
//#endregion
|
|
4
50
|
export { runFileFn };
|