@module-federation/modern-js 0.0.0-next-20241017102355 → 0.0.0-next-20241018034800

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.
Files changed (115) hide show
  1. package/dist/cjs/cli/{routes/ast/index.js → constant.js} +6 -6
  2. package/dist/cjs/cli/index.js +2 -7
  3. package/dist/cjs/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +6 -6
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
  5. package/dist/cjs/{runtime/withMFRouteId.js → cli/mfRuntimePlugins/shared-strategy.js} +23 -11
  6. package/dist/cjs/cli/ssrPlugin.js +2 -5
  7. package/dist/cjs/cli/utils.js +6 -11
  8. package/dist/cjs/cli/utils.spec.js +6 -5
  9. package/dist/cjs/constant.js +2 -35
  10. package/dist/cjs/runtime/index.js +1 -4
  11. package/dist/cjs/ssr-runtime/plugin.js +8 -7
  12. package/dist/esm/cli/constant.js +4 -0
  13. package/dist/esm/cli/index.js +2 -7
  14. package/dist/esm/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
  15. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
  16. package/dist/esm/cli/ssrPlugin.js +3 -6
  17. package/dist/esm/cli/utils.js +5 -9
  18. package/dist/esm/cli/utils.spec.js +6 -5
  19. package/dist/esm/constant.js +1 -23
  20. package/dist/esm/runtime/index.js +1 -3
  21. package/dist/esm/ssr-runtime/plugin.js +11 -8
  22. package/dist/esm-node/cli/constant.js +4 -0
  23. package/dist/esm-node/cli/index.js +2 -7
  24. package/dist/esm-node/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
  25. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
  26. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
  27. package/dist/esm-node/cli/ssrPlugin.js +2 -5
  28. package/dist/esm-node/cli/utils.js +5 -9
  29. package/dist/esm-node/cli/utils.spec.js +6 -5
  30. package/dist/esm-node/constant.js +1 -23
  31. package/dist/esm-node/runtime/index.js +1 -3
  32. package/dist/esm-node/ssr-runtime/plugin.js +8 -7
  33. package/dist/types/cli/constant.d.ts +1 -0
  34. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  35. package/dist/types/cli/utils.d.ts +0 -2
  36. package/dist/types/constant.d.ts +0 -11
  37. package/dist/types/runtime/index.d.ts +0 -1
  38. package/dist/types/ssr-runtime/plugin.d.ts +1 -3
  39. package/dist/types/types/index.d.ts +1 -3
  40. package/package.json +12 -49
  41. package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -41
  42. package/dist/cjs/cli/routes/ast/constant.js +0 -49
  43. package/dist/cjs/cli/routes/ast/generateRoutes.js +0 -143
  44. package/dist/cjs/cli/routes/clearMFCache.js +0 -57
  45. package/dist/cjs/cli/routes/exportRoutePlugin.js +0 -77
  46. package/dist/cjs/cli/routes/importRoutesPlugin.js +0 -120
  47. package/dist/cjs/cli/routes/plugin.js +0 -157
  48. package/dist/cjs/cli/routes/traverseRouteFiles.js +0 -148
  49. package/dist/cjs/cli/routes/utils.js +0 -168
  50. package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -72
  51. package/dist/cjs/cli/server/fetchRoutePlugin.js +0 -81
  52. package/dist/cjs/interfaces/route.js +0 -16
  53. package/dist/cjs/runtime/routes/plugin-inject-assets.js +0 -92
  54. package/dist/cjs/runtime/routes/plugin.js +0 -75
  55. package/dist/cjs/runtime/routes/utils.js +0 -115
  56. package/dist/cjs/types/modern.js +0 -16
  57. package/dist/cjs/types/routes.js +0 -16
  58. package/dist/esm/cli/mfRuntimePlugins/node.js +0 -13
  59. package/dist/esm/cli/routes/ast/constant.js +0 -18
  60. package/dist/esm/cli/routes/ast/generateRoutes.js +0 -110
  61. package/dist/esm/cli/routes/ast/index.js +0 -4
  62. package/dist/esm/cli/routes/clearMFCache.js +0 -34
  63. package/dist/esm/cli/routes/exportRoutePlugin.js +0 -79
  64. package/dist/esm/cli/routes/importRoutesPlugin.js +0 -122
  65. package/dist/esm/cli/routes/plugin.js +0 -266
  66. package/dist/esm/cli/routes/traverseRouteFiles.js +0 -313
  67. package/dist/esm/cli/routes/utils.js +0 -130
  68. package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -93
  69. package/dist/esm/cli/server/fetchRoutePlugin.js +0 -104
  70. package/dist/esm/interfaces/route.js +0 -0
  71. package/dist/esm/runtime/routes/plugin-inject-assets.js +0 -71
  72. package/dist/esm/runtime/routes/plugin.js +0 -97
  73. package/dist/esm/runtime/routes/utils.js +0 -86
  74. package/dist/esm/runtime/withMFRouteId.js +0 -7
  75. package/dist/esm/types/modern.js +0 -0
  76. package/dist/esm/types/routes.js +0 -0
  77. package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -11
  78. package/dist/esm-node/cli/routes/ast/constant.js +0 -18
  79. package/dist/esm-node/cli/routes/ast/generateRoutes.js +0 -109
  80. package/dist/esm-node/cli/routes/ast/index.js +0 -4
  81. package/dist/esm-node/cli/routes/clearMFCache.js +0 -33
  82. package/dist/esm-node/cli/routes/exportRoutePlugin.js +0 -53
  83. package/dist/esm-node/cli/routes/importRoutesPlugin.js +0 -96
  84. package/dist/esm-node/cli/routes/plugin.js +0 -123
  85. package/dist/esm-node/cli/routes/traverseRouteFiles.js +0 -113
  86. package/dist/esm-node/cli/routes/utils.js +0 -133
  87. package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -47
  88. package/dist/esm-node/cli/server/fetchRoutePlugin.js +0 -61
  89. package/dist/esm-node/interfaces/route.js +0 -0
  90. package/dist/esm-node/runtime/routes/plugin-inject-assets.js +0 -68
  91. package/dist/esm-node/runtime/routes/plugin.js +0 -51
  92. package/dist/esm-node/runtime/routes/utils.js +0 -86
  93. package/dist/esm-node/runtime/withMFRouteId.js +0 -7
  94. package/dist/esm-node/types/modern.js +0 -0
  95. package/dist/esm-node/types/routes.js +0 -0
  96. package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
  97. package/dist/types/cli/routes/ast/constant.d.ts +0 -8
  98. package/dist/types/cli/routes/ast/generateRoutes.d.ts +0 -5
  99. package/dist/types/cli/routes/ast/index.d.ts +0 -1
  100. package/dist/types/cli/routes/clearMFCache.d.ts +0 -1
  101. package/dist/types/cli/routes/exportRoutePlugin.d.ts +0 -4
  102. package/dist/types/cli/routes/importRoutesPlugin.d.ts +0 -4
  103. package/dist/types/cli/routes/plugin.d.ts +0 -4
  104. package/dist/types/cli/routes/traverseRouteFiles.d.ts +0 -11
  105. package/dist/types/cli/routes/utils.d.ts +0 -11
  106. package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -11
  107. package/dist/types/cli/server/fetchRoutePlugin.d.ts +0 -10
  108. package/dist/types/interfaces/route.d.ts +0 -12
  109. package/dist/types/runtime/routes/plugin-inject-assets.d.ts +0 -4
  110. package/dist/types/runtime/routes/plugin.d.ts +0 -5
  111. package/dist/types/runtime/routes/utils.d.ts +0 -22
  112. package/dist/types/runtime/withMFRouteId.d.ts +0 -1
  113. package/dist/types/types/modern.d.ts +0 -12
  114. package/dist/types/types/routes.d.ts +0 -19
  115. /package/dist/types/cli/mfRuntimePlugins/{node-fetch.d.ts → inject-node-fetch.d.ts} +0 -0
