@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.2
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/CHANGELOG.md +375 -0
- package/dist/js/modern/analyze/generateCode.js +30 -38
- package/dist/js/modern/analyze/getBundleEntry.js +5 -13
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/modern/analyze/getFileSystemEntry.js +5 -18
- package/dist/js/modern/analyze/getHtmlTemplate.js +3 -10
- package/dist/js/modern/analyze/getServerRoutes.js +25 -38
- package/dist/js/modern/analyze/index.js +90 -48
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/modern/analyze/nestedRoutes.js +8 -33
- package/dist/js/modern/analyze/templates.js +22 -37
- package/dist/js/modern/analyze/utils.js +0 -7
- package/dist/js/modern/builder/builderPlugins/compatModern.js +41 -58
- package/dist/js/modern/builder/index.js +56 -37
- package/dist/js/modern/builder/share.js +1 -5
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
- package/dist/js/modern/commands/build.js +12 -46
- package/dist/js/modern/commands/dev.js +20 -23
- package/dist/js/modern/commands/inspect.js +4 -19
- package/dist/js/modern/commands/start.js +1 -2
- package/dist/js/modern/config/default.js +207 -0
- package/dist/js/modern/config/index.js +2 -0
- package/dist/js/modern/config/initial/createHtmlConfig.js +32 -0
- package/dist/js/modern/{builder → config/initial}/createOutputConfig.js +19 -18
- package/dist/js/modern/config/initial/createSourceConfig.js +32 -0
- package/dist/js/modern/config/initial/createToolsConfig.js +41 -0
- package/dist/js/modern/config/initial/index.js +11 -0
- package/dist/js/modern/config/initial/inits.js +117 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +40 -0
- package/dist/js/modern/defineConfig.js +12 -0
- package/dist/js/modern/hooks.js +23 -19
- package/dist/js/modern/index.js +12 -19
- package/dist/js/modern/initialize/index.js +72 -0
- package/dist/js/modern/schema/Schema.js +39 -0
- package/dist/js/modern/schema/index.js +139 -0
- package/dist/js/modern/schema/legacy.js +284 -0
- package/dist/js/modern/types/config/deploy.js +0 -0
- package/dist/js/modern/types/config/dev.js +0 -0
- package/dist/js/modern/types/config/experiments.js +0 -0
- package/dist/js/modern/types/config/html.js +0 -0
- package/dist/js/modern/types/config/index.js +2 -0
- package/dist/js/modern/types/config/output.js +0 -0
- package/dist/js/modern/types/config/performance.js +0 -0
- package/dist/js/modern/types/config/security.js +0 -0
- package/dist/js/modern/types/config/source.js +0 -0
- package/dist/js/modern/types/config/tools.js +0 -0
- package/dist/js/modern/types/hooks.js +0 -0
- package/dist/js/modern/types/index.js +4 -0
- package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
- package/dist/js/modern/types/legacyConfig/dev.js +0 -0
- package/dist/js/modern/types/legacyConfig/index.js +0 -0
- package/dist/js/modern/types/legacyConfig/output.js +1 -0
- package/dist/js/modern/types/legacyConfig/source.js +0 -0
- package/dist/js/modern/types/legacyConfig/tools.js +0 -0
- package/dist/js/modern/utils/config.js +2 -13
- package/dist/js/modern/utils/createFileWatcher.js +82 -0
- package/dist/js/modern/utils/createServer.js +0 -5
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
- package/dist/js/modern/utils/printInstructions.js +2 -1
- package/dist/js/modern/utils/restart.js +17 -0
- package/dist/js/modern/utils/routes.js +0 -2
- package/dist/js/node/analyze/generateCode.js +30 -61
- package/dist/js/node/analyze/getBundleEntry.js +5 -19
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
- package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
- package/dist/js/node/analyze/getFileSystemEntry.js +5 -26
- package/dist/js/node/analyze/getHtmlTemplate.js +3 -24
- package/dist/js/node/analyze/getServerRoutes.js +24 -46
- package/dist/js/node/analyze/index.js +91 -70
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
- package/dist/js/node/analyze/nestedRoutes.js +8 -41
- package/dist/js/node/analyze/templates.js +22 -47
- package/dist/js/node/analyze/utils.js +0 -20
- package/dist/js/node/builder/builderPlugins/compatModern.js +41 -69
- package/dist/js/node/builder/index.js +57 -51
- package/dist/js/node/builder/share.js +1 -13
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
- package/dist/js/node/commands/build.js +10 -57
- package/dist/js/node/commands/deploy.js +0 -2
- package/dist/js/node/commands/dev.js +19 -34
- package/dist/js/node/commands/index.js +0 -6
- package/dist/js/node/commands/inspect.js +4 -26
- package/dist/js/node/commands/start.js +1 -11
- package/dist/js/node/config/default.js +214 -0
- package/dist/js/node/config/index.js +31 -0
- package/dist/js/node/config/initial/createHtmlConfig.js +38 -0
- package/dist/js/node/{builder → config/initial}/createOutputConfig.js +19 -20
- package/dist/js/node/config/initial/createSourceConfig.js +38 -0
- package/dist/js/node/config/initial/createToolsConfig.js +47 -0
- package/dist/js/node/config/initial/index.js +24 -0
- package/dist/js/node/config/initial/inits.js +127 -0
- package/dist/js/node/config/initial/transformNormalizedConfig.js +46 -0
- package/dist/js/node/defineConfig.js +20 -0
- package/dist/js/node/exports/server.js +0 -1
- package/dist/js/node/hooks.js +23 -30
- package/dist/js/node/index.js +35 -48
- package/dist/js/node/initialize/index.js +79 -0
- package/dist/js/node/locale/index.js +0 -4
- package/dist/js/node/schema/Schema.js +46 -0
- package/dist/js/node/schema/index.js +152 -0
- package/dist/js/node/schema/legacy.js +291 -0
- package/dist/js/node/types/config/deploy.js +0 -0
- package/dist/js/node/types/config/dev.js +0 -0
- package/dist/js/node/types/config/experiments.js +0 -0
- package/dist/js/node/types/config/html.js +0 -0
- package/dist/js/node/types/config/index.js +16 -0
- package/dist/js/node/types/config/output.js +0 -0
- package/dist/js/node/types/config/performance.js +0 -0
- package/dist/js/node/types/config/security.js +0 -0
- package/dist/js/node/types/config/source.js +0 -0
- package/dist/js/node/types/config/tools.js +0 -0
- package/dist/js/node/types/hooks.js +0 -0
- package/dist/js/node/types/index.js +38 -0
- package/dist/js/node/types/legacyConfig/deploy.js +0 -0
- package/dist/js/node/types/legacyConfig/dev.js +0 -0
- package/dist/js/node/types/legacyConfig/index.js +0 -0
- package/dist/js/node/types/legacyConfig/output.js +5 -0
- package/dist/js/node/types/legacyConfig/source.js +0 -0
- package/dist/js/node/types/legacyConfig/tools.js +0 -0
- package/dist/js/node/utils/commands.js +0 -2
- package/dist/js/node/utils/config.js +2 -26
- package/dist/js/node/utils/createFileWatcher.js +90 -0
- package/dist/js/node/utils/createServer.js +0 -15
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
- package/dist/js/node/utils/language.js +0 -2
- package/dist/js/node/utils/printInstructions.js +2 -5
- package/dist/js/node/utils/restart.js +23 -0
- package/dist/js/node/utils/routes.js +0 -5
- package/dist/js/treeshaking/analyze/generateCode.js +58 -101
- package/dist/js/treeshaking/analyze/getBundleEntry.js +12 -20
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +5 -18
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +3 -27
- package/dist/js/treeshaking/analyze/getServerRoutes.js +29 -41
- package/dist/js/treeshaking/analyze/index.js +195 -91
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
- package/dist/js/treeshaking/analyze/templates.js +31 -50
- package/dist/js/treeshaking/analyze/utils.js +7 -14
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +50 -68
- package/dist/js/treeshaking/builder/index.js +69 -65
- package/dist/js/treeshaking/builder/share.js +1 -5
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
- package/dist/js/treeshaking/commands/build.js +41 -116
- package/dist/js/treeshaking/commands/deploy.js +0 -3
- package/dist/js/treeshaking/commands/dev.js +38 -46
- package/dist/js/treeshaking/commands/inspect.js +9 -27
- package/dist/js/treeshaking/commands/start.js +1 -9
- package/dist/js/treeshaking/config/default.js +200 -0
- package/dist/js/treeshaking/config/index.js +2 -0
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +31 -0
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +67 -0
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -0
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +38 -0
- package/dist/js/treeshaking/config/initial/index.js +11 -0
- package/dist/js/treeshaking/config/initial/inits.js +114 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +38 -0
- package/dist/js/treeshaking/defineConfig.js +14 -0
- package/dist/js/treeshaking/hooks.js +23 -19
- package/dist/js/treeshaking/index.js +8 -43
- package/dist/js/treeshaking/initialize/index.js +121 -0
- package/dist/js/treeshaking/schema/Schema.js +75 -0
- package/dist/js/treeshaking/schema/index.js +138 -0
- package/dist/js/treeshaking/schema/legacy.js +273 -0
- package/dist/js/treeshaking/types/config/deploy.js +0 -0
- package/dist/js/treeshaking/types/config/dev.js +0 -0
- package/dist/js/treeshaking/types/config/experiments.js +0 -0
- package/dist/js/treeshaking/types/config/html.js +0 -0
- package/dist/js/treeshaking/types/config/index.js +2 -0
- package/dist/js/treeshaking/types/config/output.js +0 -0
- package/dist/js/treeshaking/types/config/performance.js +0 -0
- package/dist/js/treeshaking/types/config/security.js +0 -0
- package/dist/js/treeshaking/types/config/source.js +0 -0
- package/dist/js/treeshaking/types/config/tools.js +0 -0
- package/dist/js/treeshaking/types/hooks.js +0 -0
- package/dist/js/treeshaking/types/index.js +4 -0
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/source.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -0
- package/dist/js/treeshaking/utils/config.js +2 -18
- package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
- package/dist/js/treeshaking/utils/createServer.js +0 -10
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
- package/dist/js/treeshaking/utils/printInstructions.js +0 -5
- package/dist/js/treeshaking/utils/restart.js +45 -0
- package/dist/js/treeshaking/utils/routes.js +0 -4
- package/dist/types/analyze/generateCode.d.ts +3 -2
- package/dist/types/analyze/getBundleEntry.d.ts +2 -2
- package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
- package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
- package/dist/types/analyze/getServerRoutes.d.ts +3 -2
- package/dist/types/analyze/index.d.ts +3 -42
- package/dist/types/analyze/nestedRoutes.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +4 -2
- package/dist/types/analyze/utils.d.ts +1 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -3
- package/dist/types/builder/index.d.ts +7 -8
- package/dist/types/builder/share.d.ts +2 -2
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/inspect.d.ts +6 -1
- package/dist/types/commands/start.d.ts +2 -2
- package/dist/types/config/default.d.ts +3 -0
- package/dist/types/config/index.d.ts +2 -0
- package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
- package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
- package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
- package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
- package/dist/types/config/initial/index.d.ts +4 -0
- package/dist/types/config/initial/inits.d.ts +4 -0
- package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
- package/dist/types/defineConfig.d.ts +7 -0
- package/dist/types/hooks.d.ts +2 -42
- package/dist/types/index.d.ts +5 -7
- package/dist/types/initialize/index.d.ts +3 -0
- package/dist/types/schema/Schema.d.ts +14 -0
- package/dist/types/schema/index.d.ts +4 -0
- package/dist/types/schema/legacy.d.ts +3 -0
- package/dist/types/types/config/deploy.d.ts +9 -0
- package/dist/types/types/config/dev.d.ts +13 -0
- package/dist/types/types/config/experiments.d.ts +4 -0
- package/dist/types/types/config/html.d.ts +4 -0
- package/dist/types/types/config/index.d.ts +62 -0
- package/dist/types/types/config/output.d.ts +23 -0
- package/dist/types/types/config/performance.d.ts +4 -0
- package/dist/types/types/config/security.d.ts +4 -0
- package/dist/types/types/config/source.d.ts +22 -0
- package/dist/types/types/config/tools.d.ts +15 -0
- package/dist/types/types/hooks.d.ts +80 -0
- package/dist/types/types/index.d.ts +23 -0
- package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
- package/dist/types/types/legacyConfig/dev.d.ts +12 -0
- package/dist/types/types/legacyConfig/index.d.ts +33 -0
- package/dist/types/types/legacyConfig/output.d.ts +51 -0
- package/dist/types/types/legacyConfig/source.d.ts +25 -0
- package/dist/types/types/legacyConfig/tools.d.ts +16 -0
- package/dist/types/utils/config.d.ts +2 -3
- package/dist/types/utils/createFileWatcher.d.ts +3 -0
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +3 -0
- package/package.json +26 -25
- package/dist/js/modern/builder/createHtmlConfig.js +0 -58
- package/dist/js/modern/builder/createSourceConfig.js +0 -85
- package/dist/js/modern/builder/createToolsConfig.js +0 -94
- package/dist/js/modern/utils/createCompiler.js +0 -58
- package/dist/js/node/builder/createHtmlConfig.js +0 -76
- package/dist/js/node/builder/createSourceConfig.js +0 -99
- package/dist/js/node/builder/createToolsConfig.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -75
- package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
- package/dist/js/treeshaking/builder/createOutputConfig.js +0 -67
- package/dist/js/treeshaking/builder/createSourceConfig.js +0 -100
- package/dist/js/treeshaking/builder/createToolsConfig.js +0 -90
- package/dist/js/treeshaking/utils/createCompiler.js +0 -117
- package/dist/types/builder/createHtmlConfig.d.ts +0 -6
- package/dist/types/builder/createOutputConfig.d.ts +0 -3
- package/dist/types/builder/createSourceConfig.d.ts +0 -5
- package/dist/types/builder/createToolsConfig.d.ts +0 -13
- package/dist/types/utils/createCompiler.d.ts +0 -12
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import path from 'path';
|
|
8
5
|
import { fs } from '@modern-js/utils';
|
|
9
6
|
import { makeLegalIdentifier } from "../makeLegalIdentifier";
|
|
10
7
|
import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT } from "../constants";
|
|
11
8
|
import { replaceWithAlias } from "../utils";
|
|
12
9
|
import { debug, findLayout, shouldSkip, getRouteWeight } from "./utils";
|
|
13
|
-
|
|
14
10
|
const compName = (srcDirectory, filePath) => {
|
|
15
11
|
const legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
|
16
12
|
return `Comp_${legalCompName}`;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
const layoutNameAbbr = filePath => {
|
|
20
15
|
const prefix = 'L_';
|
|
21
16
|
const dirName = path.dirname(filePath).split('/').pop() || '';
|
|
22
17
|
return `${prefix}${makeLegalIdentifier(dirName)}`;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
const parents = [];
|
|
26
|
-
/* eslint-disable no-param-reassign */
|
|
27
20
|
|
|
21
|
+
/* eslint-disable no-param-reassign */
|
|
28
22
|
const recursiveReadDir = ({
|
|
29
23
|
dir,
|
|
30
24
|
routes,
|
|
@@ -36,7 +30,6 @@ const recursiveReadDir = ({
|
|
|
36
30
|
let resetParent = false;
|
|
37
31
|
let parent = parents[parents.length - 1];
|
|
38
32
|
const layout = findLayout(dir);
|
|
39
|
-
|
|
40
33
|
if (layout) {
|
|
41
34
|
if (_basePath === '/') {
|
|
42
35
|
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
@@ -58,16 +51,13 @@ const recursiveReadDir = ({
|
|
|
58
51
|
routes = route.children;
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
for (const relative of fs.readdirSync(dir)) {
|
|
63
55
|
const filePath = path.join(dir, relative);
|
|
64
|
-
|
|
65
56
|
if (!shouldSkip(filePath)) {
|
|
66
57
|
const filename = path.basename(filePath, path.extname(filePath));
|
|
67
58
|
const alias = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
|
68
59
|
const componentName = compName(srcDirectory, filePath);
|
|
69
60
|
const dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
70
|
-
|
|
71
61
|
if (dynamicRouteMatched) {
|
|
72
62
|
if (hasDynamicRoute) {
|
|
73
63
|
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
@@ -75,7 +65,6 @@ const recursiveReadDir = ({
|
|
|
75
65
|
hasDynamicRoute = true;
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
const route = {
|
|
80
69
|
path: `${_basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
81
70
|
_component: alias,
|
|
@@ -83,7 +72,6 @@ const recursiveReadDir = ({
|
|
|
83
72
|
parent,
|
|
84
73
|
type: 'page'
|
|
85
74
|
};
|
|
86
|
-
|
|
87
75
|
if (fs.statSync(filePath).isDirectory()) {
|
|
88
76
|
recursiveReadDir({
|
|
89
77
|
dir: filePath,
|
|
@@ -94,38 +82,32 @@ const recursiveReadDir = ({
|
|
|
94
82
|
});
|
|
95
83
|
continue;
|
|
96
84
|
}
|
|
97
|
-
|
|
98
85
|
if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
99
86
|
continue;
|
|
100
87
|
}
|
|
101
|
-
|
|
102
88
|
if (filename === FILE_SYSTEM_ROUTES_INDEX) {
|
|
103
89
|
route.path = _basePath === '/' ? _basePath : `${_basePath.substring(0, _basePath.length - 1)}`;
|
|
104
90
|
}
|
|
105
|
-
|
|
106
91
|
if (filename === '404' && _basePath === '/') {
|
|
107
92
|
route.path = '*';
|
|
108
93
|
}
|
|
109
|
-
|
|
110
94
|
routes.push(route);
|
|
111
95
|
}
|
|
112
96
|
}
|
|
113
|
-
|
|
114
97
|
if (resetParent) {
|
|
115
98
|
parents.pop();
|
|
116
99
|
}
|
|
117
100
|
};
|
|
118
101
|
/* eslint-enable no-param-reassign */
|
|
119
102
|
|
|
120
|
-
|
|
121
103
|
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
122
104
|
const flat = routes => routes.reduce((memo, route) => memo.concat(Array.isArray(route.children) ? flat(route.children) : [route]), []);
|
|
123
|
-
|
|
124
105
|
const generate = route => {
|
|
125
106
|
const codes = [];
|
|
126
107
|
let lastComponent = route.component;
|
|
127
|
-
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
108
|
+
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
128
109
|
|
|
110
|
+
// eslint-disable-next-line no-param-reassign, no-cond-assign
|
|
129
111
|
while (route = route.parent) {
|
|
130
112
|
const layoutComponent = route.component;
|
|
131
113
|
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
@@ -134,7 +116,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
134
116
|
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
135
117
|
lastComponent = currentComponent;
|
|
136
118
|
}
|
|
137
|
-
|
|
138
119
|
const file = path.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
139
120
|
fs.outputFileSync(file, `${imports.join('\n')}\n${codes.join('\n')}\nexport default ${lastComponent}`);
|
|
140
121
|
return {
|
|
@@ -142,7 +123,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
142
123
|
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
|
143
124
|
};
|
|
144
125
|
};
|
|
145
|
-
|
|
146
126
|
const normalized = flat(nested).map(route => route.parent ? _objectSpread(_objectSpread(_objectSpread({}, route), generate(route)), {}, {
|
|
147
127
|
parent: undefined
|
|
148
128
|
}) : _objectSpread(_objectSpread({}, route), {}, {
|
|
@@ -150,7 +130,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
150
130
|
}));
|
|
151
131
|
return normalized;
|
|
152
132
|
};
|
|
153
|
-
|
|
154
133
|
export const getClientRoutes = ({
|
|
155
134
|
entrypoint,
|
|
156
135
|
srcDirectory,
|
|
@@ -162,15 +141,12 @@ export const getClientRoutes = ({
|
|
|
162
141
|
entry,
|
|
163
142
|
entryName
|
|
164
143
|
} = entrypoint;
|
|
165
|
-
|
|
166
144
|
if (!fs.existsSync(entry)) {
|
|
167
145
|
throw new Error(`generate file system routes error, ${entry} directory not found.`);
|
|
168
146
|
}
|
|
169
|
-
|
|
170
147
|
if (!(fs.existsSync(entry) && fs.statSync(entry).isDirectory())) {
|
|
171
148
|
throw new Error(`generate file system routes error, ${entry} should be directory.`);
|
|
172
149
|
}
|
|
173
|
-
|
|
174
150
|
let routes = [];
|
|
175
151
|
recursiveReadDir({
|
|
176
152
|
dir: entry,
|
|
@@ -182,15 +158,14 @@ export const getClientRoutes = ({
|
|
|
182
158
|
const internalComponentsDir = path.resolve(internalDirectory, `${entryName}/${FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
183
159
|
fs.emptyDirSync(internalComponentsDir);
|
|
184
160
|
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
185
|
-
parents.length = 0;
|
|
161
|
+
parents.length = 0;
|
|
186
162
|
|
|
163
|
+
// FIXME: support more situations
|
|
187
164
|
routes.sort((a, b) => {
|
|
188
165
|
const delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
|
189
|
-
|
|
190
166
|
if (delta === 0) {
|
|
191
167
|
return a.path.length - b.path.length;
|
|
192
168
|
}
|
|
193
|
-
|
|
194
169
|
return delta;
|
|
195
170
|
});
|
|
196
171
|
debug(`fileSystem routes: %o`, routes);
|
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import path from 'path';
|
|
8
5
|
import { fs } from '@modern-js/utils';
|
|
9
6
|
import { makeLegalIdentifier } from "../makeLegalIdentifier";
|
|
10
7
|
import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT } from "../constants";
|
|
11
8
|
import { replaceWithAlias } from "../utils";
|
|
12
9
|
import { debug, findLayout, shouldSkip, getRouteWeight } from "./utils";
|
|
13
|
-
|
|
14
10
|
const compName = (srcDirectory, filePath) => {
|
|
15
11
|
const legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
|
16
12
|
return `Comp_${legalCompName}`;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
const layoutNameAbbr = filePath => {
|
|
20
15
|
const prefix = 'L_';
|
|
21
16
|
const dirName = path.dirname(filePath).split('/').pop() || '';
|
|
22
17
|
return `${prefix}${makeLegalIdentifier(dirName)}`;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
const parents = [];
|
|
26
|
-
/* eslint-disable no-param-reassign */
|
|
27
20
|
|
|
21
|
+
/* eslint-disable no-param-reassign */
|
|
28
22
|
const recursiveReadDirLegacy = ({
|
|
29
23
|
dir,
|
|
30
24
|
routes,
|
|
@@ -36,7 +30,6 @@ const recursiveReadDirLegacy = ({
|
|
|
36
30
|
let resetParent = false;
|
|
37
31
|
let parent = parents[parents.length - 1];
|
|
38
32
|
const layout = findLayout(dir);
|
|
39
|
-
|
|
40
33
|
if (layout) {
|
|
41
34
|
if (_basePath === '/') {
|
|
42
35
|
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
@@ -58,16 +51,13 @@ const recursiveReadDirLegacy = ({
|
|
|
58
51
|
routes = route.routes;
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
for (const relative of fs.readdirSync(dir)) {
|
|
63
55
|
const filePath = path.join(dir, relative);
|
|
64
|
-
|
|
65
56
|
if (!shouldSkip(filePath)) {
|
|
66
57
|
const filename = path.basename(filePath, path.extname(filePath));
|
|
67
58
|
const alias = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
|
68
59
|
const componentName = compName(srcDirectory, filePath);
|
|
69
60
|
const dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
70
|
-
|
|
71
61
|
if (dynamicRouteMatched) {
|
|
72
62
|
if (hasDynamicRoute) {
|
|
73
63
|
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
@@ -75,7 +65,6 @@ const recursiveReadDirLegacy = ({
|
|
|
75
65
|
hasDynamicRoute = true;
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
const route = {
|
|
80
69
|
path: `${_basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
81
70
|
_component: alias,
|
|
@@ -83,7 +72,6 @@ const recursiveReadDirLegacy = ({
|
|
|
83
72
|
exact: true,
|
|
84
73
|
parent
|
|
85
74
|
};
|
|
86
|
-
|
|
87
75
|
if (fs.statSync(filePath).isDirectory()) {
|
|
88
76
|
recursiveReadDirLegacy({
|
|
89
77
|
dir: filePath,
|
|
@@ -94,39 +82,33 @@ const recursiveReadDirLegacy = ({
|
|
|
94
82
|
});
|
|
95
83
|
continue;
|
|
96
84
|
}
|
|
97
|
-
|
|
98
85
|
if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
99
86
|
continue;
|
|
100
87
|
}
|
|
101
|
-
|
|
102
88
|
if (filename === FILE_SYSTEM_ROUTES_INDEX) {
|
|
103
89
|
route.path = _basePath === '/' ? _basePath : `${_basePath.substring(0, _basePath.length - 1)}`;
|
|
104
90
|
}
|
|
105
|
-
|
|
106
91
|
if (filename === '404' && _basePath === '/') {
|
|
107
92
|
route.path = '*';
|
|
108
93
|
route.exact = false;
|
|
109
94
|
}
|
|
110
|
-
|
|
111
95
|
routes.push(route);
|
|
112
96
|
}
|
|
113
97
|
}
|
|
114
|
-
|
|
115
98
|
if (resetParent) {
|
|
116
99
|
parents.pop();
|
|
117
100
|
}
|
|
118
101
|
};
|
|
119
102
|
/* eslint-enable no-param-reassign */
|
|
120
103
|
|
|
121
|
-
|
|
122
104
|
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
123
105
|
const flat = routes => routes.reduce((memo, route) => memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [route]), []);
|
|
124
|
-
|
|
125
106
|
const generate = route => {
|
|
126
107
|
const codes = [];
|
|
127
108
|
let lastComponent = route.component;
|
|
128
|
-
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
109
|
+
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
129
110
|
|
|
111
|
+
// eslint-disable-next-line no-param-reassign, no-cond-assign
|
|
130
112
|
while (route = route.parent) {
|
|
131
113
|
const layoutComponent = route.component;
|
|
132
114
|
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
@@ -135,7 +117,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
135
117
|
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
136
118
|
lastComponent = currentComponent;
|
|
137
119
|
}
|
|
138
|
-
|
|
139
120
|
const file = path.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
140
121
|
fs.outputFileSync(file, `${imports.join('\n')}\n${codes.join('\n')}\nexport default ${lastComponent}`);
|
|
141
122
|
return {
|
|
@@ -143,7 +124,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
143
124
|
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
|
144
125
|
};
|
|
145
126
|
};
|
|
146
|
-
|
|
147
127
|
const normalized = flat(nested).map(route => route.parent ? _objectSpread(_objectSpread(_objectSpread({}, route), generate(route)), {}, {
|
|
148
128
|
parent: undefined
|
|
149
129
|
}) : _objectSpread(_objectSpread({}, route), {}, {
|
|
@@ -151,7 +131,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
151
131
|
}));
|
|
152
132
|
return normalized;
|
|
153
133
|
};
|
|
154
|
-
|
|
155
134
|
export const getClientRoutes = ({
|
|
156
135
|
entrypoint,
|
|
157
136
|
srcDirectory,
|
|
@@ -163,15 +142,12 @@ export const getClientRoutes = ({
|
|
|
163
142
|
entry,
|
|
164
143
|
entryName
|
|
165
144
|
} = entrypoint;
|
|
166
|
-
|
|
167
145
|
if (!fs.existsSync(entry)) {
|
|
168
146
|
throw new Error(`generate file system routes error, ${entry} directory not found.`);
|
|
169
147
|
}
|
|
170
|
-
|
|
171
148
|
if (!(fs.existsSync(entry) && fs.statSync(entry).isDirectory())) {
|
|
172
149
|
throw new Error(`generate file system routes error, ${entry} should be directory.`);
|
|
173
150
|
}
|
|
174
|
-
|
|
175
151
|
let routes = [];
|
|
176
152
|
recursiveReadDirLegacy({
|
|
177
153
|
dir: entry,
|
|
@@ -183,15 +159,14 @@ export const getClientRoutes = ({
|
|
|
183
159
|
const internalComponentsDir = path.resolve(internalDirectory, `${entryName}/${FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
184
160
|
fs.emptyDirSync(internalComponentsDir);
|
|
185
161
|
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
186
|
-
parents.length = 0;
|
|
162
|
+
parents.length = 0;
|
|
187
163
|
|
|
164
|
+
// FIXME: support more situations
|
|
188
165
|
routes.sort((a, b) => {
|
|
189
166
|
const delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
|
190
|
-
|
|
191
167
|
if (delta === 0) {
|
|
192
168
|
return a.path.length - b.path.length;
|
|
193
169
|
}
|
|
194
|
-
|
|
195
170
|
return delta;
|
|
196
171
|
});
|
|
197
172
|
debug(`fileSystem routes: %o`, routes);
|
|
@@ -10,12 +10,9 @@ export const shouldSkip = file => {
|
|
|
10
10
|
if (fs.statSync(file).isDirectory()) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
const ext = path.extname(file);
|
|
15
|
-
|
|
16
14
|
if (FILE_SYSTEM_ROUTES_IGNORED_REGEX.test(file) || !JS_EXTENSIONS.includes(ext) || FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT === path.basename(file, ext)) {
|
|
17
15
|
return true;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
return false;
|
|
21
18
|
};
|
|
@@ -3,44 +3,35 @@ import path from 'path';
|
|
|
3
3
|
import { findExists, ensureAbsolutePath } from '@modern-js/utils';
|
|
4
4
|
import { isDefaultExportFunction } from "./isDefaultExportFunction";
|
|
5
5
|
import { JS_EXTENSIONS, INDEX_FILE_NAME, APP_FILE_NAME, PAGES_DIR_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, NESTED_ROUTES_DIR } from "./constants";
|
|
6
|
-
|
|
7
6
|
const hasIndex = dir => findExists(JS_EXTENSIONS.map(ext => path.resolve(dir, `${INDEX_FILE_NAME}${ext}`)));
|
|
8
|
-
|
|
9
7
|
const hasApp = dir => findExists(JS_EXTENSIONS.map(ext => path.resolve(dir, `${APP_FILE_NAME}${ext}`)));
|
|
10
|
-
|
|
11
8
|
const hasPages = dir => fs.existsSync(path.join(dir, PAGES_DIR_NAME));
|
|
12
|
-
|
|
13
9
|
const hasNestedRoutes = dir => fs.existsSync(path.join(dir, NESTED_ROUTES_DIR));
|
|
14
|
-
|
|
15
10
|
const isBundleEntry = dir => hasApp(dir) || hasPages(dir) || hasIndex(dir) || hasNestedRoutes(dir);
|
|
16
|
-
|
|
17
11
|
const scanDir = dirs => dirs.map(dir => {
|
|
18
12
|
const indexFile = hasIndex(dir);
|
|
19
13
|
const customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
|
20
14
|
const entryName = path.basename(dir);
|
|
21
|
-
|
|
22
15
|
if (indexFile && !customBootstrap) {
|
|
23
16
|
return {
|
|
24
17
|
entryName,
|
|
25
18
|
entry: indexFile,
|
|
19
|
+
absoluteEntryDir: path.resolve(dir),
|
|
26
20
|
isAutoMount: false
|
|
27
21
|
};
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
const isHasApp = hasApp(dir);
|
|
31
|
-
|
|
32
24
|
if (isHasApp) {
|
|
33
25
|
return {
|
|
34
26
|
entryName,
|
|
35
27
|
entry: path.join(dir, APP_FILE_NAME),
|
|
36
28
|
isAutoMount: true,
|
|
29
|
+
absoluteEntryDir: path.resolve(dir),
|
|
37
30
|
customBootstrap
|
|
38
31
|
};
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
const isHasNestedRoutes = hasNestedRoutes(dir);
|
|
42
34
|
const isHasPages = hasPages(dir);
|
|
43
|
-
|
|
44
35
|
if (isHasNestedRoutes || isHasPages) {
|
|
45
36
|
const entrypoint = {
|
|
46
37
|
entryName,
|
|
@@ -49,27 +40,24 @@ const scanDir = dirs => dirs.map(dir => {
|
|
|
49
40
|
globalApp: findExists(JS_EXTENSIONS.map(ext => path.resolve(dir, `./${PAGES_DIR_NAME}/${FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
|
|
50
41
|
},
|
|
51
42
|
isAutoMount: true,
|
|
43
|
+
absoluteEntryDir: path.resolve(dir),
|
|
52
44
|
customBootstrap
|
|
53
45
|
};
|
|
54
|
-
|
|
55
46
|
if (isHasPages) {
|
|
56
47
|
entrypoint.entry = path.join(dir, PAGES_DIR_NAME);
|
|
57
48
|
}
|
|
58
|
-
|
|
59
49
|
if (isHasNestedRoutes) {
|
|
60
50
|
entrypoint.nestedRoutesEntry = path.join(dir, NESTED_ROUTES_DIR);
|
|
61
51
|
}
|
|
62
|
-
|
|
63
52
|
return entrypoint;
|
|
64
53
|
}
|
|
65
|
-
|
|
66
54
|
return {
|
|
67
55
|
entryName,
|
|
68
56
|
entry: indexFile,
|
|
57
|
+
absoluteEntryDir: path.resolve(dir),
|
|
69
58
|
isAutoMount: false
|
|
70
59
|
};
|
|
71
60
|
});
|
|
72
|
-
|
|
73
61
|
export const getFileSystemEntry = (appContext, config) => {
|
|
74
62
|
const {
|
|
75
63
|
appDirectory
|
|
@@ -79,8 +67,7 @@ export const getFileSystemEntry = (appContext, config) => {
|
|
|
79
67
|
entriesDir
|
|
80
68
|
}
|
|
81
69
|
} = config;
|
|
82
|
-
const src = ensureAbsolutePath(appDirectory, entriesDir);
|
|
83
|
-
|
|
70
|
+
const src = ensureAbsolutePath(appDirectory, entriesDir || '');
|
|
84
71
|
if (fs.existsSync(src)) {
|
|
85
72
|
if (fs.statSync(src).isDirectory()) {
|
|
86
73
|
return scanDir(isBundleEntry(src) ? [src] : fs.readdirSync(src).map(file => path.join(src, file)).filter(file => fs.statSync(file).isDirectory() && isBundleEntry(file)));
|
|
@@ -3,7 +3,6 @@ import { fs, findExists, MAIN_ENTRY_NAME } from '@modern-js/utils';
|
|
|
3
3
|
import { HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER } from "./constants";
|
|
4
4
|
import * as templates from "./templates";
|
|
5
5
|
var PartialPosition;
|
|
6
|
-
|
|
7
6
|
(function (PartialPosition) {
|
|
8
7
|
PartialPosition["TOP"] = "top";
|
|
9
8
|
PartialPosition["HEAD"] = "head";
|
|
@@ -11,7 +10,6 @@ var PartialPosition;
|
|
|
11
10
|
PartialPosition["BOTTOM"] = "bottom";
|
|
12
11
|
PartialPosition["INDEX"] = "index";
|
|
13
12
|
})(PartialPosition || (PartialPosition = {}));
|
|
14
|
-
|
|
15
13
|
const findPartials = (dir, entryName, position) => {
|
|
16
14
|
if (fs.existsSync(dir)) {
|
|
17
15
|
const base = findExists(HTML_PARTIALS_EXTENSIONS.map(ext => path.resolve(dir, `${position}${ext}`)));
|
|
@@ -21,11 +19,10 @@ const findPartials = (dir, entryName, position) => {
|
|
|
21
19
|
content: fs.readFileSync(file, 'utf8')
|
|
22
20
|
} : null;
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
return null;
|
|
26
|
-
};
|
|
27
|
-
|
|
23
|
+
};
|
|
28
24
|
|
|
25
|
+
// generate html template for
|
|
29
26
|
export const getHtmlTemplate = async (entrypoints, api, {
|
|
30
27
|
appContext,
|
|
31
28
|
config
|
|
@@ -39,16 +36,14 @@ export const getHtmlTemplate = async (entrypoints, api, {
|
|
|
39
36
|
configDir
|
|
40
37
|
}
|
|
41
38
|
} = config;
|
|
42
|
-
const htmlDir = path.resolve(appDirectory, configDir, HTML_PARTIALS_FOLDER);
|
|
39
|
+
const htmlDir = path.resolve(appDirectory, configDir || '', HTML_PARTIALS_FOLDER);
|
|
43
40
|
const htmlTemplates = {};
|
|
44
|
-
|
|
45
41
|
for (const entrypoint of entrypoints) {
|
|
46
42
|
const {
|
|
47
43
|
entryName
|
|
48
44
|
} = entrypoint;
|
|
49
45
|
const name = entrypoints.length === 1 && entryName === MAIN_ENTRY_NAME ? '' : entryName;
|
|
50
46
|
const customIndexTemplate = findPartials(htmlDir, name, PartialPosition.INDEX);
|
|
51
|
-
|
|
52
47
|
if (customIndexTemplate) {
|
|
53
48
|
htmlTemplates[entryName] = customIndexTemplate.file;
|
|
54
49
|
} else {
|
|
@@ -71,12 +66,10 @@ export const getHtmlTemplate = async (entrypoints, api, {
|
|
|
71
66
|
fs.outputFileSync(templatePath, templates.html(partials), 'utf8');
|
|
72
67
|
htmlTemplates[entryName] = templatePath;
|
|
73
68
|
const bottomTemplate = findPartials(htmlDir, name, PartialPosition.BOTTOM);
|
|
74
|
-
|
|
75
69
|
if (bottomTemplate) {
|
|
76
70
|
htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
}
|
|
80
|
-
|
|
81
74
|
return htmlTemplates;
|
|
82
75
|
};
|
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
const _excluded = ["path"],
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
_excluded2 = ["path"];
|
|
4
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
5
|
-
|
|
6
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
7
|
-
|
|
8
5
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
-
|
|
10
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
-
|
|
12
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
-
|
|
14
8
|
import path from 'path';
|
|
15
9
|
import fs from 'fs';
|
|
16
10
|
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash } from '@modern-js/utils';
|
|
17
11
|
import { walkDirectory } from "./utils";
|
|
12
|
+
|
|
18
13
|
/**
|
|
19
14
|
* Add base url for each server route.
|
|
20
15
|
* @param baseUrl - Base url from server.baseUrl
|
|
21
16
|
* @param routes - Server routes.
|
|
22
17
|
* @returns Server routes with baseUrl prefixed.
|
|
23
18
|
*/
|
|
24
|
-
|
|
25
19
|
const applyBaseUrl = (baseUrl, routes) => {
|
|
26
20
|
if (baseUrl) {
|
|
27
21
|
if (Array.isArray(baseUrl)) {
|
|
@@ -35,37 +29,34 @@ const applyBaseUrl = (baseUrl, routes) => {
|
|
|
35
29
|
});
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
return routes;
|
|
40
33
|
};
|
|
34
|
+
|
|
41
35
|
/**
|
|
42
36
|
*
|
|
43
37
|
* @param original - Original entrypoint route info.
|
|
44
38
|
* @param routeOptions - Custom entrypoint route config from server.routes.
|
|
45
39
|
* @returns
|
|
46
40
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
41
|
const applyRouteOptions = (original, routeOptions) => {
|
|
50
42
|
const {
|
|
51
43
|
route,
|
|
52
44
|
disableSpa
|
|
53
45
|
} = routeOptions;
|
|
54
|
-
original.isSPA = !disableSpa;
|
|
46
|
+
original.isSPA = !disableSpa;
|
|
55
47
|
|
|
48
|
+
// set entryPath as dir
|
|
56
49
|
!original.isSPA && (original.entryPath = path.dirname(original.entryPath));
|
|
57
50
|
let routes;
|
|
58
|
-
|
|
59
51
|
if (route) {
|
|
60
52
|
if (Array.isArray(route)) {
|
|
61
53
|
routes = route.map(url => {
|
|
62
54
|
if (isPlainObject(url)) {
|
|
63
55
|
const _ref = url,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
{
|
|
57
|
+
path: urlPath
|
|
58
|
+
} = _ref,
|
|
59
|
+
other = _objectWithoutProperties(_ref, _excluded);
|
|
69
60
|
return _objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
|
|
70
61
|
urlPath
|
|
71
62
|
});
|
|
@@ -77,11 +68,10 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
77
68
|
});
|
|
78
69
|
} else if (isPlainObject(route)) {
|
|
79
70
|
const _ref2 = route,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
{
|
|
72
|
+
path: urlPath
|
|
73
|
+
} = _ref2,
|
|
74
|
+
other = _objectWithoutProperties(_ref2, _excluded2);
|
|
85
75
|
routes = [_objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
|
|
86
76
|
urlPath
|
|
87
77
|
})];
|
|
@@ -93,23 +83,24 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
93
83
|
} else {
|
|
94
84
|
routes = [original];
|
|
95
85
|
}
|
|
96
|
-
|
|
97
86
|
return routes;
|
|
98
87
|
};
|
|
88
|
+
|
|
99
89
|
/**
|
|
100
90
|
* Collect routes from entrypoints.
|
|
101
91
|
* @param entrypoints - Bundle entrypoints.
|
|
102
92
|
* @param config - Normalized user config.
|
|
103
93
|
* @returns entrypoint Routes
|
|
104
94
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
95
|
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
108
96
|
const {
|
|
97
|
+
html: {
|
|
98
|
+
disableHtmlFolder
|
|
99
|
+
},
|
|
109
100
|
output: {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
101
|
+
distPath: {
|
|
102
|
+
html: htmlPath
|
|
103
|
+
} = {}
|
|
113
104
|
},
|
|
114
105
|
server: {
|
|
115
106
|
baseUrl,
|
|
@@ -136,30 +127,28 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
136
127
|
isSPA: true,
|
|
137
128
|
isSSR,
|
|
138
129
|
responseHeaders: resHeaders,
|
|
139
|
-
|
|
130
|
+
// FIXME: remove the config.enableModernMode
|
|
131
|
+
// enableModernMode: Boolean(enableModernMode),
|
|
140
132
|
bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : undefined
|
|
141
133
|
};
|
|
142
|
-
|
|
143
134
|
if (routes !== null && routes !== void 0 && routes.hasOwnProperty(entryName)) {
|
|
144
135
|
const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
|
|
145
136
|
route: routes[entryName]
|
|
146
137
|
};
|
|
147
138
|
route = applyRouteOptions(route, routeOptions);
|
|
148
139
|
}
|
|
149
|
-
|
|
150
140
|
return Array.isArray(route) ? [...previous, ...route] : [...previous, route];
|
|
151
141
|
}, []);
|
|
152
142
|
htmlRoutes = applyBaseUrl(baseUrl, htmlRoutes);
|
|
153
143
|
return htmlRoutes;
|
|
154
144
|
};
|
|
145
|
+
|
|
155
146
|
/**
|
|
156
147
|
* Collect static public file routes from config/public folder.
|
|
157
148
|
* @param appContext - App context info.
|
|
158
149
|
* @param config - normalized user config.
|
|
159
150
|
* @returns Static public file routes.
|
|
160
151
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
152
|
const collectStaticRoutes = (appContext, config) => {
|
|
164
153
|
const {
|
|
165
154
|
appDirectory
|
|
@@ -172,21 +161,19 @@ const collectStaticRoutes = (appContext, config) => {
|
|
|
172
161
|
publicRoutes = {}
|
|
173
162
|
}
|
|
174
163
|
} = config;
|
|
175
|
-
const publicFolder = path.resolve(appDirectory, configDir, 'public');
|
|
164
|
+
const publicFolder = path.resolve(appDirectory, configDir || '', 'public');
|
|
176
165
|
return fs.existsSync(publicFolder) ? walkDirectory(publicFolder).map(filePath => {
|
|
177
166
|
const urlPath = `${urlJoin(toPosix(filePath).slice(toPosix(publicFolder).length))}`;
|
|
178
167
|
return {
|
|
179
168
|
urlPath: publicRoutes[removeLeadingSlash(urlPath)] || urlPath,
|
|
180
169
|
isSPA: true,
|
|
181
170
|
isSSR: false,
|
|
182
|
-
entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir), filePath))
|
|
171
|
+
entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir || ''), filePath))
|
|
183
172
|
};
|
|
184
173
|
}) : [];
|
|
185
174
|
};
|
|
186
|
-
|
|
187
175
|
export const getServerRoutes = (entrypoints, {
|
|
188
176
|
appContext,
|
|
189
177
|
config
|
|
190
178
|
}) => [...collectHtmlRoutes(entrypoints, appContext, config), ...collectStaticRoutes(appContext, config)];
|
|
191
|
-
|
|
192
179
|
const toPosix = pathStr => pathStr.split(path.sep).join(path.posix.sep);
|