@modern-js/app-tools 1.22.2 → 2.0.0-alpha.0
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 +1383 -104
- package/bin/modern.js +13 -1
- package/dist/js/modern/analyze/Builder.js +39 -0
- package/dist/js/modern/analyze/constants.js +48 -15
- package/dist/js/modern/analyze/generateCode.js +286 -133
- package/dist/js/modern/analyze/getBundleEntry.js +39 -41
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
- package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
- package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +74 -39
- package/dist/js/modern/analyze/getHtmlTemplate.js +90 -57
- package/dist/js/modern/analyze/getServerRoutes.js +123 -140
- package/dist/js/modern/analyze/index.js +220 -133
- package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -20
- package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -13
- package/dist/js/modern/analyze/nestedRoutes.js +166 -0
- package/dist/js/modern/analyze/templates.js +289 -29
- package/dist/js/modern/analyze/utils.js +128 -58
- package/dist/js/modern/builder/builderPlugins/compatModern.js +233 -0
- package/dist/js/modern/builder/index.js +154 -0
- package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
- package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
- package/dist/js/modern/builder/share.js +46 -0
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
- package/dist/js/modern/commands/build.js +75 -138
- package/dist/js/modern/commands/deploy.js +27 -4
- package/dist/js/modern/commands/dev.js +102 -66
- package/dist/js/modern/commands/index.js +1 -1
- package/dist/js/modern/commands/inspect.js +33 -64
- package/dist/js/modern/commands/serve.js +54 -0
- package/dist/js/modern/config/default.js +173 -0
- package/dist/js/modern/config/index.js +8 -0
- package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
- package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
- package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
- package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
- package/dist/js/modern/config/initial/index.js +16 -0
- package/dist/js/modern/config/initial/inits.js +153 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
- package/dist/js/modern/defineConfig.js +27 -0
- package/dist/js/modern/exports/server.js +4 -1
- package/dist/js/modern/hooks.js +37 -21
- package/dist/js/modern/index.js +185 -94
- package/dist/js/modern/initialize/index.js +120 -0
- package/dist/js/modern/locale/en.js +20 -22
- package/dist/js/modern/locale/index.js +6 -6
- package/dist/js/modern/locale/zh.js +21 -23
- package/dist/js/modern/schema/Schema.js +40 -0
- package/dist/js/modern/schema/index.js +88 -0
- package/dist/js/modern/schema/legacy.js +148 -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 +1 -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 +3 -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 +0 -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/commands.js +13 -0
- package/dist/js/modern/utils/config.js +102 -52
- package/dist/js/modern/utils/createFileWatcher.js +115 -0
- package/dist/js/modern/utils/createServer.js +67 -10
- package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
- package/dist/js/modern/utils/getSpecifiedEntries.js +46 -25
- package/dist/js/modern/utils/language.js +6 -3
- package/dist/js/modern/utils/printInstructions.js +29 -9
- package/dist/js/modern/utils/restart.js +44 -0
- package/dist/js/modern/utils/routes.js +29 -14
- package/dist/js/node/analyze/Builder.js +64 -0
- package/dist/js/node/analyze/constants.js +86 -33
- package/dist/js/node/analyze/generateCode.js +305 -163
- package/dist/js/node/analyze/getBundleEntry.js +66 -58
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
- package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
- package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +99 -58
- package/dist/js/node/analyze/getHtmlTemplate.js +121 -83
- package/dist/js/node/analyze/getServerRoutes.js +146 -160
- package/dist/js/node/analyze/index.js +243 -161
- package/dist/js/node/analyze/isDefaultExportFunction.js +59 -38
- package/dist/js/node/analyze/makeLegalIdentifier.js +31 -19
- package/dist/js/node/analyze/nestedRoutes.js +193 -0
- package/dist/js/node/analyze/templates.js +316 -43
- package/dist/js/node/analyze/utils.js +158 -78
- package/dist/js/node/builder/builderPlugins/compatModern.js +258 -0
- package/dist/js/node/builder/index.js +177 -0
- package/dist/js/node/builder/loaders/routerLoader.js +38 -0
- package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
- package/dist/js/node/builder/share.js +75 -0
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
- package/dist/js/node/commands/build.js +97 -159
- package/dist/js/node/commands/deploy.js +49 -12
- package/dist/js/node/commands/dev.js +121 -93
- package/dist/js/node/commands/index.js +19 -44
- package/dist/js/node/commands/inspect.js +56 -93
- package/dist/js/node/commands/serve.js +83 -0
- package/dist/js/node/config/default.js +195 -0
- package/dist/js/node/config/index.js +34 -0
- package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
- package/dist/js/node/config/initial/createOutputConfig.js +91 -0
- package/dist/js/node/config/initial/createSourceConfig.js +62 -0
- package/dist/js/node/config/initial/createToolsConfig.js +65 -0
- package/dist/js/node/config/initial/index.js +41 -0
- package/dist/js/node/config/initial/inits.js +176 -0
- package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
- package/dist/js/node/defineConfig.js +49 -0
- package/dist/js/node/exports/server.js +25 -11
- package/dist/js/node/hooks.js +53 -36
- package/dist/js/node/index.js +216 -128
- package/dist/js/node/initialize/index.js +135 -0
- package/dist/js/node/locale/en.js +40 -26
- package/dist/js/node/locale/index.js +31 -18
- package/dist/js/node/locale/zh.js +41 -27
- package/dist/js/node/schema/Schema.js +63 -0
- package/dist/js/node/schema/index.js +118 -0
- package/dist/js/node/schema/legacy.js +169 -0
- package/dist/js/node/types/config/deploy.js +15 -0
- package/dist/js/node/types/config/dev.js +15 -0
- package/dist/js/node/types/config/experiments.js +15 -0
- package/dist/js/node/types/config/html.js +15 -0
- package/dist/js/node/types/config/index.js +17 -0
- package/dist/js/node/types/config/output.js +15 -0
- package/dist/js/node/types/config/performance.js +15 -0
- package/dist/js/node/types/config/security.js +15 -0
- package/dist/js/node/types/config/source.js +15 -0
- package/dist/js/node/types/config/tools.js +15 -0
- package/dist/js/node/types/hooks.js +15 -0
- package/dist/js/node/types/index.js +19 -0
- package/dist/js/node/types/legacyConfig/deploy.js +15 -0
- package/dist/js/node/types/legacyConfig/dev.js +15 -0
- package/dist/js/node/types/legacyConfig/index.js +15 -0
- package/dist/js/node/types/legacyConfig/output.js +15 -0
- package/dist/js/node/types/legacyConfig/source.js +15 -0
- package/dist/js/node/types/legacyConfig/tools.js +15 -0
- package/dist/js/node/utils/commands.js +37 -0
- package/dist/js/node/utils/config.js +125 -75
- package/dist/js/node/utils/createFileWatcher.js +139 -0
- package/dist/js/node/utils/createServer.js +96 -25
- package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +68 -34
- package/dist/js/node/utils/language.js +28 -10
- package/dist/js/node/utils/printInstructions.js +51 -19
- package/dist/js/node/utils/restart.js +67 -0
- package/dist/js/node/utils/routes.js +58 -24
- package/dist/js/node/utils/types.js +15 -0
- package/dist/js/treeshaking/analyze/Builder.js +199 -0
- package/dist/js/treeshaking/analyze/constants.js +37 -0
- package/dist/js/treeshaking/analyze/generateCode.js +615 -0
- package/dist/js/treeshaking/analyze/getBundleEntry.js +64 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
- package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
- package/dist/js/treeshaking/analyze/index.js +589 -0
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
- package/dist/js/treeshaking/analyze/nestedRoutes.js +426 -0
- package/dist/js/treeshaking/analyze/templates.js +446 -0
- package/dist/js/treeshaking/analyze/utils.js +390 -0
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +304 -0
- package/dist/js/treeshaking/builder/index.js +374 -0
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
- package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
- package/dist/js/treeshaking/builder/share.js +40 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +343 -0
- package/dist/js/treeshaking/commands/build.js +291 -0
- package/dist/js/treeshaking/commands/deploy.js +154 -0
- package/dist/js/treeshaking/commands/dev.js +319 -0
- package/dist/js/treeshaking/commands/index.js +3 -0
- package/dist/js/treeshaking/commands/inspect.js +149 -0
- package/dist/js/treeshaking/commands/serve.js +199 -0
- package/dist/js/treeshaking/config/default.js +208 -0
- package/dist/js/treeshaking/config/index.js +3 -0
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
- package/dist/js/treeshaking/config/initial/index.js +12 -0
- package/dist/js/treeshaking/config/initial/inits.js +213 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
- package/dist/js/treeshaking/defineConfig.js +61 -0
- package/dist/js/treeshaking/exports/server.js +2 -0
- package/dist/js/treeshaking/hooks.js +31 -0
- package/dist/js/treeshaking/index.js +694 -0
- package/dist/js/treeshaking/initialize/index.js +300 -0
- package/dist/js/treeshaking/locale/en.js +35 -0
- package/dist/js/treeshaking/locale/index.js +9 -0
- package/dist/js/treeshaking/locale/zh.js +35 -0
- package/dist/js/treeshaking/schema/Schema.js +273 -0
- package/dist/js/treeshaking/schema/index.js +181 -0
- package/dist/js/treeshaking/schema/legacy.js +337 -0
- package/dist/js/treeshaking/types/config/deploy.js +1 -0
- package/dist/js/treeshaking/types/config/dev.js +1 -0
- package/dist/js/treeshaking/types/config/experiments.js +1 -0
- package/dist/js/treeshaking/types/config/html.js +1 -0
- package/dist/js/treeshaking/types/config/index.js +1 -0
- package/dist/js/treeshaking/types/config/output.js +1 -0
- package/dist/js/treeshaking/types/config/performance.js +1 -0
- package/dist/js/treeshaking/types/config/security.js +1 -0
- package/dist/js/treeshaking/types/config/source.js +1 -0
- package/dist/js/treeshaking/types/config/tools.js +1 -0
- package/dist/js/treeshaking/types/hooks.js +1 -0
- package/dist/js/treeshaking/types/index.js +3 -0
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
- package/dist/js/treeshaking/utils/commands.js +10 -0
- package/dist/js/treeshaking/utils/config.js +302 -0
- package/dist/js/treeshaking/utils/createFileWatcher.js +283 -0
- package/dist/js/treeshaking/utils/createServer.js +258 -0
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +185 -0
- package/dist/js/treeshaking/utils/language.js +6 -0
- package/dist/js/treeshaking/utils/printInstructions.js +152 -0
- package/dist/js/treeshaking/utils/restart.js +187 -0
- package/dist/js/treeshaking/utils/routes.js +153 -0
- package/dist/js/treeshaking/utils/types.js +1 -0
- package/dist/types/analyze/Builder.d.ts +8 -0
- package/dist/types/analyze/constants.d.ts +13 -1
- package/dist/types/analyze/generateCode.d.ts +3 -2
- package/dist/types/analyze/getBundleEntry.d.ts +2 -2
- package/dist/types/analyze/{getClientRoutes.d.ts → getClientRoutes/getRoutes.d.ts} +2 -7
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +15 -0
- package/dist/types/analyze/getClientRoutes/index.d.ts +2 -0
- package/dist/types/analyze/getClientRoutes/utils.d.ts +5 -0
- 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 -40
- package/dist/types/analyze/nestedRoutes.d.ts +5 -0
- package/dist/types/analyze/templates.d.ts +24 -5
- package/dist/types/analyze/utils.d.ts +12 -2
- package/dist/types/builder/builderPlugins/compatModern.d.ts +14 -0
- package/dist/types/builder/index.d.ts +18 -0
- package/dist/types/builder/loaders/routerLoader.d.ts +3 -0
- package/dist/types/builder/loaders/serverModuleLoader.d.ts +3 -0
- package/dist/types/builder/share.d.ts +26 -0
- package/dist/types/builder/webpackPlugins/htmlAsyncChunkPlugin.d.ts +8 -0
- package/dist/types/builder/webpackPlugins/htmlBottomTemplate.d.ts +10 -0
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +4 -0
- package/dist/types/commands/build.d.ts +2 -1
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +10 -6
- package/dist/types/commands/serve.d.ts +3 -0
- 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 +8 -0
- package/dist/types/hooks.d.ts +2 -37
- package/dist/types/index.d.ts +9 -3
- package/dist/types/initialize/index.d.ts +5 -0
- package/dist/types/locale/en.d.ts +1 -2
- package/dist/types/locale/index.d.ts +2 -4
- package/dist/types/locale/zh.d.ts +1 -2
- 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 +66 -0
- package/dist/types/types/config/output.d.ts +22 -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 +24 -0
- package/dist/types/types/config/tools.d.ts +24 -0
- package/dist/types/types/hooks.d.ts +89 -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 +13 -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 +17 -0
- package/dist/types/utils/commands.d.ts +2 -0
- package/dist/types/utils/config.d.ts +2 -2
- package/dist/types/utils/createFileWatcher.d.ts +4 -0
- package/dist/types/utils/createServer.d.ts +9 -1
- package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
- package/dist/types/utils/printInstructions.d.ts +3 -2
- package/dist/types/utils/restart.d.ts +3 -0
- package/dist/types/utils/types.d.ts +2 -3
- package/lib/types.d.ts +1 -1
- package/package.json +37 -46
- package/dist/js/modern/analyze/getClientRoutes.js +0 -219
- package/dist/js/modern/commands/start.js +0 -31
- package/dist/js/modern/utils/createCompiler.js +0 -61
- package/dist/js/node/analyze/getClientRoutes.js +0 -241
- package/dist/js/node/commands/start.js +0 -47
- package/dist/js/node/utils/createCompiler.js +0 -81
- package/dist/types/commands/start.d.ts +0 -2
- package/dist/types/utils/createCompiler.d.ts +0 -13
|
@@ -1,219 +0,0 @@
|
|
|
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
|
-
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
|
-
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
|
-
import path from 'path';
|
|
8
|
-
import { fs, createDebugger, findExists, normalizeToPosixPath } from '@modern-js/utils';
|
|
9
|
-
import { makeLegalIdentifier } from "./makeLegalIdentifier";
|
|
10
|
-
import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, JS_EXTENSIONS } from "./constants";
|
|
11
|
-
const debug = createDebugger('get-client-routes');
|
|
12
|
-
|
|
13
|
-
const findLayout = dir => findExists(JS_EXTENSIONS.map(ext => path.resolve(dir, `${FILE_SYSTEM_ROUTES_LAYOUT}${ext}`)));
|
|
14
|
-
|
|
15
|
-
const shouldSkip = file => {
|
|
16
|
-
// should not skip directory.
|
|
17
|
-
if (fs.statSync(file).isDirectory()) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const ext = path.extname(file);
|
|
22
|
-
|
|
23
|
-
if (FILE_SYSTEM_ROUTES_IGNORED_REGEX.test(file) || !JS_EXTENSIONS.includes(ext) || FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT === path.basename(file, ext)) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return false;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const replaceWithAlias = (base, filePath, alias) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
31
|
-
|
|
32
|
-
const compName = (srcDirectory, filePath) => {
|
|
33
|
-
const legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
|
34
|
-
return `Comp_${legalCompName}`;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const layoutNameAbbr = filePath => {
|
|
38
|
-
const prefix = 'L_';
|
|
39
|
-
const dirName = path.dirname(filePath).split('/').pop() || '';
|
|
40
|
-
return `${prefix}${makeLegalIdentifier(dirName)}`;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const parents = [];
|
|
44
|
-
/* eslint-disable no-param-reassign */
|
|
45
|
-
|
|
46
|
-
const recursiveReadDir = ({
|
|
47
|
-
dir,
|
|
48
|
-
routes,
|
|
49
|
-
basePath: _basePath = '/',
|
|
50
|
-
srcDirectory,
|
|
51
|
-
srcAlias
|
|
52
|
-
}) => {
|
|
53
|
-
let hasDynamicRoute = false;
|
|
54
|
-
let resetParent = false;
|
|
55
|
-
let parent = parents[parents.length - 1];
|
|
56
|
-
const layout = findLayout(dir);
|
|
57
|
-
|
|
58
|
-
if (layout) {
|
|
59
|
-
if (_basePath === '/') {
|
|
60
|
-
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
61
|
-
} else {
|
|
62
|
-
const alias = replaceWithAlias(srcDirectory, layout, srcAlias);
|
|
63
|
-
const componentName = compName(srcDirectory, layout);
|
|
64
|
-
const route = {
|
|
65
|
-
path: `${_basePath.substring(0, _basePath.length - 1)}`,
|
|
66
|
-
exact: false,
|
|
67
|
-
routes: [],
|
|
68
|
-
_component: alias,
|
|
69
|
-
component: componentName,
|
|
70
|
-
parent
|
|
71
|
-
};
|
|
72
|
-
parent = route;
|
|
73
|
-
resetParent = true;
|
|
74
|
-
routes.push(route);
|
|
75
|
-
parents.push(route);
|
|
76
|
-
routes = route.routes;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (const relative of fs.readdirSync(dir)) {
|
|
81
|
-
const filePath = path.join(dir, relative);
|
|
82
|
-
|
|
83
|
-
if (!shouldSkip(filePath)) {
|
|
84
|
-
const filename = path.basename(filePath, path.extname(filePath));
|
|
85
|
-
const alias = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
|
86
|
-
const componentName = compName(srcDirectory, filePath);
|
|
87
|
-
const dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
88
|
-
|
|
89
|
-
if (dynamicRouteMatched) {
|
|
90
|
-
if (hasDynamicRoute) {
|
|
91
|
-
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
92
|
-
} else {
|
|
93
|
-
hasDynamicRoute = true;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const route = {
|
|
98
|
-
path: `${_basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
99
|
-
_component: alias,
|
|
100
|
-
component: componentName,
|
|
101
|
-
exact: true,
|
|
102
|
-
parent
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
if (fs.statSync(filePath).isDirectory()) {
|
|
106
|
-
recursiveReadDir({
|
|
107
|
-
dir: filePath,
|
|
108
|
-
routes,
|
|
109
|
-
basePath: `${route.path}/`,
|
|
110
|
-
srcDirectory,
|
|
111
|
-
srcAlias
|
|
112
|
-
});
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (filename === FILE_SYSTEM_ROUTES_INDEX) {
|
|
121
|
-
route.path = _basePath === '/' ? _basePath : `${_basePath.substring(0, _basePath.length - 1)}`;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (filename === '404' && _basePath === '/') {
|
|
125
|
-
route.path = '*';
|
|
126
|
-
route.exact = false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
routes.push(route);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (resetParent) {
|
|
134
|
-
parents.pop();
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
/* eslint-enable no-param-reassign */
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
141
|
-
const flat = routes => routes.reduce((memo, route) => memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [route]), []);
|
|
142
|
-
|
|
143
|
-
const generate = route => {
|
|
144
|
-
const codes = [];
|
|
145
|
-
let lastComponent = route.component;
|
|
146
|
-
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`]; // eslint-disable-next-line no-param-reassign, no-cond-assign
|
|
147
|
-
|
|
148
|
-
while (route = route.parent) {
|
|
149
|
-
const layoutComponent = route.component;
|
|
150
|
-
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
151
|
-
imports.push(`import ${layoutComponent} from '${route._component}';`);
|
|
152
|
-
const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
|
|
153
|
-
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
154
|
-
lastComponent = currentComponent;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const file = path.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
158
|
-
fs.outputFileSync(file, `${imports.join('\n')}\n${codes.join('\n')}\nexport default ${lastComponent}`);
|
|
159
|
-
return {
|
|
160
|
-
component: lastComponent,
|
|
161
|
-
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const normalized = flat(nested).map(route => route.parent ? _objectSpread(_objectSpread(_objectSpread({}, route), generate(route)), {}, {
|
|
166
|
-
parent: undefined
|
|
167
|
-
}) : _objectSpread(_objectSpread({}, route), {}, {
|
|
168
|
-
parent: undefined
|
|
169
|
-
}));
|
|
170
|
-
return normalized;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const getRouteWeight = route => route === '*' ? 999 : route.split(':').length - 1;
|
|
174
|
-
|
|
175
|
-
export const getClientRoutes = ({
|
|
176
|
-
entrypoint,
|
|
177
|
-
srcDirectory,
|
|
178
|
-
srcAlias,
|
|
179
|
-
internalDirectory,
|
|
180
|
-
internalDirAlias
|
|
181
|
-
}) => {
|
|
182
|
-
const {
|
|
183
|
-
entry,
|
|
184
|
-
entryName
|
|
185
|
-
} = entrypoint;
|
|
186
|
-
|
|
187
|
-
if (!fs.existsSync(entry)) {
|
|
188
|
-
throw new Error(`generate file system routes error, ${entry} directory not found.`);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (!(fs.existsSync(entry) && fs.statSync(entry).isDirectory())) {
|
|
192
|
-
throw new Error(`generate file system routes error, ${entry} should be directory.`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
let routes = [];
|
|
196
|
-
recursiveReadDir({
|
|
197
|
-
dir: entry,
|
|
198
|
-
routes,
|
|
199
|
-
basePath: '/',
|
|
200
|
-
srcDirectory,
|
|
201
|
-
srcAlias
|
|
202
|
-
});
|
|
203
|
-
const internalComponentsDir = path.resolve(internalDirectory, `${entryName}/${FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
204
|
-
fs.emptyDirSync(internalComponentsDir);
|
|
205
|
-
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
206
|
-
parents.length = 0; // FIXME: support more situations
|
|
207
|
-
|
|
208
|
-
routes.sort((a, b) => {
|
|
209
|
-
const delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
|
210
|
-
|
|
211
|
-
if (delta === 0) {
|
|
212
|
-
return a.path.length - b.path.length;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return delta;
|
|
216
|
-
});
|
|
217
|
-
debug(`fileSystem routes: %o`, routes);
|
|
218
|
-
return routes;
|
|
219
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { logger, chalk, isApiOnly } from '@modern-js/utils';
|
|
2
|
-
import server from '@modern-js/prod-server';
|
|
3
|
-
import { printInstructions } from "../utils/printInstructions";
|
|
4
|
-
export const start = async api => {
|
|
5
|
-
var _userConfig$source;
|
|
6
|
-
|
|
7
|
-
const appContext = api.useAppContext();
|
|
8
|
-
const userConfig = api.useResolvedConfigContext();
|
|
9
|
-
const hookRunners = api.useHookRunners();
|
|
10
|
-
const {
|
|
11
|
-
appDirectory,
|
|
12
|
-
port,
|
|
13
|
-
serverConfigFile
|
|
14
|
-
} = appContext;
|
|
15
|
-
logger.log(chalk.cyan(`Starting the modern server...`));
|
|
16
|
-
const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
|
|
17
|
-
const app = await server({
|
|
18
|
-
pwd: appDirectory,
|
|
19
|
-
config: userConfig,
|
|
20
|
-
plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
|
|
21
|
-
serverConfigFile,
|
|
22
|
-
apiOnly
|
|
23
|
-
});
|
|
24
|
-
app.listen(port, async err => {
|
|
25
|
-
if (err) {
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
await printInstructions(hookRunners, appContext, userConfig);
|
|
30
|
-
});
|
|
31
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { webpack } from '@modern-js/webpack';
|
|
2
|
-
import { chalk, logger, formatWebpackMessages, clearConsole } from '@modern-js/utils';
|
|
3
|
-
import { printInstructions } from "./printInstructions";
|
|
4
|
-
export const createCompiler = async ({
|
|
5
|
-
api,
|
|
6
|
-
webpackConfigs,
|
|
7
|
-
// TODO: params
|
|
8
|
-
userConfig,
|
|
9
|
-
appContext
|
|
10
|
-
}) => {
|
|
11
|
-
try {
|
|
12
|
-
const hookRunners = api.useHookRunners();
|
|
13
|
-
await hookRunners.beforeCreateCompiler({
|
|
14
|
-
webpackConfigs
|
|
15
|
-
});
|
|
16
|
-
const compiler = webpack(webpackConfigs);
|
|
17
|
-
await hookRunners.afterCreateCompiler({
|
|
18
|
-
compiler
|
|
19
|
-
});
|
|
20
|
-
let isFirstCompile = true;
|
|
21
|
-
compiler.hooks.invalid.tap('invalid', () => {
|
|
22
|
-
clearConsole();
|
|
23
|
-
logger.log('Compiling...');
|
|
24
|
-
});
|
|
25
|
-
compiler.hooks.done.tap('done', async stats => {
|
|
26
|
-
const statsData = stats.toJson({
|
|
27
|
-
preset: 'errors-warnings'
|
|
28
|
-
});
|
|
29
|
-
const {
|
|
30
|
-
errors,
|
|
31
|
-
warnings
|
|
32
|
-
} = formatWebpackMessages(statsData);
|
|
33
|
-
|
|
34
|
-
if (errors.length) {
|
|
35
|
-
logger.log(chalk.red(`Failed to compile.\n`));
|
|
36
|
-
logger.log(errors.join('\n\n'));
|
|
37
|
-
logger.log();
|
|
38
|
-
} else if (process.stdout.isTTY || isFirstCompile) {
|
|
39
|
-
await hookRunners.afterDev();
|
|
40
|
-
|
|
41
|
-
if (warnings.length) {
|
|
42
|
-
logger.log(chalk.yellow(`Compiled with warnings.\n`));
|
|
43
|
-
logger.log(warnings.join('\n\n'));
|
|
44
|
-
logger.log();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await printInstructions(hookRunners, appContext, userConfig);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
isFirstCompile = false;
|
|
51
|
-
});
|
|
52
|
-
return compiler;
|
|
53
|
-
} catch (err) {
|
|
54
|
-
logger.log(chalk.red(`Failed to compile.`));
|
|
55
|
-
logger.log();
|
|
56
|
-
logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
|
|
57
|
-
// eslint-disable-next-line no-process-exit
|
|
58
|
-
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getClientRoutes = void 0;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
|
-
var _makeLegalIdentifier = require("./makeLegalIdentifier");
|
|
13
|
-
|
|
14
|
-
var _constants = require("./constants");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
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; }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
|
-
const debug = (0, _utils.createDebugger)('get-client-routes');
|
|
25
|
-
|
|
26
|
-
const findLayout = dir => (0, _utils.findExists)(_constants.JS_EXTENSIONS.map(ext => _path.default.resolve(dir, `${_constants.FILE_SYSTEM_ROUTES_LAYOUT}${ext}`)));
|
|
27
|
-
|
|
28
|
-
const shouldSkip = file => {
|
|
29
|
-
// should not skip directory.
|
|
30
|
-
if (_utils.fs.statSync(file).isDirectory()) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const ext = _path.default.extname(file);
|
|
35
|
-
|
|
36
|
-
if (_constants.FILE_SYSTEM_ROUTES_IGNORED_REGEX.test(file) || !_constants.JS_EXTENSIONS.includes(ext) || _constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT === _path.default.basename(file, ext)) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return false;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const replaceWithAlias = (base, filePath, alias) => (0, _utils.normalizeToPosixPath)(_path.default.join(alias, _path.default.relative(base, filePath)));
|
|
44
|
-
|
|
45
|
-
const compName = (srcDirectory, filePath) => {
|
|
46
|
-
const legalCompName = (0, _makeLegalIdentifier.makeLegalIdentifier)(_path.default.relative(srcDirectory, filePath));
|
|
47
|
-
return `Comp_${legalCompName}`;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const layoutNameAbbr = filePath => {
|
|
51
|
-
const prefix = 'L_';
|
|
52
|
-
const dirName = _path.default.dirname(filePath).split('/').pop() || '';
|
|
53
|
-
return `${prefix}${(0, _makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const parents = [];
|
|
57
|
-
/* eslint-disable no-param-reassign */
|
|
58
|
-
|
|
59
|
-
const recursiveReadDir = ({
|
|
60
|
-
dir,
|
|
61
|
-
routes,
|
|
62
|
-
basePath: _basePath = '/',
|
|
63
|
-
srcDirectory,
|
|
64
|
-
srcAlias
|
|
65
|
-
}) => {
|
|
66
|
-
let hasDynamicRoute = false;
|
|
67
|
-
let resetParent = false;
|
|
68
|
-
let parent = parents[parents.length - 1];
|
|
69
|
-
const layout = findLayout(dir);
|
|
70
|
-
|
|
71
|
-
if (layout) {
|
|
72
|
-
if (_basePath === '/') {
|
|
73
|
-
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
74
|
-
} else {
|
|
75
|
-
const alias = replaceWithAlias(srcDirectory, layout, srcAlias);
|
|
76
|
-
const componentName = compName(srcDirectory, layout);
|
|
77
|
-
const route = {
|
|
78
|
-
path: `${_basePath.substring(0, _basePath.length - 1)}`,
|
|
79
|
-
exact: false,
|
|
80
|
-
routes: [],
|
|
81
|
-
_component: alias,
|
|
82
|
-
component: componentName,
|
|
83
|
-
parent
|
|
84
|
-
};
|
|
85
|
-
parent = route;
|
|
86
|
-
resetParent = true;
|
|
87
|
-
routes.push(route);
|
|
88
|
-
parents.push(route);
|
|
89
|
-
routes = route.routes;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
for (const relative of _utils.fs.readdirSync(dir)) {
|
|
94
|
-
const filePath = _path.default.join(dir, relative);
|
|
95
|
-
|
|
96
|
-
if (!shouldSkip(filePath)) {
|
|
97
|
-
const filename = _path.default.basename(filePath, _path.default.extname(filePath));
|
|
98
|
-
|
|
99
|
-
const alias = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
|
100
|
-
const componentName = compName(srcDirectory, filePath);
|
|
101
|
-
|
|
102
|
-
const dynamicRouteMatched = _constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
103
|
-
|
|
104
|
-
if (dynamicRouteMatched) {
|
|
105
|
-
if (hasDynamicRoute) {
|
|
106
|
-
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
107
|
-
} else {
|
|
108
|
-
hasDynamicRoute = true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const route = {
|
|
113
|
-
path: `${_basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
114
|
-
_component: alias,
|
|
115
|
-
component: componentName,
|
|
116
|
-
exact: true,
|
|
117
|
-
parent
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
if (_utils.fs.statSync(filePath).isDirectory()) {
|
|
121
|
-
recursiveReadDir({
|
|
122
|
-
dir: filePath,
|
|
123
|
-
routes,
|
|
124
|
-
basePath: `${route.path}/`,
|
|
125
|
-
srcDirectory,
|
|
126
|
-
srcAlias
|
|
127
|
-
});
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (filename === _constants.FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (filename === _constants.FILE_SYSTEM_ROUTES_INDEX) {
|
|
136
|
-
route.path = _basePath === '/' ? _basePath : `${_basePath.substring(0, _basePath.length - 1)}`;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (filename === '404' && _basePath === '/') {
|
|
140
|
-
route.path = '*';
|
|
141
|
-
route.exact = false;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
routes.push(route);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (resetParent) {
|
|
149
|
-
parents.pop();
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
/* eslint-enable no-param-reassign */
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
156
|
-
const flat = routes => routes.reduce((memo, route) => memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [route]), []);
|
|
157
|
-
|
|
158
|
-
const generate = route => {
|
|
159
|
-
const codes = [];
|
|
160
|
-
let lastComponent = route.component;
|
|
161
|
-
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`]; // eslint-disable-next-line no-param-reassign, no-cond-assign
|
|
162
|
-
|
|
163
|
-
while (route = route.parent) {
|
|
164
|
-
const layoutComponent = route.component;
|
|
165
|
-
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
166
|
-
imports.push(`import ${layoutComponent} from '${route._component}';`);
|
|
167
|
-
const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
|
|
168
|
-
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
169
|
-
lastComponent = currentComponent;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const file = _path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
173
|
-
|
|
174
|
-
_utils.fs.outputFileSync(file, `${imports.join('\n')}\n${codes.join('\n')}\nexport default ${lastComponent}`);
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
component: lastComponent,
|
|
178
|
-
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const normalized = flat(nested).map(route => route.parent ? _objectSpread(_objectSpread(_objectSpread({}, route), generate(route)), {}, {
|
|
183
|
-
parent: undefined
|
|
184
|
-
}) : _objectSpread(_objectSpread({}, route), {}, {
|
|
185
|
-
parent: undefined
|
|
186
|
-
}));
|
|
187
|
-
return normalized;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const getRouteWeight = route => route === '*' ? 999 : route.split(':').length - 1;
|
|
191
|
-
|
|
192
|
-
const getClientRoutes = ({
|
|
193
|
-
entrypoint,
|
|
194
|
-
srcDirectory,
|
|
195
|
-
srcAlias,
|
|
196
|
-
internalDirectory,
|
|
197
|
-
internalDirAlias
|
|
198
|
-
}) => {
|
|
199
|
-
const {
|
|
200
|
-
entry,
|
|
201
|
-
entryName
|
|
202
|
-
} = entrypoint;
|
|
203
|
-
|
|
204
|
-
if (!_utils.fs.existsSync(entry)) {
|
|
205
|
-
throw new Error(`generate file system routes error, ${entry} directory not found.`);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (!(_utils.fs.existsSync(entry) && _utils.fs.statSync(entry).isDirectory())) {
|
|
209
|
-
throw new Error(`generate file system routes error, ${entry} should be directory.`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
let routes = [];
|
|
213
|
-
recursiveReadDir({
|
|
214
|
-
dir: entry,
|
|
215
|
-
routes,
|
|
216
|
-
basePath: '/',
|
|
217
|
-
srcDirectory,
|
|
218
|
-
srcAlias
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const internalComponentsDir = _path.default.resolve(internalDirectory, `${entryName}/${_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
222
|
-
|
|
223
|
-
_utils.fs.emptyDirSync(internalComponentsDir);
|
|
224
|
-
|
|
225
|
-
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
226
|
-
parents.length = 0; // FIXME: support more situations
|
|
227
|
-
|
|
228
|
-
routes.sort((a, b) => {
|
|
229
|
-
const delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
|
230
|
-
|
|
231
|
-
if (delta === 0) {
|
|
232
|
-
return a.path.length - b.path.length;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return delta;
|
|
236
|
-
});
|
|
237
|
-
debug(`fileSystem routes: %o`, routes);
|
|
238
|
-
return routes;
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
exports.getClientRoutes = getClientRoutes;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.start = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
|
-
var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
|
|
11
|
-
|
|
12
|
-
var _printInstructions = require("../utils/printInstructions");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
const start = async api => {
|
|
17
|
-
var _userConfig$source;
|
|
18
|
-
|
|
19
|
-
const appContext = api.useAppContext();
|
|
20
|
-
const userConfig = api.useResolvedConfigContext();
|
|
21
|
-
const hookRunners = api.useHookRunners();
|
|
22
|
-
const {
|
|
23
|
-
appDirectory,
|
|
24
|
-
port,
|
|
25
|
-
serverConfigFile
|
|
26
|
-
} = appContext;
|
|
27
|
-
|
|
28
|
-
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
|
29
|
-
|
|
30
|
-
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
|
|
31
|
-
const app = await (0, _prodServer.default)({
|
|
32
|
-
pwd: appDirectory,
|
|
33
|
-
config: userConfig,
|
|
34
|
-
plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
|
|
35
|
-
serverConfigFile,
|
|
36
|
-
apiOnly
|
|
37
|
-
});
|
|
38
|
-
app.listen(port, async err => {
|
|
39
|
-
if (err) {
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
exports.start = start;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createCompiler = void 0;
|
|
7
|
-
|
|
8
|
-
var _webpack = require("@modern-js/webpack");
|
|
9
|
-
|
|
10
|
-
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
|
-
var _printInstructions = require("./printInstructions");
|
|
13
|
-
|
|
14
|
-
const createCompiler = async ({
|
|
15
|
-
api,
|
|
16
|
-
webpackConfigs,
|
|
17
|
-
// TODO: params
|
|
18
|
-
userConfig,
|
|
19
|
-
appContext
|
|
20
|
-
}) => {
|
|
21
|
-
try {
|
|
22
|
-
const hookRunners = api.useHookRunners();
|
|
23
|
-
await hookRunners.beforeCreateCompiler({
|
|
24
|
-
webpackConfigs
|
|
25
|
-
});
|
|
26
|
-
const compiler = (0, _webpack.webpack)(webpackConfigs);
|
|
27
|
-
await hookRunners.afterCreateCompiler({
|
|
28
|
-
compiler
|
|
29
|
-
});
|
|
30
|
-
let isFirstCompile = true;
|
|
31
|
-
compiler.hooks.invalid.tap('invalid', () => {
|
|
32
|
-
(0, _utils.clearConsole)();
|
|
33
|
-
|
|
34
|
-
_utils.logger.log('Compiling...');
|
|
35
|
-
});
|
|
36
|
-
compiler.hooks.done.tap('done', async stats => {
|
|
37
|
-
const statsData = stats.toJson({
|
|
38
|
-
preset: 'errors-warnings'
|
|
39
|
-
});
|
|
40
|
-
const {
|
|
41
|
-
errors,
|
|
42
|
-
warnings
|
|
43
|
-
} = (0, _utils.formatWebpackMessages)(statsData);
|
|
44
|
-
|
|
45
|
-
if (errors.length) {
|
|
46
|
-
_utils.logger.log(_utils.chalk.red(`Failed to compile.\n`));
|
|
47
|
-
|
|
48
|
-
_utils.logger.log(errors.join('\n\n'));
|
|
49
|
-
|
|
50
|
-
_utils.logger.log();
|
|
51
|
-
} else if (process.stdout.isTTY || isFirstCompile) {
|
|
52
|
-
await hookRunners.afterDev();
|
|
53
|
-
|
|
54
|
-
if (warnings.length) {
|
|
55
|
-
_utils.logger.log(_utils.chalk.yellow(`Compiled with warnings.\n`));
|
|
56
|
-
|
|
57
|
-
_utils.logger.log(warnings.join('\n\n'));
|
|
58
|
-
|
|
59
|
-
_utils.logger.log();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
isFirstCompile = false;
|
|
66
|
-
});
|
|
67
|
-
return compiler;
|
|
68
|
-
} catch (err) {
|
|
69
|
-
_utils.logger.log(_utils.chalk.red(`Failed to compile.`));
|
|
70
|
-
|
|
71
|
-
_utils.logger.log();
|
|
72
|
-
|
|
73
|
-
_utils.logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
|
|
74
|
-
// eslint-disable-next-line no-process-exit
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
exports.createCompiler = createCompiler;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { webpack, Configuration } from '@modern-js/webpack';
|
|
2
|
-
import type { IAppContext, NormalizedConfig, PluginAPI } from '@modern-js/core';
|
|
3
|
-
export declare const createCompiler: ({
|
|
4
|
-
api,
|
|
5
|
-
webpackConfigs,
|
|
6
|
-
userConfig,
|
|
7
|
-
appContext
|
|
8
|
-
}: {
|
|
9
|
-
api: PluginAPI;
|
|
10
|
-
webpackConfigs: Configuration[];
|
|
11
|
-
userConfig: NormalizedConfig;
|
|
12
|
-
appContext: IAppContext;
|
|
13
|
-
}) => Promise<webpack.MultiCompiler>;
|