@modern-js/app-tools 2.53.1-alpha.4 → 2.54.1-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +0 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/cjs/commands/build.js +2 -0
- package/dist/cjs/commands/deploy.js +2 -2
- package/dist/cjs/commands/dev.js +19 -5
- package/dist/cjs/commands/index.js +113 -7
- package/dist/cjs/commands/serve.js +19 -5
- package/dist/cjs/hooks.js +5 -0
- package/dist/cjs/index.js +14 -83
- package/dist/cjs/plugins/analyze/constants.js +56 -0
- package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
- package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
- package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
- package/dist/cjs/plugins/analyze/templates.js +101 -0
- package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
- package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/node.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -2
- package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +10 -4
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/deploy.js +2 -2
- package/dist/esm/commands/dev.js +13 -9
- package/dist/esm/commands/index.js +411 -3
- package/dist/esm/commands/serve.js +12 -8
- package/dist/esm/hooks.js +5 -0
- package/dist/esm/index.js +12 -394
- package/dist/esm/plugins/analyze/constants.js +24 -0
- package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
- package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
- package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
- package/dist/esm/plugins/analyze/templates.js +22 -0
- package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
- package/dist/esm/plugins/deploy/platforms/netlify.js +5 -3
- package/dist/esm/plugins/deploy/platforms/node.js +5 -3
- package/dist/esm/plugins/deploy/platforms/vercel.js +5 -3
- package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm/plugins/serverBuild.js +13 -6
- package/dist/esm/utils/createServer.js +2 -2
- package/dist/esm/utils/loadPlugins.js +64 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm-node/commands/build.js +2 -0
- package/dist/esm-node/commands/deploy.js +2 -2
- package/dist/esm-node/commands/dev.js +11 -7
- package/dist/esm-node/commands/index.js +92 -3
- package/dist/esm-node/commands/serve.js +10 -6
- package/dist/esm-node/hooks.js +5 -0
- package/dist/esm-node/index.js +12 -79
- package/dist/esm-node/plugins/analyze/constants.js +24 -0
- package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
- package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
- package/dist/esm-node/plugins/analyze/templates.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -3
- package/dist/esm-node/plugins/deploy/platforms/node.js +3 -3
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -3
- package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm-node/plugins/serverBuild.js +11 -5
- package/dist/esm-node/utils/createServer.js +2 -2
- package/dist/esm-node/utils/loadPlugins.js +21 -0
- package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
- package/dist/types/commands/index.d.ts +10 -3
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/exports/server.d.ts +4 -0
- package/dist/types/index.d.ts +2 -5
- package/dist/types/plugins/analyze/constants.d.ts +9 -0
- package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
- package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
- package/dist/types/plugins/analyze/templates.d.ts +19 -0
- package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
- package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
- package/dist/types/types/hooks.d.ts +11 -1
- package/dist/types/utils/loadPlugins.d.ts +5 -0
- package/package.json +22 -22
- package/dist/cjs/analyze/constants.js +0 -122
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
- package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
- package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
- package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
- package/dist/cjs/analyze/nestedRoutes.js +0 -295
- package/dist/cjs/analyze/templates.js +0 -444
- package/dist/esm/analyze/constants.js +0 -76
- package/dist/esm/analyze/getBundleEntry.js +0 -75
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
- package/dist/esm/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
- package/dist/esm/analyze/getFileSystemEntry.js +0 -113
- package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
- package/dist/esm/analyze/nestedRoutes.js +0 -398
- package/dist/esm/analyze/templates.js +0 -435
- package/dist/esm/utils/getServerInternalPlugins.js +0 -40
- package/dist/esm-node/analyze/constants.js +0 -76
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
- package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
- package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
- package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
- package/dist/esm-node/analyze/nestedRoutes.js +0 -259
- package/dist/esm-node/analyze/templates.js +0 -405
- package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
- package/dist/types/analyze/constants.d.ts +0 -42
- package/dist/types/analyze/getBundleEntry.d.ts +0 -3
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
- package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
- package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
- package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
- package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
- package/dist/types/analyze/nestedRoutes.d.ts +0 -7
- package/dist/types/analyze/templates.d.ts +0 -30
- package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
- /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -1,185 +0,0 @@
|
|
1
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
2
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
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
|
-
var compName = function(srcDirectory, filePath) {
|
10
|
-
var legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
11
|
-
return "Comp_".concat(legalCompName);
|
12
|
-
};
|
13
|
-
var layoutNameAbbr = function(filePath) {
|
14
|
-
var prefix = "L_";
|
15
|
-
var dirName = path.dirname(filePath).split("/").pop() || "";
|
16
|
-
return "".concat(prefix).concat(makeLegalIdentifier(dirName));
|
17
|
-
};
|
18
|
-
var parents = [];
|
19
|
-
var recursiveReadDir = function(param) {
|
20
|
-
var dir = param.dir, routes = param.routes, _param_basePath = param.basePath, basePath = _param_basePath === void 0 ? "/" : _param_basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
|
21
|
-
var hasDynamicRoute = false;
|
22
|
-
var resetParent = false;
|
23
|
-
var parent = parents[parents.length - 1];
|
24
|
-
var layout = findLayout(dir);
|
25
|
-
if (layout) {
|
26
|
-
if (basePath === "/") {
|
27
|
-
throw new Error("should use _app instead of _layout in ".concat(dir));
|
28
|
-
} else {
|
29
|
-
var alias = replaceWithAlias(srcDirectory, layout, srcAlias);
|
30
|
-
var componentName = compName(srcDirectory, layout);
|
31
|
-
var route = {
|
32
|
-
path: "".concat(basePath.substring(0, basePath.length - 1)),
|
33
|
-
children: [],
|
34
|
-
_component: alias,
|
35
|
-
component: componentName,
|
36
|
-
parent,
|
37
|
-
type: "page"
|
38
|
-
};
|
39
|
-
parent = route;
|
40
|
-
resetParent = true;
|
41
|
-
routes.push(route);
|
42
|
-
parents.push(route);
|
43
|
-
routes = route.children;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
47
|
-
try {
|
48
|
-
for (var _iterator = fs.readdirSync(dir)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
49
|
-
var relative = _step.value;
|
50
|
-
var filePath = path.join(dir, relative);
|
51
|
-
if (!shouldSkip(filePath)) {
|
52
|
-
var filename = path.basename(filePath, path.extname(filePath));
|
53
|
-
var alias1 = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
54
|
-
var componentName1 = compName(srcDirectory, filePath);
|
55
|
-
var dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
56
|
-
if (dynamicRouteMatched) {
|
57
|
-
if (hasDynamicRoute) {
|
58
|
-
throw new Error("Can't set two dynamic route in one directory: ".concat(dir));
|
59
|
-
} else {
|
60
|
-
hasDynamicRoute = true;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
var route1 = {
|
64
|
-
path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1].replace(/\$$/, "?")).concat(dynamicRouteMatched[2]) : filename),
|
65
|
-
_component: alias1,
|
66
|
-
component: componentName1,
|
67
|
-
parent,
|
68
|
-
type: "page"
|
69
|
-
};
|
70
|
-
if (fs.statSync(filePath).isDirectory()) {
|
71
|
-
recursiveReadDir({
|
72
|
-
dir: filePath,
|
73
|
-
routes,
|
74
|
-
basePath: "".concat(route1.path, "/"),
|
75
|
-
srcDirectory,
|
76
|
-
srcAlias
|
77
|
-
});
|
78
|
-
continue;
|
79
|
-
}
|
80
|
-
if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
|
81
|
-
continue;
|
82
|
-
}
|
83
|
-
if (filename === FILE_SYSTEM_ROUTES_INDEX) {
|
84
|
-
route1.path = basePath === "/" ? basePath : "".concat(basePath.substring(0, basePath.length - 1));
|
85
|
-
}
|
86
|
-
if (filename === "404" && basePath === "/") {
|
87
|
-
route1.path = "*";
|
88
|
-
}
|
89
|
-
routes.push(route1);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
} catch (err) {
|
93
|
-
_didIteratorError = true;
|
94
|
-
_iteratorError = err;
|
95
|
-
} finally {
|
96
|
-
try {
|
97
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
98
|
-
_iterator.return();
|
99
|
-
}
|
100
|
-
} finally {
|
101
|
-
if (_didIteratorError) {
|
102
|
-
throw _iteratorError;
|
103
|
-
}
|
104
|
-
}
|
105
|
-
}
|
106
|
-
if (resetParent) {
|
107
|
-
parents.pop();
|
108
|
-
}
|
109
|
-
};
|
110
|
-
var normalizeNestedRoutes = function(nested, internalComponentsDir, internalDirectory, internalDirAlias) {
|
111
|
-
var flat = function(routes) {
|
112
|
-
return routes.reduce(function(memo, route) {
|
113
|
-
return memo.concat(Array.isArray(route.children) ? flat(route.children) : [
|
114
|
-
route
|
115
|
-
]);
|
116
|
-
}, []);
|
117
|
-
};
|
118
|
-
var generate = function(route) {
|
119
|
-
var codes = [];
|
120
|
-
var lastComponent = route.component;
|
121
|
-
var imports = [
|
122
|
-
"import React from 'react';",
|
123
|
-
"import ".concat(lastComponent, " from '").concat(route._component, "'")
|
124
|
-
];
|
125
|
-
while (route = route.parent) {
|
126
|
-
var layoutComponent = route.component;
|
127
|
-
var layoutComponentAbbr = layoutNameAbbr(route._component);
|
128
|
-
imports.push("import ".concat(layoutComponent, " from '").concat(route._component, "';"));
|
129
|
-
var currentComponent = "".concat(layoutComponentAbbr, "_").concat(lastComponent);
|
130
|
-
codes.push("const ".concat(currentComponent, " = props => <").concat(layoutComponent, " Component={").concat(lastComponent, "} {...props} />;"));
|
131
|
-
lastComponent = currentComponent;
|
132
|
-
}
|
133
|
-
var file = path.resolve(internalComponentsDir, "".concat(lastComponent, ".jsx"));
|
134
|
-
fs.outputFileSync(file, "".concat(imports.join("\n"), "\n").concat(codes.join("\n"), "\nexport default ").concat(lastComponent));
|
135
|
-
return {
|
136
|
-
component: lastComponent,
|
137
|
-
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
138
|
-
};
|
139
|
-
};
|
140
|
-
var normalized = flat(nested).map(function(route) {
|
141
|
-
return route.parent ? _object_spread_props(_object_spread({}, route, generate(route)), {
|
142
|
-
parent: void 0
|
143
|
-
}) : _object_spread_props(_object_spread({}, route), {
|
144
|
-
parent: void 0
|
145
|
-
});
|
146
|
-
});
|
147
|
-
return normalized;
|
148
|
-
};
|
149
|
-
var getClientRoutes = function(param) {
|
150
|
-
var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias, internalDirectory = param.internalDirectory, internalDirAlias = param.internalDirAlias;
|
151
|
-
var entryName = entrypoint.entryName, pageRoutesEntry = entrypoint.pageRoutesEntry;
|
152
|
-
if (!pageRoutesEntry) {
|
153
|
-
return [];
|
154
|
-
}
|
155
|
-
if (!fs.existsSync(pageRoutesEntry)) {
|
156
|
-
throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " directory not found."));
|
157
|
-
}
|
158
|
-
if (!(fs.existsSync(pageRoutesEntry) && fs.statSync(pageRoutesEntry).isDirectory())) {
|
159
|
-
throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " should be directory."));
|
160
|
-
}
|
161
|
-
var routes = [];
|
162
|
-
recursiveReadDir({
|
163
|
-
dir: pageRoutesEntry,
|
164
|
-
routes,
|
165
|
-
basePath: "/",
|
166
|
-
srcDirectory,
|
167
|
-
srcAlias
|
168
|
-
});
|
169
|
-
var internalComponentsDir = path.resolve(internalDirectory, "".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_COMPONENTS_DIR));
|
170
|
-
fs.emptyDirSync(internalComponentsDir);
|
171
|
-
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
172
|
-
parents.length = 0;
|
173
|
-
routes.sort(function(a, b) {
|
174
|
-
var delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
175
|
-
if (delta === 0) {
|
176
|
-
return a.path.length - b.path.length;
|
177
|
-
}
|
178
|
-
return delta;
|
179
|
-
});
|
180
|
-
debug("fileSystem routes: %o", routes);
|
181
|
-
return routes;
|
182
|
-
};
|
183
|
-
export {
|
184
|
-
getClientRoutes
|
185
|
-
};
|
@@ -1,183 +0,0 @@
|
|
1
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
2
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
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
|
-
var compName = function(srcDirectory, filePath) {
|
10
|
-
var legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
11
|
-
return "Comp_".concat(legalCompName);
|
12
|
-
};
|
13
|
-
var layoutNameAbbr = function(filePath) {
|
14
|
-
var prefix = "L_";
|
15
|
-
var dirName = path.dirname(filePath).split("/").pop() || "";
|
16
|
-
return "".concat(prefix).concat(makeLegalIdentifier(dirName));
|
17
|
-
};
|
18
|
-
var parents = [];
|
19
|
-
var recursiveReadDirLegacy = function(param) {
|
20
|
-
var dir = param.dir, routes = param.routes, _param_basePath = param.basePath, basePath = _param_basePath === void 0 ? "/" : _param_basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
|
21
|
-
var hasDynamicRoute = false;
|
22
|
-
var resetParent = false;
|
23
|
-
var parent = parents[parents.length - 1];
|
24
|
-
var layout = findLayout(dir);
|
25
|
-
if (layout) {
|
26
|
-
if (basePath === "/") {
|
27
|
-
throw new Error("should use _app instead of _layout in ".concat(dir));
|
28
|
-
} else {
|
29
|
-
var alias = replaceWithAlias(srcDirectory, layout, srcAlias);
|
30
|
-
var componentName = compName(srcDirectory, layout);
|
31
|
-
var route = {
|
32
|
-
path: "".concat(basePath.substring(0, basePath.length - 1)),
|
33
|
-
exact: false,
|
34
|
-
routes: [],
|
35
|
-
_component: alias,
|
36
|
-
component: componentName,
|
37
|
-
parent
|
38
|
-
};
|
39
|
-
parent = route;
|
40
|
-
resetParent = true;
|
41
|
-
routes.push(route);
|
42
|
-
parents.push(route);
|
43
|
-
routes = route.routes;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
47
|
-
try {
|
48
|
-
for (var _iterator = fs.readdirSync(dir)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
49
|
-
var relative = _step.value;
|
50
|
-
var filePath = path.join(dir, relative);
|
51
|
-
if (!shouldSkip(filePath)) {
|
52
|
-
var filename = path.basename(filePath, path.extname(filePath));
|
53
|
-
var alias1 = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
54
|
-
var componentName1 = compName(srcDirectory, filePath);
|
55
|
-
var dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
56
|
-
if (dynamicRouteMatched) {
|
57
|
-
if (hasDynamicRoute) {
|
58
|
-
throw new Error("Can't set two dynamic route in one directory: ".concat(dir));
|
59
|
-
} else {
|
60
|
-
hasDynamicRoute = true;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
var route1 = {
|
64
|
-
path: "".concat(basePath).concat(dynamicRouteMatched ? ":".concat(dynamicRouteMatched[1].replace(/\$$/, "?")).concat(dynamicRouteMatched[2]) : filename),
|
65
|
-
_component: alias1,
|
66
|
-
component: componentName1,
|
67
|
-
exact: true,
|
68
|
-
parent
|
69
|
-
};
|
70
|
-
if (fs.statSync(filePath).isDirectory()) {
|
71
|
-
recursiveReadDirLegacy({
|
72
|
-
dir: filePath,
|
73
|
-
routes,
|
74
|
-
basePath: "".concat(route1.path, "/"),
|
75
|
-
srcDirectory,
|
76
|
-
srcAlias
|
77
|
-
});
|
78
|
-
continue;
|
79
|
-
}
|
80
|
-
if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
|
81
|
-
continue;
|
82
|
-
}
|
83
|
-
if (filename === FILE_SYSTEM_ROUTES_INDEX) {
|
84
|
-
route1.path = basePath === "/" ? basePath : "".concat(basePath.substring(0, basePath.length - 1));
|
85
|
-
}
|
86
|
-
if (filename === "404" && basePath === "/") {
|
87
|
-
route1.path = "*";
|
88
|
-
route1.exact = false;
|
89
|
-
}
|
90
|
-
routes.push(route1);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
} catch (err) {
|
94
|
-
_didIteratorError = true;
|
95
|
-
_iteratorError = err;
|
96
|
-
} finally {
|
97
|
-
try {
|
98
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
99
|
-
_iterator.return();
|
100
|
-
}
|
101
|
-
} finally {
|
102
|
-
if (_didIteratorError) {
|
103
|
-
throw _iteratorError;
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
if (resetParent) {
|
108
|
-
parents.pop();
|
109
|
-
}
|
110
|
-
};
|
111
|
-
var normalizeNestedRoutes = function(nested, internalComponentsDir, internalDirectory, internalDirAlias) {
|
112
|
-
var flat = function(routes) {
|
113
|
-
return routes.reduce(function(memo, route) {
|
114
|
-
return memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [
|
115
|
-
route
|
116
|
-
]);
|
117
|
-
}, []);
|
118
|
-
};
|
119
|
-
var generate = function(route) {
|
120
|
-
var codes = [];
|
121
|
-
var lastComponent = route.component;
|
122
|
-
var imports = [
|
123
|
-
"import React from 'react';",
|
124
|
-
"import ".concat(lastComponent, " from '").concat(route._component, "'")
|
125
|
-
];
|
126
|
-
while (route = route.parent) {
|
127
|
-
var layoutComponent = route.component;
|
128
|
-
var layoutComponentAbbr = layoutNameAbbr(route._component);
|
129
|
-
imports.push("import ".concat(layoutComponent, " from '").concat(route._component, "';"));
|
130
|
-
var currentComponent = "".concat(layoutComponentAbbr, "_").concat(lastComponent);
|
131
|
-
codes.push("const ".concat(currentComponent, " = props => <").concat(layoutComponent, " Component={").concat(lastComponent, "} {...props} />;"));
|
132
|
-
lastComponent = currentComponent;
|
133
|
-
}
|
134
|
-
var file = path.resolve(internalComponentsDir, "".concat(lastComponent, ".jsx"));
|
135
|
-
fs.outputFileSync(file, "".concat(imports.join("\n"), "\n").concat(codes.join("\n"), "\nexport default ").concat(lastComponent));
|
136
|
-
return {
|
137
|
-
component: lastComponent,
|
138
|
-
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
139
|
-
};
|
140
|
-
};
|
141
|
-
var normalized = flat(nested).map(function(route) {
|
142
|
-
return route.parent ? _object_spread_props(_object_spread({}, route, generate(route)), {
|
143
|
-
parent: void 0
|
144
|
-
}) : _object_spread_props(_object_spread({}, route), {
|
145
|
-
parent: void 0
|
146
|
-
});
|
147
|
-
});
|
148
|
-
return normalized;
|
149
|
-
};
|
150
|
-
var getClientRoutes = function(param) {
|
151
|
-
var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias, internalDirectory = param.internalDirectory, internalDirAlias = param.internalDirAlias;
|
152
|
-
var entry = entrypoint.entry, entryName = entrypoint.entryName;
|
153
|
-
if (!fs.existsSync(entry)) {
|
154
|
-
throw new Error("generate file system routes error, ".concat(entry, " directory not found."));
|
155
|
-
}
|
156
|
-
if (!(fs.existsSync(entry) && fs.statSync(entry).isDirectory())) {
|
157
|
-
throw new Error("generate file system routes error, ".concat(entry, " should be directory."));
|
158
|
-
}
|
159
|
-
var routes = [];
|
160
|
-
recursiveReadDirLegacy({
|
161
|
-
dir: entry,
|
162
|
-
routes,
|
163
|
-
basePath: "/",
|
164
|
-
srcDirectory,
|
165
|
-
srcAlias
|
166
|
-
});
|
167
|
-
var internalComponentsDir = path.resolve(internalDirectory, "".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_COMPONENTS_DIR));
|
168
|
-
fs.emptyDirSync(internalComponentsDir);
|
169
|
-
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
170
|
-
parents.length = 0;
|
171
|
-
routes.sort(function(a, b) {
|
172
|
-
var delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
173
|
-
if (delta === 0) {
|
174
|
-
return a.path.length - b.path.length;
|
175
|
-
}
|
176
|
-
return delta;
|
177
|
-
});
|
178
|
-
debug("fileSystem routes: %o", routes);
|
179
|
-
return routes;
|
180
|
-
};
|
181
|
-
export {
|
182
|
-
getClientRoutes
|
183
|
-
};
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import path from "path";
|
2
|
-
import { createDebugger, findExists, fs } from "@modern-js/utils";
|
3
|
-
import { JS_EXTENSIONS, FILE_SYSTEM_ROUTES_LAYOUT, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX } from "../constants";
|
4
|
-
var debug = createDebugger("get-client-routes");
|
5
|
-
var findLayout = function(dir) {
|
6
|
-
return findExists(JS_EXTENSIONS.map(function(ext) {
|
7
|
-
return path.resolve(dir, "".concat(FILE_SYSTEM_ROUTES_LAYOUT).concat(ext));
|
8
|
-
}));
|
9
|
-
};
|
10
|
-
var getRouteWeight = function(route) {
|
11
|
-
return route === "*" ? 999 : route.split(":").length - 1;
|
12
|
-
};
|
13
|
-
var shouldSkip = function(file) {
|
14
|
-
if (fs.statSync(file).isDirectory()) {
|
15
|
-
return false;
|
16
|
-
}
|
17
|
-
var ext = path.extname(file);
|
18
|
-
if (FILE_SYSTEM_ROUTES_IGNORED_REGEX.test(file) || !JS_EXTENSIONS.includes(ext) || FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT === path.basename(file, ext)) {
|
19
|
-
return true;
|
20
|
-
}
|
21
|
-
return false;
|
22
|
-
};
|
23
|
-
export {
|
24
|
-
debug,
|
25
|
-
findLayout,
|
26
|
-
getRouteWeight,
|
27
|
-
shouldSkip
|
28
|
-
};
|
@@ -1,113 +0,0 @@
|
|
1
|
-
import fs from "fs";
|
2
|
-
import path from "path";
|
3
|
-
import { findExists, ensureAbsolutePath } from "@modern-js/utils";
|
4
|
-
import { isDefaultExportFunction } from "./isDefaultExportFunction";
|
5
|
-
import { JS_EXTENSIONS, INDEX_FILE_NAME, APP_FILE_NAME, PAGES_DIR_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, NESTED_ROUTES_DIR } from "./constants";
|
6
|
-
var hasIndex = function(dir) {
|
7
|
-
return findExists(JS_EXTENSIONS.map(function(ext) {
|
8
|
-
return path.resolve(dir, "".concat(INDEX_FILE_NAME).concat(ext));
|
9
|
-
}));
|
10
|
-
};
|
11
|
-
var hasApp = function(dir) {
|
12
|
-
return findExists(JS_EXTENSIONS.map(function(ext) {
|
13
|
-
return path.resolve(dir, "".concat(APP_FILE_NAME).concat(ext));
|
14
|
-
}));
|
15
|
-
};
|
16
|
-
var hasPages = function(dir) {
|
17
|
-
return fs.existsSync(path.join(dir, PAGES_DIR_NAME));
|
18
|
-
};
|
19
|
-
var hasNestedRoutes = function(dir) {
|
20
|
-
return fs.existsSync(path.join(dir, NESTED_ROUTES_DIR));
|
21
|
-
};
|
22
|
-
var isBundleEntry = function(dir) {
|
23
|
-
return hasApp(dir) || hasPages(dir) || hasIndex(dir) || hasNestedRoutes(dir);
|
24
|
-
};
|
25
|
-
var scanDir = function(dirs) {
|
26
|
-
return dirs.map(function(dir) {
|
27
|
-
var indexFile = hasIndex(dir);
|
28
|
-
var customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
29
|
-
var entryName = path.basename(dir);
|
30
|
-
if (indexFile && !customBootstrap) {
|
31
|
-
return {
|
32
|
-
entryName,
|
33
|
-
isMainEntry: false,
|
34
|
-
entry: indexFile,
|
35
|
-
absoluteEntryDir: path.resolve(dir),
|
36
|
-
isAutoMount: false
|
37
|
-
};
|
38
|
-
}
|
39
|
-
var isHasApp = hasApp(dir);
|
40
|
-
if (isHasApp) {
|
41
|
-
return {
|
42
|
-
entryName,
|
43
|
-
isMainEntry: false,
|
44
|
-
entry: path.join(dir, APP_FILE_NAME),
|
45
|
-
isAutoMount: true,
|
46
|
-
absoluteEntryDir: path.resolve(dir),
|
47
|
-
customBootstrap
|
48
|
-
};
|
49
|
-
}
|
50
|
-
var isHasNestedRoutes = hasNestedRoutes(dir);
|
51
|
-
var isHasPages = hasPages(dir);
|
52
|
-
if (isHasNestedRoutes || isHasPages) {
|
53
|
-
var entrypoint = {
|
54
|
-
entryName,
|
55
|
-
isMainEntry: false,
|
56
|
-
entry: "",
|
57
|
-
fileSystemRoutes: {
|
58
|
-
globalApp: findExists(JS_EXTENSIONS.map(function(ext) {
|
59
|
-
return path.resolve(dir, "./".concat(PAGES_DIR_NAME, "/").concat(FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT).concat(ext));
|
60
|
-
}))
|
61
|
-
},
|
62
|
-
isAutoMount: true,
|
63
|
-
absoluteEntryDir: path.resolve(dir),
|
64
|
-
customBootstrap
|
65
|
-
};
|
66
|
-
if (isHasPages) {
|
67
|
-
entrypoint.entry = path.join(dir, PAGES_DIR_NAME);
|
68
|
-
entrypoint.pageRoutesEntry = entrypoint.entry;
|
69
|
-
}
|
70
|
-
if (isHasNestedRoutes) {
|
71
|
-
entrypoint.entry = path.join(dir, NESTED_ROUTES_DIR);
|
72
|
-
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
73
|
-
}
|
74
|
-
return entrypoint;
|
75
|
-
}
|
76
|
-
return {
|
77
|
-
entryName,
|
78
|
-
isMainEntry: false,
|
79
|
-
entry: indexFile,
|
80
|
-
absoluteEntryDir: path.resolve(dir),
|
81
|
-
isAutoMount: false
|
82
|
-
};
|
83
|
-
});
|
84
|
-
};
|
85
|
-
var getFileSystemEntry = function(appContext, config) {
|
86
|
-
var appDirectory = appContext.appDirectory;
|
87
|
-
var _config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs;
|
88
|
-
var disabledDirs = [];
|
89
|
-
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
90
|
-
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {
|
91
|
-
return ensureAbsolutePath(appDirectory, dir);
|
92
|
-
});
|
93
|
-
}
|
94
|
-
var src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
95
|
-
if (fs.existsSync(src)) {
|
96
|
-
if (fs.statSync(src).isDirectory()) {
|
97
|
-
return scanDir(isBundleEntry(src) ? [
|
98
|
-
src
|
99
|
-
] : fs.readdirSync(src).map(function(file) {
|
100
|
-
return path.join(src, file);
|
101
|
-
}).filter(function(file) {
|
102
|
-
return fs.statSync(file).isDirectory() && isBundleEntry(file) && !disabledDirs.includes(file);
|
103
|
-
}));
|
104
|
-
} else {
|
105
|
-
throw Error("source.entriesDir accept a directory.");
|
106
|
-
}
|
107
|
-
} else {
|
108
|
-
throw Error("src dir ".concat(entriesDir, " not found."));
|
109
|
-
}
|
110
|
-
};
|
111
|
-
export {
|
112
|
-
getFileSystemEntry
|
113
|
-
};
|
@@ -1,15 +0,0 @@
|
|
1
|
-
var reservedWords = "break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public";
|
2
|
-
var builtins = "arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl";
|
3
|
-
var forbidList = new Set("".concat(reservedWords, " ").concat(builtins).split(" "));
|
4
|
-
function makeLegalIdentifier(str) {
|
5
|
-
var identifier = str.replace(/-(\w)/g, function(_, letter) {
|
6
|
-
return letter.toUpperCase();
|
7
|
-
}).replace(/[^$_a-zA-Z0-9]/g, "_");
|
8
|
-
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
9
|
-
return "_".concat(identifier);
|
10
|
-
}
|
11
|
-
return identifier || "_";
|
12
|
-
}
|
13
|
-
export {
|
14
|
-
makeLegalIdentifier
|
15
|
-
};
|