@@ -1,266 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import path from "path";
5
- import { fs } from "@modern-js/utils";
6
- import { transformName2Prefix } from "../../runtime/routes/utils";
7
- import { META_NAME } from "../../constant";
8
- import { traverseRouteFiles } from "./traverseRouteFiles";
9
- import { moduleFederationExportRoutePlugin } from "./exportRoutePlugin";
10
- import { moduleFederationImportRoutePlugin } from "./importRoutesPlugin";
11
- import { addShared } from "./utils";
12
- import { DEFAULT_ENTRY, ROUTE_ID } from "../../constant";
13
- var moduleFederationRoutesPlugin = function(param) {
14
- var userConfig = param.userConfig, internalOptions = param.internalOptions, serverPlugin = param.serverPlugin, transformRuntimeOptions = param.transformRuntimeOptions;
15
- var entries = /* @__PURE__ */ new Set();
16
- var remotePathMap = {};
17
- var ssrByRouteIdsMap = {};
18
- var internalRoutesPluginOptions = {
19
- userConfig,
20
- internalOptions,
21
- entries,
22
- remotePathMap,
23
- ssrByRouteIdsMap,
24
- serverPlugin,
25
- transformRuntimeOptions
26
- };
27
- return {
28
- name: "@modern-js/plugin-module-federation-route",
29
- pre: [
30
- "@modern-js/plugin-module-federation-config"
31
- ],
32
- setup: function() {
33
- var _ref = _async_to_generator(function(param2) {
34
- var useAppContext, appContext, name, _internalOptions_metaName, metaName, internalDirectory, csrConfig, _ref2, scanEntries;
35
- return _ts_generator(this, function(_state) {
36
- switch (_state.label) {
37
- case 0:
38
- useAppContext = param2.useAppContext;
39
- if (!userConfig.exportRoutes && !userConfig.importRoutes) {
40
- return [
41
- 2
42
- ];
43
- }
44
- appContext = useAppContext();
45
- name = internalOptions.csrConfig.name;
46
- _internalOptions_metaName = internalOptions.metaName, metaName = _internalOptions_metaName === void 0 ? META_NAME : _internalOptions_metaName;
47
- internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
48
- csrConfig = internalOptions.csrConfig;
49
- if (!(_type_of(csrConfig.remotes) === "object" && Object.keys(csrConfig.remotes).length))
50
- return [
51
- 3,
52
- 2
53
- ];
54
- return [
55
- 4,
56
- traverseRouteFiles({
57
- appDirectory: appContext.appDirectory,
58
- generateRouteFile: userConfig.importRoutes,
59
- remotePathMap
60
- })
61
- ];
62
- case 1:
63
- _ref2 = _state.sent(), scanEntries = _ref2.entries;
64
- scanEntries.forEach(function(e) {
65
- return entries.add(e);
66
- });
67
- return [
68
- 3,
69
- 3
70
- ];
71
- case 2:
72
- entries.add(DEFAULT_ENTRY);
73
- _state.label = 3;
74
- case 3:
75
- return [
76
- 2,
77
- {
78
- config: /* @__PURE__ */ _async_to_generator(function() {
79
- return _ts_generator(this, function(_state2) {
80
- return [
81
- 2,
82
- {
83
- tools: {
84
- // bundlerChain can not keep target order
85
- rspack: function rspack(_config, param3) {
86
- var isServer = param3.isServer;
87
- addShared({
88
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
89
- metaName,
90
- isServer,
91
- internalDirectory,
92
- entries
93
- });
94
- },
95
- // bundlerChain can not keep target order
96
- webpack: function webpack(_config, param3) {
97
- var isServer = param3.isServer;
98
- addShared({
99
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
100
- metaName,
101
- isServer,
102
- internalDirectory,
103
- entries
104
- });
105
- }
106
- },
107
- source: {
108
- define: {
109
- MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
110
- }
111
- }
112
- }
113
- ];
114
- });
115
- }),
116
- modifyFileSystemRoutes: function modifyFileSystemRoutes(options) {
117
- return _async_to_generator(function() {
118
- var routes, entrypoint, entryName, prefix, modifyRouteIds;
119
- return _ts_generator(this, function(_state2) {
120
- switch (_state2.label) {
121
- case 0:
122
- routes = options.routes, entrypoint = options.entrypoint;
123
- entryName = entrypoint.entryName;
124
- prefix = transformName2Prefix(internalOptions.csrConfig.name);
125
- modifyRouteIds = function() {
126
- var _ref3 = _async_to_generator(function(route, pathName) {
127
- var currentPathName, originalId, remoteInfo, _$path, name2, remoteIdPrefix, isLayout, newId, content, _tmp;
128
- return _ts_generator(this, function(_state3) {
129
- switch (_state3.label) {
130
- case 0:
131
- currentPathName = route.path ? path.join("/", pathName, route.path) : pathName;
132
- if (!route.id)
133
- return [
134
- 3,
135
- 6
136
- ];
137
- originalId = route.id;
138
- route.originalId = originalId;
139
- remoteInfo = remotePathMap[currentPathName];
140
- if (!remoteInfo)
141
- return [
142
- 3,
143
- 2
144
- ];
145
- _$path = remoteInfo.path, name2 = remoteInfo.name;
146
- remoteIdPrefix = transformName2Prefix(name2);
147
- isLayout = Boolean(route.children);
148
- newId = "".concat(remoteIdPrefix).concat(isLayout ? "layout" : "page");
149
- ssrByRouteIdsMap[originalId] = newId;
150
- content = fs.readFileSync(_$path, "utf-8");
151
- return [
152
- 4,
153
- fs.writeFile(_$path, content.replace(ROUTE_ID, originalId))
154
- ];
155
- case 1:
156
- _state3.sent();
157
- route.id = newId;
158
- return [
159
- 3,
160
- 3
161
- ];
162
- case 2:
163
- route.id = "".concat(prefix).concat(route.id);
164
- _state3.label = 3;
165
- case 3:
166
- _tmp = route.children;
167
- if (!_tmp)
168
- return [
169
- 3,
170
- 5
171
- ];
172
- return [
173
- 4,
174
- Promise.all(route.children.map(function() {
175
- var _ref4 = _async_to_generator(function(r) {
176
- return _ts_generator(this, function(_state4) {
177
- switch (_state4.label) {
178
- case 0:
179
- return [
180
- 4,
181
- modifyRouteIds(r, currentPathName)
182
- ];
183
- case 1:
184
- return [
185
- 2,
186
- _state4.sent()
187
- ];
188
- }
189
- });
190
- });
191
- return function(r) {
192
- return _ref4.apply(this, arguments);
193
- };
194
- }()))
195
- ];
196
- case 4:
197
- _tmp = _state3.sent();
198
- _state3.label = 5;
199
- case 5:
200
- _tmp;
201
- _state3.label = 6;
202
- case 6:
203
- return [
204
- 2
205
- ];
206
- }
207
- });
208
- });
209
- return function modifyRouteIds2(route, pathName) {
210
- return _ref3.apply(this, arguments);
211
- };
212
- }();
213
- return [
214
- 4,
215
- Promise.all(routes.map(function() {
216
- var _ref3 = _async_to_generator(function(route) {
217
- return _ts_generator(this, function(_state3) {
218
- switch (_state3.label) {
219
- case 0:
220
- return [
221
- 4,
222
- modifyRouteIds(route, entryName === DEFAULT_ENTRY ? "" : entryName)
223
- ];
224
- case 1:
225
- _state3.sent();
226
- return [
227
- 2
228
- ];
229
- }
230
- });
231
- });
232
- return function(route) {
233
- return _ref3.apply(this, arguments);
234
- };
235
- }()))
236
- ];
237
- case 1:
238
- _state2.sent();
239
- return [
240
- 2,
241
- options
242
- ];
243
- }
244
- });
245
- })();
246
- }
247
- }
248
- ];
249
- }
250
- });
251
- });
252
- return function(_) {
253
- return _ref.apply(this, arguments);
254
- };
255
- }(),
256
- usePlugins: [
257
- moduleFederationExportRoutePlugin(internalRoutesPluginOptions),
258
- moduleFederationImportRoutePlugin(internalRoutesPluginOptions)
259
- ]
260
- };
261
- };
262
- var plugin_default = moduleFederationRoutesPlugin;
263
- export {
264
- plugin_default as default,
265
- moduleFederationRoutesPlugin
266
- };
@@ -1,313 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { fs, normalizeToPosixPath } from "@modern-js/utils";
5
- import path from "path";
6
- import os from "os";
7
- import { DEFAULT_ENTRY, MF_JSON, ROUTE_ID } from "../../constant";
8
- import { getRemoteLayoutId } from "../../runtime/routes/utils";
9
- var ROUTES = "routes";
10
- function calcPathName(filePath, rootDir, entry) {
11
- var relativePath = path.relative(rootDir, filePath);
12
- var conditionalReg = /^\[(.*)\]$/;
13
- var splitPaths = relativePath.split("/").reduce(function(sum, cur) {
14
- if (cur.includes(".")) {
15
- var _sum;
16
- var split = cur.split(".").map(function(i) {
17
- var match2 = i.match(conditionalReg);
18
- if (match2) {
19
- return ":".concat(match2[1]);
20
- }
21
- return i.startsWith("__") ? "" : i;
22
- });
23
- (_sum = sum).push.apply(_sum, _to_consumable_array(split));
24
- } else {
25
- var match = cur.match(conditionalReg);
26
- if (match) {
27
- sum.push(":".concat(match[1]));
28
- } else {
29
- if (!cur.startsWith("__")) {
30
- sum.push(cur);
31
- }
32
- }
33
- }
34
- return sum;
35
- }, []);
36
- return path.join("/", entry, splitPaths.filter(function(p) {
37
- return !!p;
38
- }).join("/"));
39
- }
40
- function traverseRouteFiles(options) {
41
- return _traverseRouteFiles.apply(this, arguments);
42
- }
43
- function _traverseRouteFiles() {
44
- _traverseRouteFiles = _async_to_generator(function(options) {
45
- var appDirectory, generateRouteFile, remotePathMap, entries, srcPath, traverse, traverseRoutes, normalizedEntries;
46
- return _ts_generator(this, function(_state) {
47
- switch (_state.label) {
48
- case 0:
49
- appDirectory = options.appDirectory, generateRouteFile = options.generateRouteFile, remotePathMap = options.remotePathMap;
50
- entries = [];
51
- srcPath = "".concat(appDirectory, "/src");
52
- traverse = function() {
53
- var _ref = _async_to_generator(function(filepath, rootDir, entry) {
54
- var isDirectory, items, mfJson, mfJsonContent, remoteName, remoteLayoutId, writeFile, pathname, filePath;
55
- return _ts_generator(this, function(_state2) {
56
- switch (_state2.label) {
57
- case 0:
58
- return [
59
- 4,
60
- fs.pathExists(filepath)
61
- ];
62
- case 1:
63
- if (!_state2.sent()) {
64
- return [
65
- 2,
66
- null
67
- ];
68
- }
69
- return [
70
- 4,
71
- fs.stat(filepath)
72
- ];
73
- case 2:
74
- isDirectory = _state2.sent().isDirectory();
75
- if (!isDirectory) {
76
- return [
77
- 2,
78
- null
79
- ];
80
- }
81
- return [
82
- 4,
83
- fs.readdir(filepath)
84
- ];
85
- case 3:
86
- items = _state2.sent();
87
- mfJson = items.find(function(i) {
88
- return i === MF_JSON;
89
- });
90
- if (!mfJson)
91
- return [
92
- 3,
93
- 7
94
- ];
95
- return [
96
- 4,
97
- fs.readJSON(normalizeToPosixPath(path.join(filepath, mfJson)))
98
- ];
99
- case 4:
100
- mfJsonContent = _state2.sent();
101
- remoteName = mfJsonContent.remoteName;
102
- remoteLayoutId = getRemoteLayoutId(remoteName);
103
- writeFile = function() {
104
- var _ref2 = _async_to_generator(function(id, type, pathname2) {
105
- var generatedFilePath, content;
106
- return _ts_generator(this, function(_state3) {
107
- switch (_state3.label) {
108
- case 0:
109
- generatedFilePath = normalizeToPosixPath(path.join(filepath, "".concat(type, ".tsx")));
110
- content = [
111
- "// Do not edit this file. It is a auto generated.",
112
- "// It will render ".concat(remoteName, "'s ").concat(type, "."),
113
- "// The ".concat(type, " pathname is: ").concat(pathname2),
114
- "// The ".concat(type, " route id is: ").concat(ROUTE_ID)
115
- ];
116
- return [
117
- 4,
118
- fs.writeFile(generatedFilePath, content.join(os.EOL))
119
- ];
120
- case 1:
121
- _state3.sent();
122
- return [
123
- 2,
124
- generatedFilePath
125
- ];
126
- }
127
- });
128
- });
129
- return function writeFile2(id, type, pathname2) {
130
- return _ref2.apply(this, arguments);
131
- };
132
- }();
133
- if (!remoteLayoutId)
134
- return [
135
- 3,
136
- 6
137
- ];
138
- pathname = calcPathName(filepath, rootDir, entry);
139
- return [
140
- 4,
141
- writeFile(remoteLayoutId, "layout", pathname)
142
- ];
143
- case 5:
144
- filePath = _state2.sent();
145
- remotePathMap[pathname] = {
146
- name: remoteName,
147
- path: filePath
148
- };
149
- _state2.label = 6;
150
- case 6:
151
- return [
152
- 2
153
- ];
154
- case 7:
155
- return [
156
- 4,
157
- Promise.all(items.map(function() {
158
- var _ref2 = _async_to_generator(function(item) {
159
- return _ts_generator(this, function(_state3) {
160
- switch (_state3.label) {
161
- case 0:
162
- return [
163
- 4,
164
- traverse(normalizeToPosixPath(path.join(filepath, item)), rootDir, entry)
165
- ];
166
- case 1:
167
- _state3.sent();
168
- return [
169
- 2
170
- ];
171
- }
172
- });
173
- });
174
- return function(item) {
175
- return _ref2.apply(this, arguments);
176
- };
177
- }()))
178
- ];
179
- case 8:
180
- _state2.sent();
181
- return [
182
- 2
183
- ];
184
- }
185
- });
186
- });
187
- return function traverse2(filepath, rootDir, entry) {
188
- return _ref.apply(this, arguments);
189
- };
190
- }();
191
- traverseRoutes = function() {
192
- var _ref = _async_to_generator(function(dir) {
193
- var level, isDirectory, items, entry, rootDir;
194
- var _arguments = arguments;
195
- return _ts_generator(this, function(_state2) {
196
- switch (_state2.label) {
197
- case 0:
198
- level = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : 1;
199
- if (level > 3) {
200
- return [
201
- 2
202
- ];
203
- }
204
- return [
205
- 4,
206
- fs.stat(dir)
207
- ];
208
- case 1:
209
- isDirectory = _state2.sent().isDirectory();
210
- if (!isDirectory) {
211
- return [
212
- 2
213
- ];
214
- }
215
- return [
216
- 4,
217
- fs.readdir(dir)
218
- ];
219
- case 2:
220
- items = _state2.sent();
221
- if (!items.find(function(i) {
222
- return i === ROUTES;
223
- }))
224
- return [
225
- 3,
226
- 5
227
- ];
228
- entry = path.relative(srcPath, dir);
229
- entries.push(entry);
230
- rootDir = "".concat(dir, "/").concat(ROUTES);
231
- if (!generateRouteFile)
232
- return [
233
- 3,
234
- 4
235
- ];
236
- return [
237
- 4,
238
- traverse(rootDir, rootDir, entry)
239
- ];
240
- case 3:
241
- _state2.sent();
242
- _state2.label = 4;
243
- case 4:
244
- return [
245
- 3,
246
- 7
247
- ];
248
- case 5:
249
- return [
250
- 4,
251
- Promise.all(items.map(function() {
252
- var _ref2 = _async_to_generator(function(item) {
253
- return _ts_generator(this, function(_state3) {
254
- switch (_state3.label) {
255
- case 0:
256
- return [
257
- 4,
258
- traverseRoutes(path.join(dir, item), level++)
259
- ];
260
- case 1:
261
- _state3.sent();
262
- return [
263
- 2
264
- ];
265
- }
266
- });
267
- });
268
- return function(item) {
269
- return _ref2.apply(this, arguments);
270
- };
271
- }()))
272
- ];
273
- case 6:
274
- _state2.sent();
275
- _state2.label = 7;
276
- case 7:
277
- return [
278
- 2
279
- ];
280
- }
281
- });
282
- });
283
- return function traverseRoutes2(dir) {
284
- return _ref.apply(this, arguments);
285
- };
286
- }();
287
- return [
288
- 4,
289
- traverseRoutes(srcPath)
290
- ];
291
- case 1:
292
- _state.sent();
293
- normalizedEntries = entries.map(function(entry) {
294
- if (entry === "") {
295
- return DEFAULT_ENTRY;
296
- }
297
- return entry;
298
- });
299
- return [
300
- 2,
301
- {
302
- entries: normalizedEntries
303
- }
304
- ];
305
- }
306
- });
307
- });
308
- return _traverseRouteFiles.apply(this, arguments);
309
- }
310
- export {
311
- calcPathName,
312
- traverseRouteFiles
313
- };