@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/make.js
CHANGED
|
@@ -1,83 +1,82 @@
|
|
|
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 normalize from "normalize-path";
|
|
55
|
-
function makeRender(ssgRoutes, render, port) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
55
|
+
export function makeRender(ssgRoutes, render, port) {
|
|
56
|
+
return ssgRoutes.map(function(ssgRoute) {
|
|
57
|
+
return render({
|
|
58
|
+
url: ssgRoute.urlPath,
|
|
59
|
+
headers: _object_spread({
|
|
60
|
+
host: "localhost:".concat(port)
|
|
61
|
+
}, ssgRoute.headers),
|
|
62
|
+
connection: {}
|
|
64
63
|
});
|
|
64
|
+
});
|
|
65
65
|
}
|
|
66
|
-
function makeRoute(baseRoute, route) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
export function makeRoute(baseRoute, route) {
|
|
67
|
+
var headers = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
68
|
+
var urlPath = baseRoute.urlPath, entryPath = baseRoute.entryPath;
|
|
69
|
+
if (typeof route === "string") {
|
|
70
|
+
return _object_spread_props(_object_spread({}, baseRoute), {
|
|
71
|
+
urlPath: normalize("".concat(urlPath).concat(route)) || "/",
|
|
72
|
+
headers,
|
|
73
|
+
output: path.join(entryPath, "..".concat(route === "/" ? "" : route))
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
return _object_spread_props(_object_spread({}, baseRoute), {
|
|
77
|
+
urlPath: normalize("".concat(urlPath).concat(route.url)) || "/",
|
|
78
|
+
headers: _object_spread({}, headers, route.headers),
|
|
79
|
+
output: route.output ? path.normalize(route.output) : path.join(entryPath, "..".concat(route.url === "/" ? "" : route.url))
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
82
|
}
|
|
83
|
-
export { makeRender, makeRoute };
|
package/dist/esm/libs/output.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
export function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
4
|
+
htmlAry.forEach(function(html, index) {
|
|
5
|
+
var ssgRoute = ssgRoutes[index];
|
|
6
|
+
var filepath = path.join(baseDir, ssgRoute.output);
|
|
7
|
+
if (!fs.existsSync(path.dirname(filepath))) {
|
|
8
|
+
fs.ensureDirSync(path.dirname(filepath));
|
|
9
|
+
}
|
|
10
|
+
fs.writeFileSync(filepath, html);
|
|
11
|
+
});
|
|
12
12
|
}
|
|
13
|
-
export { writeHtmlFile };
|
package/dist/esm/libs/replace.js
CHANGED
|
@@ -1,115 +1,128 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
5
7
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
+
function _array_without_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return _array_like_to_array(arr);
|
|
8
11
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
function _define_property(obj, key, value) {
|
|
13
|
+
if (key in obj) {
|
|
14
|
+
Object.defineProperty(obj, key, {
|
|
15
|
+
value,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
obj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
21
24
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
25
|
+
function _iterable_to_array(iter) {
|
|
26
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
27
|
+
return Array.from(iter);
|
|
24
28
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
29
|
+
function _non_iterable_spread() {
|
|
30
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
27
31
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
ownKeys.forEach(function(key) {
|
|
38
|
-
_defineProperty(target, key, source[key]);
|
|
39
|
-
});
|
|
32
|
+
function _object_spread(target) {
|
|
33
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
34
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
35
|
+
var ownKeys = Object.keys(source);
|
|
36
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
37
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
38
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
39
|
+
}));
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
ownKeys.forEach(function(key) {
|
|
42
|
+
_define_property(target, key, source[key]);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return target;
|
|
42
46
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
function _object_without_properties(source, excluded) {
|
|
48
|
+
if (source == null)
|
|
49
|
+
return {};
|
|
50
|
+
var target = _object_without_properties_loose(source, excluded);
|
|
51
|
+
var key, i;
|
|
52
|
+
if (Object.getOwnPropertySymbols) {
|
|
53
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
54
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
55
|
+
key = sourceSymbolKeys[i];
|
|
56
|
+
if (excluded.indexOf(key) >= 0)
|
|
57
|
+
continue;
|
|
58
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key))
|
|
59
|
+
continue;
|
|
60
|
+
target[key] = source[key];
|
|
55
61
|
}
|
|
56
|
-
|
|
62
|
+
}
|
|
63
|
+
return target;
|
|
57
64
|
}
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
function _object_without_properties_loose(source, excluded) {
|
|
66
|
+
if (source == null)
|
|
67
|
+
return {};
|
|
68
|
+
var target = {};
|
|
69
|
+
var sourceKeys = Object.keys(source);
|
|
70
|
+
var key, i;
|
|
71
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
72
|
+
key = sourceKeys[i];
|
|
73
|
+
if (excluded.indexOf(key) >= 0)
|
|
74
|
+
continue;
|
|
75
|
+
target[key] = source[key];
|
|
76
|
+
}
|
|
77
|
+
return target;
|
|
69
78
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
79
|
+
function _to_consumable_array(arr) {
|
|
80
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
72
81
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
83
|
+
if (!o)
|
|
84
|
+
return;
|
|
85
|
+
if (typeof o === "string")
|
|
86
|
+
return _array_like_to_array(o, minLen);
|
|
87
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
88
|
+
if (n === "Object" && o.constructor)
|
|
89
|
+
n = o.constructor.name;
|
|
90
|
+
if (n === "Map" || n === "Set")
|
|
91
|
+
return Array.from(n);
|
|
92
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
93
|
+
return _array_like_to_array(o, minLen);
|
|
80
94
|
}
|
|
81
95
|
import normalize from "normalize-path";
|
|
82
|
-
function exist(route, pageRoutes) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
export function exist(route, pageRoutes) {
|
|
97
|
+
return pageRoutes.slice().findIndex(function(pageRoute) {
|
|
98
|
+
var urlEqual = normalize(pageRoute.urlPath) === normalize(route.urlPath);
|
|
99
|
+
var entryEqual = pageRoute.entryName === route.entryName;
|
|
100
|
+
if (urlEqual && entryEqual) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
});
|
|
91
105
|
}
|
|
92
|
-
function replaceRoute(ssgRoutes, pageRoutes) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
export function replaceRoute(ssgRoutes, pageRoutes) {
|
|
107
|
+
var _pageRoutes;
|
|
108
|
+
var cleanSsgRoutes = ssgRoutes.map(function(ssgRoute) {
|
|
109
|
+
var output = ssgRoute.output, headers = ssgRoute.headers, cleanSsgRoute = _object_without_properties(ssgRoute, [
|
|
110
|
+
"output",
|
|
111
|
+
"headers"
|
|
112
|
+
]);
|
|
113
|
+
return Object.assign(cleanSsgRoute, output ? {
|
|
114
|
+
entryPath: output
|
|
115
|
+
} : {});
|
|
116
|
+
});
|
|
117
|
+
var freshRoutes = [];
|
|
118
|
+
cleanSsgRoutes.forEach(function(ssgRoute) {
|
|
119
|
+
var index = exist(ssgRoute, pageRoutes);
|
|
120
|
+
if (index < 0) {
|
|
121
|
+
freshRoutes.push(_object_spread({}, ssgRoute));
|
|
122
|
+
} else {
|
|
123
|
+
pageRoutes[index].entryPath = ssgRoute.entryPath;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
(_pageRoutes = pageRoutes).push.apply(_pageRoutes, _to_consumable_array(freshRoutes));
|
|
127
|
+
return pageRoutes;
|
|
114
128
|
}
|
|
115
|
-
export { exist, replaceRoute };
|