@modern-js/app-tools 1.21.3 → 2.0.0-beta.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 +138 -16
- package/dist/js/modern/analyze/constants.js +1 -0
- package/dist/js/modern/analyze/generateCode.js +118 -16
- package/dist/js/modern/analyze/getBundleEntry.js +3 -2
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +198 -0
- package/dist/js/modern/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +8 -28
- package/dist/js/modern/analyze/getClientRoutes/index.js +2 -0
- package/dist/js/modern/analyze/getClientRoutes/utils.js +21 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +31 -12
- package/dist/js/modern/analyze/index.js +2 -1
- package/dist/js/modern/analyze/nestedRoutes.js +127 -0
- package/dist/js/modern/analyze/templates.js +164 -10
- package/dist/js/modern/analyze/utils.js +2 -1
- package/dist/js/modern/builder/builderPlugins/compatModern.js +226 -0
- package/dist/js/modern/builder/createHtmlConfig.js +58 -0
- package/dist/js/modern/builder/createOutputConfig.js +67 -0
- package/dist/js/modern/builder/createSourceConfig.js +85 -0
- package/dist/js/modern/builder/createToolsConfig.js +94 -0
- package/dist/js/modern/builder/index.js +106 -0
- package/dist/js/modern/builder/share.js +48 -0
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +37 -0
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +44 -0
- package/dist/js/modern/commands/build.js +41 -95
- package/dist/js/modern/commands/dev.js +15 -19
- package/dist/js/modern/commands/inspect.js +17 -58
- package/dist/js/modern/commands/start.js +2 -1
- package/dist/js/modern/index.js +14 -4
- package/dist/js/modern/locale/en.js +0 -1
- package/dist/js/modern/locale/zh.js +0 -1
- package/dist/js/modern/utils/commands.js +5 -0
- package/dist/js/modern/utils/createCompiler.js +37 -40
- package/dist/js/modern/utils/createServer.js +16 -0
- package/dist/js/modern/utils/printInstructions.js +1 -1
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/generateCode.js +121 -14
- package/dist/js/node/analyze/getBundleEntry.js +3 -2
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +221 -0
- package/dist/js/node/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +16 -35
- package/dist/js/node/analyze/getClientRoutes/index.js +21 -0
- package/dist/js/node/analyze/getClientRoutes/utils.js +42 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +30 -11
- package/dist/js/node/analyze/index.js +2 -1
- package/dist/js/node/analyze/nestedRoutes.js +144 -0
- package/dist/js/node/analyze/templates.js +167 -10
- package/dist/js/node/analyze/utils.js +6 -2
- package/dist/js/node/builder/builderPlugins/compatModern.js +245 -0
- package/dist/js/node/builder/createHtmlConfig.js +76 -0
- package/dist/js/node/builder/createOutputConfig.js +75 -0
- package/dist/js/node/builder/createSourceConfig.js +99 -0
- package/dist/js/node/builder/createToolsConfig.js +103 -0
- package/dist/js/node/builder/index.js +129 -0
- package/dist/js/node/builder/share.js +63 -0
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +46 -0
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +53 -0
- package/dist/js/node/commands/build.js +44 -98
- package/dist/js/node/commands/dev.js +13 -23
- package/dist/js/node/commands/inspect.js +18 -74
- package/dist/js/node/commands/start.js +3 -1
- package/dist/js/node/index.js +19 -2
- package/dist/js/node/locale/en.js +0 -1
- package/dist/js/node/locale/zh.js +0 -1
- package/dist/js/node/utils/commands.js +14 -0
- package/dist/js/node/utils/createCompiler.js +43 -49
- package/dist/js/node/utils/createServer.js +21 -2
- package/dist/js/node/utils/printInstructions.js +1 -1
- package/dist/js/treeshaking/analyze/constants.js +16 -0
- package/dist/js/treeshaking/analyze/generateCode.js +412 -0
- package/dist/js/treeshaking/analyze/getBundleEntry.js +77 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +210 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +211 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +2 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +27 -0
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +109 -0
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +153 -0
- package/dist/js/treeshaking/analyze/getServerRoutes.js +170 -0
- package/dist/js/treeshaking/analyze/index.js +214 -0
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +18 -0
- package/dist/js/treeshaking/analyze/nestedRoutes.js +207 -0
- package/dist/js/treeshaking/analyze/templates.js +189 -0
- package/dist/js/treeshaking/analyze/utils.js +95 -0
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +231 -0
- package/dist/js/treeshaking/builder/createHtmlConfig.js +59 -0
- package/dist/js/treeshaking/builder/createOutputConfig.js +67 -0
- package/dist/js/treeshaking/builder/createSourceConfig.js +100 -0
- package/dist/js/treeshaking/builder/createToolsConfig.js +90 -0
- package/dist/js/treeshaking/builder/index.js +172 -0
- package/dist/js/treeshaking/builder/share.js +50 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +58 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +53 -0
- package/dist/js/treeshaking/commands/build.js +168 -0
- package/dist/js/treeshaking/commands/deploy.js +29 -0
- package/dist/js/treeshaking/commands/dev.js +146 -0
- package/dist/js/treeshaking/commands/index.js +3 -0
- package/dist/js/treeshaking/commands/inspect.js +52 -0
- package/dist/js/treeshaking/commands/start.js +78 -0
- package/dist/js/treeshaking/exports/server.js +1 -0
- package/dist/js/treeshaking/hooks.js +21 -0
- package/dist/js/treeshaking/index.js +304 -0
- package/dist/js/treeshaking/locale/en.js +34 -0
- package/dist/js/treeshaking/locale/index.js +9 -0
- package/dist/js/treeshaking/locale/zh.js +34 -0
- package/dist/js/treeshaking/utils/commands.js +5 -0
- package/dist/js/treeshaking/utils/config.js +140 -0
- package/dist/js/treeshaking/utils/createCompiler.js +117 -0
- package/dist/js/treeshaking/utils/createServer.js +83 -0
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +68 -0
- package/dist/js/treeshaking/utils/language.js +5 -0
- package/dist/js/treeshaking/utils/printInstructions.js +35 -0
- package/dist/js/treeshaking/utils/routes.js +33 -0
- package/dist/js/treeshaking/utils/types.js +0 -0
- package/dist/types/analyze/constants.d.ts +1 -0
- package/dist/types/analyze/generateCode.d.ts +1 -1
- 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/index.d.ts +2 -2
- package/dist/types/analyze/nestedRoutes.d.ts +5 -0
- package/dist/types/analyze/templates.d.ts +17 -3
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +14 -0
- package/dist/types/builder/createHtmlConfig.d.ts +6 -0
- package/dist/types/builder/createOutputConfig.d.ts +3 -0
- package/dist/types/builder/createSourceConfig.d.ts +5 -0
- package/dist/types/builder/createToolsConfig.d.ts +13 -0
- package/dist/types/builder/index.d.ts +19 -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/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/inspect.d.ts +5 -6
- package/dist/types/commands/start.d.ts +2 -1
- package/dist/types/hooks.d.ts +15 -10
- package/dist/types/index.d.ts +4 -2
- package/dist/types/locale/en.d.ts +0 -1
- package/dist/types/locale/index.d.ts +0 -2
- package/dist/types/locale/zh.d.ts +0 -1
- package/dist/types/utils/commands.d.ts +1 -0
- package/dist/types/utils/createCompiler.d.ts +9 -10
- package/dist/types/utils/createServer.d.ts +8 -1
- package/dist/types/utils/printInstructions.d.ts +3 -2
- package/dist/types/utils/types.d.ts +2 -3
- package/package.json +25 -43
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
5
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { fs, logger } from '@modern-js/utils';
|
|
8
|
+
import { useResolvedConfigContext } from '@modern-js/core';
|
|
9
|
+
import esbuild from 'esbuild';
|
|
10
|
+
import { getCommand } from "../utils/commands";
|
|
11
|
+
import * as templates from "./templates";
|
|
12
|
+
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
13
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
14
|
+
import { getDefaultImports } from "./utils";
|
|
15
|
+
import { walk } from "./nestedRoutes";
|
|
16
|
+
|
|
17
|
+
var createImportSpecifier = function createImportSpecifier(specifiers) {
|
|
18
|
+
var defaults = '';
|
|
19
|
+
var named = [];
|
|
20
|
+
|
|
21
|
+
var _iterator = _createForOfIteratorHelper(specifiers),
|
|
22
|
+
_step;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
26
|
+
var _step$value = _step.value,
|
|
27
|
+
local = _step$value.local,
|
|
28
|
+
imported = _step$value.imported;
|
|
29
|
+
|
|
30
|
+
if (local && imported) {
|
|
31
|
+
named.push("".concat(imported, " as ").concat(local));
|
|
32
|
+
} else if (local) {
|
|
33
|
+
defaults = local;
|
|
34
|
+
} else {
|
|
35
|
+
named.push(imported);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch (err) {
|
|
39
|
+
_iterator.e(err);
|
|
40
|
+
} finally {
|
|
41
|
+
_iterator.f();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (defaults && named.length) {
|
|
45
|
+
return "".concat(defaults, ", { ").concat(named.join(', '), " }");
|
|
46
|
+
} else if (defaults) {
|
|
47
|
+
return defaults;
|
|
48
|
+
} else {
|
|
49
|
+
return "{ ".concat(named.join(', '), " }");
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export var createImportStatements = function createImportStatements(statements) {
|
|
54
|
+
// merge import statements with the same value.
|
|
55
|
+
var deDuplicated = [];
|
|
56
|
+
var seen = new Map();
|
|
57
|
+
|
|
58
|
+
var _iterator2 = _createForOfIteratorHelper(statements),
|
|
59
|
+
_step2;
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
var _loop = function _loop() {
|
|
63
|
+
var _step2$value = _step2.value,
|
|
64
|
+
value = _step2$value.value,
|
|
65
|
+
specifiers = _step2$value.specifiers,
|
|
66
|
+
initialize = _step2$value.initialize;
|
|
67
|
+
|
|
68
|
+
if (!seen.has(value)) {
|
|
69
|
+
deDuplicated.push({
|
|
70
|
+
value: value,
|
|
71
|
+
specifiers: specifiers,
|
|
72
|
+
initialize: initialize
|
|
73
|
+
});
|
|
74
|
+
seen.set(value, specifiers);
|
|
75
|
+
} else {
|
|
76
|
+
var _seen$get, _deDuplicated$modifyI, _deDuplicated$modifyI2;
|
|
77
|
+
|
|
78
|
+
(_seen$get = seen.get(value)).push.apply(_seen$get, _toConsumableArray(specifiers)); // make "initialize" param can be connected when multiple plugins were imported from same package
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
var modifyIndex = deDuplicated.findIndex(function (v) {
|
|
82
|
+
return v.value === value;
|
|
83
|
+
});
|
|
84
|
+
var originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
|
|
85
|
+
deDuplicated[modifyIndex].initialize = originInitialize.concat("\n".concat(initialize || ''));
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
90
|
+
_loop();
|
|
91
|
+
}
|
|
92
|
+
} catch (err) {
|
|
93
|
+
_iterator2.e(err);
|
|
94
|
+
} finally {
|
|
95
|
+
_iterator2.f();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return deDuplicated.map(function (_ref) {
|
|
99
|
+
var value = _ref.value,
|
|
100
|
+
specifiers = _ref.specifiers,
|
|
101
|
+
initialize = _ref.initialize;
|
|
102
|
+
return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || '');
|
|
103
|
+
}).join('\n');
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var buildLoader = /*#__PURE__*/function () {
|
|
107
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(entry, outfile) {
|
|
108
|
+
var loader, EXTERNAL_REGEXP, command;
|
|
109
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
110
|
+
while (1) {
|
|
111
|
+
switch (_context.prev = _context.next) {
|
|
112
|
+
case 0:
|
|
113
|
+
loader = {
|
|
114
|
+
'.js': 'jsx',
|
|
115
|
+
'.ts': 'tsx'
|
|
116
|
+
};
|
|
117
|
+
EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
118
|
+
command = getCommand();
|
|
119
|
+
_context.next = 5;
|
|
120
|
+
return esbuild.build({
|
|
121
|
+
format: 'cjs',
|
|
122
|
+
platform: 'node',
|
|
123
|
+
target: 'esnext',
|
|
124
|
+
loader: loader,
|
|
125
|
+
watch: command === 'dev' && {},
|
|
126
|
+
bundle: true,
|
|
127
|
+
logLevel: 'error',
|
|
128
|
+
entryPoints: [entry],
|
|
129
|
+
outfile: outfile,
|
|
130
|
+
plugins: [{
|
|
131
|
+
name: 'make-all-packages-external',
|
|
132
|
+
setup: function setup(build) {
|
|
133
|
+
// https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
|
|
134
|
+
build.onResolve({
|
|
135
|
+
filter: EXTERNAL_REGEXP
|
|
136
|
+
}, function (args) {
|
|
137
|
+
var external = true; // FIXME: windows external entrypoint
|
|
138
|
+
|
|
139
|
+
if (args.kind === 'entry-point') {
|
|
140
|
+
external = false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
path: args.path,
|
|
145
|
+
external: external
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}]
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
case 5:
|
|
153
|
+
case "end":
|
|
154
|
+
return _context.stop();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}, _callee);
|
|
158
|
+
}));
|
|
159
|
+
|
|
160
|
+
return function buildLoader(_x, _x2) {
|
|
161
|
+
return _ref2.apply(this, arguments);
|
|
162
|
+
};
|
|
163
|
+
}();
|
|
164
|
+
|
|
165
|
+
export var generateCode = /*#__PURE__*/function () {
|
|
166
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(appContext, config, entrypoints, api) {
|
|
167
|
+
var _config$runtime, _config$runtime$route;
|
|
168
|
+
|
|
169
|
+
var internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, hookRunners, islegacy, mountId, getRoutes, generateEntryCode, _generateEntryCode;
|
|
170
|
+
|
|
171
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
172
|
+
while (1) {
|
|
173
|
+
switch (_context3.prev = _context3.next) {
|
|
174
|
+
case 0:
|
|
175
|
+
_generateEntryCode = function _generateEntryCode3() {
|
|
176
|
+
_generateEntryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(entrypoint) {
|
|
177
|
+
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, _yield$hookRunners$mo, routes, _config, ssr, mode, _yield$hookRunners$be, _code, routesServerFile, outputRoutesServerFile, _code2, _yield$hookRunners$mo2, importStatements, _yield$hookRunners$mo3, plugins, _yield$hookRunners$mo4, renderFunction, _yield$hookRunners$mo5, exportStatement, code, entryFile, _yield$hookRunners$mo6, asyncEntryCode, bootstrapFile;
|
|
178
|
+
|
|
179
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
180
|
+
while (1) {
|
|
181
|
+
switch (_context2.prev = _context2.next) {
|
|
182
|
+
case 0:
|
|
183
|
+
entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
184
|
+
|
|
185
|
+
if (!isAutoMount) {
|
|
186
|
+
_context2.next = 68;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!fileSystemRoutes) {
|
|
191
|
+
_context2.next = 38;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
initialRoutes = [];
|
|
196
|
+
nestedRoute = null;
|
|
197
|
+
|
|
198
|
+
if (entrypoint.entry) {
|
|
199
|
+
initialRoutes = getRoutes({
|
|
200
|
+
entrypoint: entrypoint,
|
|
201
|
+
srcDirectory: srcDirectory,
|
|
202
|
+
srcAlias: internalSrcAlias,
|
|
203
|
+
internalDirectory: internalDirectory,
|
|
204
|
+
internalDirAlias: internalDirAlias
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!entrypoint.nestedRoutesEntry) {
|
|
209
|
+
_context2.next = 16;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (islegacy) {
|
|
214
|
+
_context2.next = 14;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
_context2.next = 10;
|
|
219
|
+
return walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
220
|
+
name: internalSrcAlias,
|
|
221
|
+
basename: srcDirectory
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
case 10:
|
|
225
|
+
nestedRoute = _context2.sent;
|
|
226
|
+
|
|
227
|
+
if (nestedRoute) {
|
|
228
|
+
initialRoutes.unshift(nestedRoute);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
_context2.next = 16;
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
case 14:
|
|
235
|
+
logger.error('Nested routes is not supported in legacy mode.'); // eslint-disable-next-line no-process-exit
|
|
236
|
+
|
|
237
|
+
process.exit(1);
|
|
238
|
+
|
|
239
|
+
case 16:
|
|
240
|
+
_context2.next = 18;
|
|
241
|
+
return hookRunners.modifyFileSystemRoutes({
|
|
242
|
+
entrypoint: entrypoint,
|
|
243
|
+
routes: initialRoutes
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
case 18:
|
|
247
|
+
_yield$hookRunners$mo = _context2.sent;
|
|
248
|
+
routes = _yield$hookRunners$mo.routes;
|
|
249
|
+
_config = useResolvedConfigContext();
|
|
250
|
+
ssr = _config === null || _config === void 0 ? void 0 : _config.server.ssr;
|
|
251
|
+
|
|
252
|
+
if (ssr) {
|
|
253
|
+
mode = _typeof(ssr) === 'object' ? ssr.mode || 'string' : 'string';
|
|
254
|
+
} else {
|
|
255
|
+
mode = false;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
_context2.next = 25;
|
|
259
|
+
return hookRunners.beforeGenerateRoutes({
|
|
260
|
+
entrypoint: entrypoint,
|
|
261
|
+
code: templates.fileSystemRoutes({
|
|
262
|
+
routes: routes,
|
|
263
|
+
ssrMode: mode,
|
|
264
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry
|
|
265
|
+
})
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
case 25:
|
|
269
|
+
_yield$hookRunners$be = _context2.sent;
|
|
270
|
+
_code = _yield$hookRunners$be.code;
|
|
271
|
+
|
|
272
|
+
if (!entrypoint.nestedRoutesEntry) {
|
|
273
|
+
_context2.next = 37;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
routesServerFile = path.join(internalDirectory, entryName, 'routes.server.js');
|
|
278
|
+
outputRoutesServerFile = path.join(distDirectory, 'loader-routes', entryName, 'index.js');
|
|
279
|
+
_code2 = templates.routesForServer({
|
|
280
|
+
routes: routes,
|
|
281
|
+
alias: {
|
|
282
|
+
name: internalSrcAlias,
|
|
283
|
+
basename: srcDirectory
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
_context2.next = 33;
|
|
287
|
+
return fs.ensureFile(routesServerFile);
|
|
288
|
+
|
|
289
|
+
case 33:
|
|
290
|
+
_context2.next = 35;
|
|
291
|
+
return fs.writeFile(routesServerFile, _code2);
|
|
292
|
+
|
|
293
|
+
case 35:
|
|
294
|
+
_context2.next = 37;
|
|
295
|
+
return buildLoader(routesServerFile, outputRoutesServerFile);
|
|
296
|
+
|
|
297
|
+
case 37:
|
|
298
|
+
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), _code, 'utf8');
|
|
299
|
+
|
|
300
|
+
case 38:
|
|
301
|
+
_context2.next = 40;
|
|
302
|
+
return hookRunners.modifyEntryImports({
|
|
303
|
+
entrypoint: entrypoint,
|
|
304
|
+
imports: getDefaultImports({
|
|
305
|
+
entrypoint: entrypoint,
|
|
306
|
+
srcDirectory: srcDirectory,
|
|
307
|
+
internalSrcAlias: internalSrcAlias,
|
|
308
|
+
internalDirAlias: internalDirAlias,
|
|
309
|
+
internalDirectory: internalDirectory
|
|
310
|
+
})
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
case 40:
|
|
314
|
+
_yield$hookRunners$mo2 = _context2.sent;
|
|
315
|
+
importStatements = _yield$hookRunners$mo2.imports;
|
|
316
|
+
_context2.next = 44;
|
|
317
|
+
return hookRunners.modifyEntryRuntimePlugins({
|
|
318
|
+
entrypoint: entrypoint,
|
|
319
|
+
plugins: []
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
case 44:
|
|
323
|
+
_yield$hookRunners$mo3 = _context2.sent;
|
|
324
|
+
plugins = _yield$hookRunners$mo3.plugins;
|
|
325
|
+
_context2.next = 48;
|
|
326
|
+
return hookRunners.modifyEntryRenderFunction({
|
|
327
|
+
entrypoint: entrypoint,
|
|
328
|
+
code: templates.renderFunction({
|
|
329
|
+
plugins: plugins,
|
|
330
|
+
customBootstrap: customBootstrap,
|
|
331
|
+
fileSystemRoutes: fileSystemRoutes
|
|
332
|
+
})
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
case 48:
|
|
336
|
+
_yield$hookRunners$mo4 = _context2.sent;
|
|
337
|
+
renderFunction = _yield$hookRunners$mo4.code;
|
|
338
|
+
_context2.next = 52;
|
|
339
|
+
return hookRunners.modifyEntryExport({
|
|
340
|
+
entrypoint: entrypoint,
|
|
341
|
+
exportStatement: 'export default AppWrapper;'
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
case 52:
|
|
345
|
+
_yield$hookRunners$mo5 = _context2.sent;
|
|
346
|
+
exportStatement = _yield$hookRunners$mo5.exportStatement;
|
|
347
|
+
code = templates.index({
|
|
348
|
+
mountId: mountId,
|
|
349
|
+
imports: createImportStatements(importStatements),
|
|
350
|
+
renderFunction: renderFunction,
|
|
351
|
+
exportStatement: exportStatement
|
|
352
|
+
});
|
|
353
|
+
entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
|
|
354
|
+
entrypoint.entry = entryFile; // generate entry file.
|
|
355
|
+
|
|
356
|
+
if (!config.source.enableAsyncEntry) {
|
|
357
|
+
_context2.next = 67;
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
_context2.next = 60;
|
|
362
|
+
return hookRunners.modifyAsyncEntry({
|
|
363
|
+
entrypoint: entrypoint,
|
|
364
|
+
code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
case 60:
|
|
368
|
+
_yield$hookRunners$mo6 = _context2.sent;
|
|
369
|
+
asyncEntryCode = _yield$hookRunners$mo6.code;
|
|
370
|
+
fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
|
|
371
|
+
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
372
|
+
fs.outputFileSync(bootstrapFile, code, 'utf8');
|
|
373
|
+
_context2.next = 68;
|
|
374
|
+
break;
|
|
375
|
+
|
|
376
|
+
case 67:
|
|
377
|
+
fs.outputFileSync(entryFile, code, 'utf8');
|
|
378
|
+
|
|
379
|
+
case 68:
|
|
380
|
+
case "end":
|
|
381
|
+
return _context2.stop();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}, _callee2);
|
|
385
|
+
}));
|
|
386
|
+
return _generateEntryCode.apply(this, arguments);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
generateEntryCode = function _generateEntryCode2(_x7) {
|
|
390
|
+
return _generateEntryCode.apply(this, arguments);
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias;
|
|
394
|
+
hookRunners = api.useHookRunners();
|
|
395
|
+
islegacy = Boolean(config === null || config === void 0 ? void 0 : (_config$runtime = config.runtime) === null || _config$runtime === void 0 ? void 0 : (_config$runtime$route = _config$runtime.router) === null || _config$runtime$route === void 0 ? void 0 : _config$runtime$route.legacy);
|
|
396
|
+
mountId = config.output.mountId;
|
|
397
|
+
getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
|
|
398
|
+
_context3.next = 9;
|
|
399
|
+
return Promise.all(entrypoints.map(generateEntryCode));
|
|
400
|
+
|
|
401
|
+
case 9:
|
|
402
|
+
case "end":
|
|
403
|
+
return _context3.stop();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}, _callee3);
|
|
407
|
+
}));
|
|
408
|
+
|
|
409
|
+
return function generateCode(_x3, _x4, _x5, _x6) {
|
|
410
|
+
return _ref3.apply(this, arguments);
|
|
411
|
+
};
|
|
412
|
+
}();
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME } from '@modern-js/utils';
|
|
3
|
+
import { getFileSystemEntry } from "./getFileSystemEntry";
|
|
4
|
+
import { JS_EXTENSIONS } from "./constants";
|
|
5
|
+
|
|
6
|
+
var ensureExtensions = function ensureExtensions(file) {
|
|
7
|
+
if (!path.extname(file)) {
|
|
8
|
+
return findExists(JS_EXTENSIONS.map(function (ext) {
|
|
9
|
+
return "".concat(file).concat(ext);
|
|
10
|
+
})) || file;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return file;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
var ifAlreadyExists = function ifAlreadyExists(entrypoints, checked) {
|
|
17
|
+
return entrypoints.some(function (entrypoint) {
|
|
18
|
+
if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
|
|
19
|
+
// reset entryName
|
|
20
|
+
checked.entryName = entrypoint.entryName;
|
|
21
|
+
return true;
|
|
22
|
+
} // filesystem routes entrypoint conflict with normal entrypoint.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (entrypoint.entry.startsWith(checked.entry) || checked.entry.startsWith(entrypoint.entry)) {
|
|
26
|
+
throw new Error("Entry configuration conflicts\n Your configuration: ".concat(checked.entry, ".\n Default entrypoint: ").concat(entrypoint.entry, "\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules."));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return false;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export var getBundleEntry = function getBundleEntry(appContext, config) {
|
|
34
|
+
var appDirectory = appContext.appDirectory,
|
|
35
|
+
packageName = appContext.packageName;
|
|
36
|
+
var _config$source = config.source,
|
|
37
|
+
disableDefaultEntries = _config$source.disableDefaultEntries,
|
|
38
|
+
entries = _config$source.entries,
|
|
39
|
+
entriesDir = _config$source.entriesDir;
|
|
40
|
+
var defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config); // merge entrypoints from user config with directory convention.
|
|
41
|
+
|
|
42
|
+
if (entries) {
|
|
43
|
+
Object.keys(entries).forEach(function (name) {
|
|
44
|
+
var value = entries[name];
|
|
45
|
+
var entrypoint = typeof value === 'string' ? {
|
|
46
|
+
entryName: name,
|
|
47
|
+
entry: ensureAbsolutePath(appDirectory, value),
|
|
48
|
+
isAutoMount: true,
|
|
49
|
+
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value)).isDirectory() ? {} : undefined
|
|
50
|
+
} : {
|
|
51
|
+
entryName: name,
|
|
52
|
+
entry: ensureAbsolutePath(appDirectory, value.entry),
|
|
53
|
+
isAutoMount: !value.disableMount,
|
|
54
|
+
fileSystemRoutes: value.enableFileSystemRoutes ? {} : undefined
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
58
|
+
defaults.push(entrypoint);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!disableDefaultEntries) {
|
|
64
|
+
// find main entry point which server route is '/'.
|
|
65
|
+
var entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir);
|
|
66
|
+
var found = defaults.find(function (_ref) {
|
|
67
|
+
var entryName = _ref.entryName,
|
|
68
|
+
entry = _ref.entry,
|
|
69
|
+
_ref$nestedRoutesEntr = _ref.nestedRoutesEntry,
|
|
70
|
+
nestedRoutesEntry = _ref$nestedRoutesEntr === void 0 ? '' : _ref$nestedRoutesEntr;
|
|
71
|
+
return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
|
|
72
|
+
});
|
|
73
|
+
found && (found.entryName = MAIN_ENTRY_NAME);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return defaults;
|
|
77
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fs } from '@modern-js/utils';
|
|
5
|
+
import { makeLegalIdentifier } from "../makeLegalIdentifier";
|
|
6
|
+
import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT } from "../constants";
|
|
7
|
+
import { replaceWithAlias } from "../utils";
|
|
8
|
+
import { debug, findLayout, shouldSkip, getRouteWeight } from "./utils";
|
|
9
|
+
|
|
10
|
+
var compName = function compName(srcDirectory, filePath) {
|
|
11
|
+
var legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
|
12
|
+
return "Comp_".concat(legalCompName);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var layoutNameAbbr = function layoutNameAbbr(filePath) {
|
|
16
|
+
var prefix = 'L_';
|
|
17
|
+
var dirName = path.dirname(filePath).split('/').pop() || '';
|
|
18
|
+
return "".concat(prefix).concat(makeLegalIdentifier(dirName));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var parents = [];
|
|
22
|
+
/* eslint-disable no-param-reassign */
|
|
23
|
+
|
|
24
|
+
var recursiveReadDir = function recursiveReadDir(_ref) {
|
|
25
|
+
var dir = _ref.dir,
|
|
26
|
+
routes = _ref.routes,
|
|
27
|
+
_ref$basePath = _ref.basePath,
|
|
28
|
+
basePath = _ref$basePath === void 0 ? '/' : _ref$basePath,
|
|
29
|
+
srcDirectory = _ref.srcDirectory,
|
|
30
|
+
srcAlias = _ref.srcAlias;
|
|
31
|
+
var hasDynamicRoute = false;
|
|
32
|
+
var resetParent = false;
|
|
33
|
+
var parent = parents[parents.length - 1];
|
|
34
|
+
var layout = findLayout(dir);
|
|
35
|
+
|
|
36
|
+
if (layout) {
|
|
37
|
+
if (basePath === '/') {
|
|
38
|
+
throw new Error("should use _app instead of _layout in ".concat(dir));
|
|
39
|
+
} else {
|
|
40
|
+
var alias = replaceWithAlias(srcDirectory, layout, srcAlias);
|
|
41
|
+
var componentName = compName(srcDirectory, layout);
|
|
42
|
+
var route = {
|
|
43
|
+
path: "".concat(basePath.substring(0, basePath.length - 1)),
|
|
44
|
+
children: [],
|
|
45
|
+
_component: alias,
|
|
46
|
+
component: componentName,
|
|
47
|
+
parent: parent,
|
|
48
|
+
type: 'page'
|
|
49
|
+
};
|
|
50
|
+
parent = route;
|
|
51
|
+
resetParent = true;
|
|
52
|
+
routes.push(route);
|
|
53
|
+
parents.push(route);
|
|
54
|
+
routes = route.children;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
var _iterator = _createForOfIteratorHelper(fs.readdirSync(dir)),
|
|
59
|
+
_step;
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
63
|
+
var relative = _step.value;
|
|
64
|
+
var filePath = path.join(dir, relative);
|
|
65
|
+
|
|
66
|
+
if (!shouldSkip(filePath)) {
|
|
67
|
+
var filename = path.basename(filePath, path.extname(filePath));
|
|
68
|
+
|
|
69
|
+
var _alias = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
|
70
|
+
|
|
71
|
+
var _componentName = compName(srcDirectory, filePath);
|
|
72
|
+
|
|
73
|
+
var dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
74
|
+
|
|
75
|
+
if (dynamicRouteMatched) {
|
|
76
|
+
if (hasDynamicRoute) {
|
|
77
|
+
throw new Error("Can't set two dynamic route in one directory: ".concat(dir));
|
|
78
|
+
} else {
|
|
79
|
+
hasDynamicRoute = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
var _route = {
|
|
84
|
+
path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1]).concat(dynamicRouteMatched[2]) : filename),
|
|
85
|
+
_component: _alias,
|
|
86
|
+
component: _componentName,
|
|
87
|
+
parent: parent,
|
|
88
|
+
type: 'page'
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
92
|
+
recursiveReadDir({
|
|
93
|
+
dir: filePath,
|
|
94
|
+
routes: routes,
|
|
95
|
+
basePath: "".concat(_route.path, "/"),
|
|
96
|
+
srcDirectory: srcDirectory,
|
|
97
|
+
srcAlias: srcAlias
|
|
98
|
+
});
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (filename === FILE_SYSTEM_ROUTES_INDEX) {
|
|
107
|
+
_route.path = basePath === '/' ? basePath : "".concat(basePath.substring(0, basePath.length - 1));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (filename === '404' && basePath === '/') {
|
|
111
|
+
_route.path = '*';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
routes.push(_route);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
_iterator.e(err);
|
|
119
|
+
} finally {
|
|
120
|
+
_iterator.f();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (resetParent) {
|
|
124
|
+
parents.pop();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/* eslint-enable no-param-reassign */
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
var normalizeNestedRoutes = function normalizeNestedRoutes(nested, internalComponentsDir, internalDirectory, internalDirAlias) {
|
|
131
|
+
var flat = function flat(routes) {
|
|
132
|
+
return routes.reduce(function (memo, route) {
|
|
133
|
+
return memo.concat(Array.isArray(route.children) ? flat(route.children) : [route]);
|
|
134
|
+
}, []);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
var generate = function generate(route) {
|
|
138
|
+
var codes = [];
|
|
139
|
+
var lastComponent = route.component;
|
|
140
|
+
var imports = ["import React from 'react';", "import ".concat(lastComponent, " from '").concat(route._component, "'")]; // eslint-disable-next-line no-param-reassign, no-cond-assign
|
|
141
|
+
|
|
142
|
+
while (route = route.parent) {
|
|
143
|
+
var layoutComponent = route.component;
|
|
144
|
+
var layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
145
|
+
imports.push("import ".concat(layoutComponent, " from '").concat(route._component, "';"));
|
|
146
|
+
var currentComponent = "".concat(layoutComponentAbbr, "_").concat(lastComponent);
|
|
147
|
+
codes.push("const ".concat(currentComponent, " = props => <").concat(layoutComponent, " Component={").concat(lastComponent, "} {...props} />;"));
|
|
148
|
+
lastComponent = currentComponent;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var file = path.resolve(internalComponentsDir, "".concat(lastComponent, ".jsx"));
|
|
152
|
+
fs.outputFileSync(file, "".concat(imports.join('\n'), "\n").concat(codes.join('\n'), "\nexport default ").concat(lastComponent));
|
|
153
|
+
return {
|
|
154
|
+
component: lastComponent,
|
|
155
|
+
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
var normalized = flat(nested).map(function (route) {
|
|
160
|
+
return route.parent ? _objectSpread(_objectSpread(_objectSpread({}, route), generate(route)), {}, {
|
|
161
|
+
parent: undefined
|
|
162
|
+
}) : _objectSpread(_objectSpread({}, route), {}, {
|
|
163
|
+
parent: undefined
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
return normalized;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export var getClientRoutes = function getClientRoutes(_ref2) {
|
|
170
|
+
var entrypoint = _ref2.entrypoint,
|
|
171
|
+
srcDirectory = _ref2.srcDirectory,
|
|
172
|
+
srcAlias = _ref2.srcAlias,
|
|
173
|
+
internalDirectory = _ref2.internalDirectory,
|
|
174
|
+
internalDirAlias = _ref2.internalDirAlias;
|
|
175
|
+
var entry = entrypoint.entry,
|
|
176
|
+
entryName = entrypoint.entryName;
|
|
177
|
+
|
|
178
|
+
if (!fs.existsSync(entry)) {
|
|
179
|
+
throw new Error("generate file system routes error, ".concat(entry, " directory not found."));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!(fs.existsSync(entry) && fs.statSync(entry).isDirectory())) {
|
|
183
|
+
throw new Error("generate file system routes error, ".concat(entry, " should be directory."));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var routes = [];
|
|
187
|
+
recursiveReadDir({
|
|
188
|
+
dir: entry,
|
|
189
|
+
routes: routes,
|
|
190
|
+
basePath: '/',
|
|
191
|
+
srcDirectory: srcDirectory,
|
|
192
|
+
srcAlias: srcAlias
|
|
193
|
+
});
|
|
194
|
+
var internalComponentsDir = path.resolve(internalDirectory, "".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_COMPONENTS_DIR));
|
|
195
|
+
fs.emptyDirSync(internalComponentsDir);
|
|
196
|
+
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
197
|
+
parents.length = 0; // FIXME: support more situations
|
|
198
|
+
|
|
199
|
+
routes.sort(function (a, b) {
|
|
200
|
+
var delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
|
201
|
+
|
|
202
|
+
if (delta === 0) {
|
|
203
|
+
return a.path.length - b.path.length;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return delta;
|
|
207
|
+
});
|
|
208
|
+
debug("fileSystem routes: %o", routes);
|
|
209
|
+
return routes;
|
|
210
|
+
};
|