@modern-js/plugin-ssg 2.15.0 → 2.17.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 +19 -0
- package/dist/cjs/index.js +62 -95
- package/dist/cjs/libs/make.js +34 -48
- package/dist/cjs/libs/output.js +18 -41
- package/dist/cjs/libs/replace.js +24 -41
- package/dist/cjs/libs/util.js +48 -72
- package/dist/cjs/server/consts.js +7 -25
- package/dist/cjs/server/index.js +67 -90
- package/dist/cjs/server/prerender.js +20 -41
- package/dist/cjs/server/process.js +22 -45
- package/dist/cjs/types.js +4 -15
- package/dist/esm/index.js +316 -309
- package/dist/esm/libs/make.js +70 -71
- package/dist/esm/libs/output.js +9 -10
- package/dist/esm/libs/replace.js +113 -100
- package/dist/esm/libs/util.js +211 -210
- package/dist/esm/server/consts.js +1 -2
- package/dist/esm/server/index.js +56 -57
- package/dist/esm/server/prerender.js +85 -86
- package/dist/esm/server/process.js +220 -213
- package/dist/esm/types.js +1 -1
- package/dist/esm-node/index.js +29 -51
- package/dist/esm-node/libs/make.js +14 -14
- package/dist/esm-node/libs/output.js +1 -4
- package/dist/esm-node/libs/replace.js +8 -11
- package/dist/esm-node/libs/util.js +26 -41
- package/dist/esm-node/server/consts.js +1 -4
- package/dist/esm-node/server/index.js +49 -52
- package/dist/esm-node/server/prerender.js +4 -5
- package/dist/esm-node/server/process.js +3 -13
- package/dist/esm-node/types.js +1 -0
- package/package.json +12 -8
package/dist/esm/libs/util.js
CHANGED
|
@@ -1,239 +1,240 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
ownKeys.forEach(function(key) {
|
|
24
|
-
_defineProperty(target, key, source[key]);
|
|
25
|
-
});
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys2 = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
26
22
|
}
|
|
27
|
-
|
|
23
|
+
ownKeys2.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
28
|
}
|
|
29
29
|
function ownKeys(object, enumerableOnly) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
keys.push.apply(keys, symbols);
|
|
30
|
+
var keys = Object.keys(object);
|
|
31
|
+
if (Object.getOwnPropertySymbols) {
|
|
32
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
33
|
+
if (enumerableOnly) {
|
|
34
|
+
symbols = symbols.filter(function(sym) {
|
|
35
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
+
});
|
|
39
37
|
}
|
|
40
|
-
|
|
38
|
+
keys.push.apply(keys, symbols);
|
|
39
|
+
}
|
|
40
|
+
return keys;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
function _object_spread_props(target, source) {
|
|
43
|
+
source = source != null ? source : {};
|
|
44
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
45
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
46
|
+
} else {
|
|
47
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
52
|
}
|
|
53
53
|
import path from "path";
|
|
54
54
|
import { ROUTE_SPEC_FILE, fs, isSingleEntry, SERVER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
55
|
-
function formatOutput(filename) {
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
export function formatOutput(filename) {
|
|
56
|
+
var outputPath = path.extname(filename) ? filename : "".concat(filename, "/index.html");
|
|
57
|
+
return outputPath;
|
|
58
58
|
}
|
|
59
|
-
function formatPath(str) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return addr;
|
|
63
|
-
}
|
|
64
|
-
if (addr.startsWith(".")) {
|
|
65
|
-
addr = addr.slice(1);
|
|
66
|
-
}
|
|
67
|
-
if (!addr.startsWith("/")) {
|
|
68
|
-
addr = "/".concat(addr);
|
|
69
|
-
}
|
|
70
|
-
if (addr.endsWith("/") && addr !== "/") {
|
|
71
|
-
addr = addr.slice(0, addr.length - 1);
|
|
72
|
-
}
|
|
59
|
+
export function formatPath(str) {
|
|
60
|
+
var addr = str;
|
|
61
|
+
if (!addr || typeof addr !== "string") {
|
|
73
62
|
return addr;
|
|
63
|
+
}
|
|
64
|
+
if (addr.startsWith(".")) {
|
|
65
|
+
addr = addr.slice(1);
|
|
66
|
+
}
|
|
67
|
+
if (!addr.startsWith("/")) {
|
|
68
|
+
addr = "/".concat(addr);
|
|
69
|
+
}
|
|
70
|
+
if (addr.endsWith("/") && addr !== "/") {
|
|
71
|
+
addr = addr.slice(0, addr.length - 1);
|
|
72
|
+
}
|
|
73
|
+
return addr;
|
|
74
74
|
}
|
|
75
|
-
function isDynamicUrl(url) {
|
|
76
|
-
|
|
75
|
+
export function isDynamicUrl(url) {
|
|
76
|
+
return url.includes(":");
|
|
77
77
|
}
|
|
78
|
-
function getUrlPrefix(route, baseUrl) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
base = baseUrl;
|
|
78
|
+
export function getUrlPrefix(route, baseUrl) {
|
|
79
|
+
var base = "";
|
|
80
|
+
if (Array.isArray(baseUrl)) {
|
|
81
|
+
var filters = baseUrl.filter(function(url) {
|
|
82
|
+
return route.urlPath.includes(url);
|
|
83
|
+
});
|
|
84
|
+
if (filters.length > 1) {
|
|
85
|
+
var matched = filters.sort(function(a, b) {
|
|
86
|
+
return a.length - b.length;
|
|
87
|
+
})[0];
|
|
88
|
+
if (!matched) {
|
|
89
|
+
throw new Error("");
|
|
90
|
+
}
|
|
91
|
+
base = matched;
|
|
95
92
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
} else {
|
|
94
|
+
base = baseUrl;
|
|
95
|
+
}
|
|
96
|
+
base = base === "/" ? "" : base;
|
|
97
|
+
var entryName = route.entryName === "main" ? "" : route.entryName;
|
|
98
|
+
var prefix = "".concat(base, "/").concat(entryName);
|
|
99
|
+
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
100
100
|
}
|
|
101
|
-
function getOutput(route, base, agreed) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
101
|
+
export function getOutput(route, base, agreed) {
|
|
102
|
+
var output = route.output;
|
|
103
|
+
if (output) {
|
|
104
|
+
return output;
|
|
105
|
+
}
|
|
106
|
+
if (agreed) {
|
|
107
|
+
var urlWithoutBase = route.urlPath.replace(base, "");
|
|
108
|
+
return urlWithoutBase.startsWith("/") ? urlWithoutBase.slice(1) : urlWithoutBase;
|
|
109
|
+
}
|
|
110
|
+
throw new Error("routing must provide output when calling createPage(), check ".concat(route.urlPath));
|
|
111
111
|
}
|
|
112
|
-
var readJSONSpec = function(dir) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
export var readJSONSpec = function(dir) {
|
|
113
|
+
var routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
114
|
+
var routeJSON = require(routeJSONPath);
|
|
115
|
+
var routes = routeJSON.routes;
|
|
116
|
+
return routes;
|
|
117
117
|
};
|
|
118
|
-
var writeJSONSpec = function(dir, routes) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
export var writeJSONSpec = function(dir, routes) {
|
|
119
|
+
var routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
120
|
+
fs.writeJSONSync(routeJSONPath, {
|
|
121
|
+
routes
|
|
122
|
+
}, {
|
|
123
|
+
spaces: 2
|
|
124
|
+
});
|
|
125
125
|
};
|
|
126
|
-
var replaceWithAlias = function(base, filePath, alias) {
|
|
127
|
-
|
|
126
|
+
export var replaceWithAlias = function(base, filePath, alias) {
|
|
127
|
+
return path.posix.join(alias, path.posix.relative(base, filePath));
|
|
128
128
|
};
|
|
129
|
-
var standardOptions = function(ssgOptions, entrypoints, routes, server) {
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
export var standardOptions = function(ssgOptions, entrypoints, routes, server) {
|
|
130
|
+
if (ssgOptions === false) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
if (ssgOptions === true) {
|
|
134
|
+
return entrypoints.reduce(function(opt, entry) {
|
|
135
|
+
opt[entry.entryName] = ssgOptions;
|
|
136
|
+
return opt;
|
|
137
|
+
}, {});
|
|
138
|
+
} else if (typeof ssgOptions === "object") {
|
|
139
|
+
var isSingle = isSingleEntry(entrypoints);
|
|
140
|
+
if (isSingle && typeof ssgOptions.main === "undefined") {
|
|
141
|
+
return {
|
|
142
|
+
main: ssgOptions
|
|
143
|
+
};
|
|
144
|
+
} else {
|
|
145
|
+
return ssgOptions;
|
|
132
146
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
var
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var entrypoint = _step.value;
|
|
153
|
-
var entryName = entrypoint.entryName;
|
|
154
|
-
if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
|
|
155
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
156
|
-
try {
|
|
157
|
-
var _loop = function() {
|
|
158
|
-
var url = _step1.value;
|
|
159
|
-
var matchUrl = entryName === "main" ? url : "".concat(url, "/").concat(entryName);
|
|
160
|
-
var route = routes.find(function(route2) {
|
|
161
|
-
return route2.urlPath === matchUrl;
|
|
162
|
-
});
|
|
163
|
-
intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
|
|
164
|
-
baseUrl: url
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
for(var _iterator = server.baseUrl[Symbol.iterator](), _step1; !(_iteratorNormalCompletion = (_step1 = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
168
|
-
} catch (err) {
|
|
169
|
-
_didIteratorError = true;
|
|
170
|
-
_iteratorError = err;
|
|
171
|
-
} finally{
|
|
172
|
-
try {
|
|
173
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
174
|
-
_iterator.return();
|
|
175
|
-
}
|
|
176
|
-
} finally{
|
|
177
|
-
if (_didIteratorError) {
|
|
178
|
-
throw _iteratorError;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
} else {
|
|
183
|
-
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
184
|
-
baseUrl: server === null || server === void 0 ? void 0 : server.baseUrl
|
|
185
|
-
});
|
|
186
|
-
}
|
|
147
|
+
} else if (typeof ssgOptions === "function") {
|
|
148
|
+
var intermediateOptions = {};
|
|
149
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
150
|
+
try {
|
|
151
|
+
var _loop = function() {
|
|
152
|
+
var entrypoint = _step.value;
|
|
153
|
+
var entryName = entrypoint.entryName;
|
|
154
|
+
if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
|
|
155
|
+
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
|
156
|
+
try {
|
|
157
|
+
var _loop2 = function() {
|
|
158
|
+
var url = _step1.value;
|
|
159
|
+
var matchUrl = entryName === "main" ? url : "".concat(url, "/").concat(entryName);
|
|
160
|
+
var route = routes.find(function(route2) {
|
|
161
|
+
return route2.urlPath === matchUrl;
|
|
162
|
+
});
|
|
163
|
+
intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
|
|
164
|
+
baseUrl: url
|
|
165
|
+
});
|
|
187
166
|
};
|
|
188
|
-
for(var
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
167
|
+
for (var _iterator2 = server.baseUrl[Symbol.iterator](), _step1; !(_iteratorNormalCompletion2 = (_step1 = _iterator2.next()).done); _iteratorNormalCompletion2 = true)
|
|
168
|
+
_loop2();
|
|
169
|
+
} catch (err) {
|
|
170
|
+
_didIteratorError2 = true;
|
|
171
|
+
_iteratorError2 = err;
|
|
172
|
+
} finally {
|
|
193
173
|
try {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
} finally{
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
174
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
175
|
+
_iterator2.return();
|
|
176
|
+
}
|
|
177
|
+
} finally {
|
|
178
|
+
if (_didIteratorError2) {
|
|
179
|
+
throw _iteratorError2;
|
|
180
|
+
}
|
|
201
181
|
}
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
185
|
+
baseUrl: server === null || server === void 0 ? void 0 : server.baseUrl
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
for (var _iterator = entrypoints[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
|
|
190
|
+
_loop();
|
|
191
|
+
} catch (err) {
|
|
192
|
+
_didIteratorError = true;
|
|
193
|
+
_iteratorError = err;
|
|
194
|
+
} finally {
|
|
195
|
+
try {
|
|
196
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
197
|
+
_iterator.return();
|
|
202
198
|
}
|
|
203
|
-
|
|
199
|
+
} finally {
|
|
200
|
+
if (_didIteratorError) {
|
|
201
|
+
throw _iteratorError;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
204
|
}
|
|
205
|
-
return
|
|
205
|
+
return intermediateOptions;
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
206
208
|
};
|
|
207
|
-
var openRouteSSR = function(routes) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
});
|
|
209
|
+
export var openRouteSSR = function(routes) {
|
|
210
|
+
var entries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
211
|
+
return routes.map(function(ssgRoute) {
|
|
212
|
+
return _object_spread_props(_object_spread({}, ssgRoute), {
|
|
213
|
+
isSSR: entries.includes(ssgRoute.entryName),
|
|
214
|
+
bundle: "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(ssgRoute.entryName, ".js")
|
|
214
215
|
});
|
|
216
|
+
});
|
|
215
217
|
};
|
|
216
|
-
var flattenRoutes = function(routes) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
218
|
+
export var flattenRoutes = function(routes) {
|
|
219
|
+
var parents = [];
|
|
220
|
+
var newRoutes = [];
|
|
221
|
+
var traverseRoute = function(route) {
|
|
222
|
+
var parent = parents[parents.length - 1];
|
|
223
|
+
var path2 = parent ? "".concat(parent.path, "/").concat(route.path || "").replace(/\/+/g, "/") : route.path || "";
|
|
224
|
+
path2 = path2.replace(/\/$/, "");
|
|
225
|
+
if (route._component && (path2 !== "/" || path2 === "/" && !parent)) {
|
|
226
|
+
newRoutes.push(_object_spread_props(_object_spread({}, route), {
|
|
227
|
+
path: path2
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
if (route.children) {
|
|
231
|
+
parents.push(_object_spread_props(_object_spread({}, route), {
|
|
232
|
+
path: path2
|
|
233
|
+
}));
|
|
234
|
+
route.children.forEach(traverseRoute);
|
|
235
|
+
parents.pop();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
routes.forEach(traverseRoute);
|
|
239
|
+
return newRoutes;
|
|
238
240
|
};
|
|
239
|
-
export { flattenRoutes, formatOutput, formatPath, getOutput, getUrlPrefix, isDynamicUrl, openRouteSSR, readJSONSpec, replaceWithAlias, standardOptions, writeJSONSpec };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
var CLOSE_SIGN = "modern_close_server";
|
|
2
|
-
export { CLOSE_SIGN };
|
|
1
|
+
export var CLOSE_SIGN = "modern_close_server";
|
package/dist/esm/server/index.js
CHANGED
|
@@ -3,62 +3,61 @@ import path from "path";
|
|
|
3
3
|
import { logger } from "@modern-js/utils";
|
|
4
4
|
import { openRouteSSR } from "../libs/util";
|
|
5
5
|
import { CLOSE_SIGN } from "./consts";
|
|
6
|
-
var createServer = function(api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
var backup = openRouteSSR(pageRoutes, entries);
|
|
13
|
-
var total = backup.concat(apiRoutes);
|
|
14
|
-
var cp = childProcess.fork(path.join(__dirname, "process"), {
|
|
15
|
-
cwd: appDirectory,
|
|
16
|
-
silent: true
|
|
17
|
-
});
|
|
18
|
-
var appContext = api.useAppContext();
|
|
19
|
-
var plugins = appContext.serverInternalPlugins;
|
|
20
|
-
cp.send(JSON.stringify({
|
|
21
|
-
options: options,
|
|
22
|
-
renderRoutes: ssgRoutes,
|
|
23
|
-
routes: total,
|
|
24
|
-
appDirectory: appDirectory,
|
|
25
|
-
plugins: plugins
|
|
26
|
-
}));
|
|
27
|
-
var htmlChunks = [];
|
|
28
|
-
var htmlAry = [];
|
|
29
|
-
cp.on("message", function(chunk) {
|
|
30
|
-
if (chunk !== null) {
|
|
31
|
-
htmlChunks.push(chunk);
|
|
32
|
-
} else {
|
|
33
|
-
var html = htmlChunks.join("");
|
|
34
|
-
htmlAry.push(html);
|
|
35
|
-
htmlChunks.length = 0;
|
|
36
|
-
}
|
|
37
|
-
if (htmlAry.length === ssgRoutes.length) {
|
|
38
|
-
cp.send(CLOSE_SIGN);
|
|
39
|
-
resolve(htmlAry);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
(_cp_stderr = cp.stderr) === null || _cp_stderr === void 0 ? void 0 : _cp_stderr.on("data", function(chunk) {
|
|
43
|
-
var str = chunk.toString();
|
|
44
|
-
if (str.includes("Error")) {
|
|
45
|
-
logger.error(str);
|
|
46
|
-
reject(new Error("ssg render failed"));
|
|
47
|
-
cp.kill("SIGKILL");
|
|
48
|
-
} else {
|
|
49
|
-
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
(_cp_stdout = cp.stdout) === null || _cp_stdout === void 0 ? void 0 : _cp_stdout.on("data", function(chunk) {
|
|
53
|
-
var str = chunk.toString();
|
|
54
|
-
if (str.includes("Error")) {
|
|
55
|
-
logger.error(str);
|
|
56
|
-
reject(new Error("ssg render failed"));
|
|
57
|
-
cp.kill("SIGKILL");
|
|
58
|
-
} else {
|
|
59
|
-
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
60
|
-
}
|
|
61
|
-
});
|
|
6
|
+
export var createServer = function(api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) {
|
|
7
|
+
return new Promise(function(resolve, reject) {
|
|
8
|
+
var _cp_stderr, _cp_stdout;
|
|
9
|
+
var entries = ssgRoutes.map(function(route) {
|
|
10
|
+
return route.entryName;
|
|
62
11
|
});
|
|
12
|
+
var backup = openRouteSSR(pageRoutes, entries);
|
|
13
|
+
var total = backup.concat(apiRoutes);
|
|
14
|
+
var cp = childProcess.fork(path.join(__dirname, "process"), {
|
|
15
|
+
cwd: appDirectory,
|
|
16
|
+
silent: true
|
|
17
|
+
});
|
|
18
|
+
var appContext = api.useAppContext();
|
|
19
|
+
var plugins = appContext.serverInternalPlugins;
|
|
20
|
+
cp.send(JSON.stringify({
|
|
21
|
+
options,
|
|
22
|
+
renderRoutes: ssgRoutes,
|
|
23
|
+
routes: total,
|
|
24
|
+
appDirectory,
|
|
25
|
+
plugins
|
|
26
|
+
}));
|
|
27
|
+
var htmlChunks = [];
|
|
28
|
+
var htmlAry = [];
|
|
29
|
+
cp.on("message", function(chunk) {
|
|
30
|
+
if (chunk !== null) {
|
|
31
|
+
htmlChunks.push(chunk);
|
|
32
|
+
} else {
|
|
33
|
+
var html = htmlChunks.join("");
|
|
34
|
+
htmlAry.push(html);
|
|
35
|
+
htmlChunks.length = 0;
|
|
36
|
+
}
|
|
37
|
+
if (htmlAry.length === ssgRoutes.length) {
|
|
38
|
+
cp.send(CLOSE_SIGN);
|
|
39
|
+
resolve(htmlAry);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
(_cp_stderr = cp.stderr) === null || _cp_stderr === void 0 ? void 0 : _cp_stderr.on("data", function(chunk) {
|
|
43
|
+
var str = chunk.toString();
|
|
44
|
+
if (str.includes("Error")) {
|
|
45
|
+
logger.error(str);
|
|
46
|
+
reject(new Error("ssg render failed"));
|
|
47
|
+
cp.kill("SIGKILL");
|
|
48
|
+
} else {
|
|
49
|
+
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
(_cp_stdout = cp.stdout) === null || _cp_stdout === void 0 ? void 0 : _cp_stdout.on("data", function(chunk) {
|
|
53
|
+
var str = chunk.toString();
|
|
54
|
+
if (str.includes("Error")) {
|
|
55
|
+
logger.error(str);
|
|
56
|
+
reject(new Error("ssg render failed"));
|
|
57
|
+
cp.kill("SIGKILL");
|
|
58
|
+
} else {
|
|
59
|
+
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
63
|
};
|
|
64
|
-
export { createServer };
|