@gyoll/builder 0.5.0 → 0.6.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/build-output/builder.cjs +26 -7
- package/build-output/builder.js +26 -7
- package/package.json +1 -1
package/build-output/builder.cjs
CHANGED
|
@@ -40,10 +40,14 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
40
40
|
}
|
|
41
41
|
const routes = [];
|
|
42
42
|
if (routeFiles.page) {
|
|
43
|
+
const pathInfo = buildRoutePath(segments);
|
|
43
44
|
const route = {
|
|
44
|
-
path:
|
|
45
|
+
path: pathInfo.path,
|
|
45
46
|
component: import_path.default.relative(baseDir, routeFiles.page)
|
|
46
47
|
};
|
|
48
|
+
if (pathInfo.catchAllParam) {
|
|
49
|
+
route.catchAllParam = pathInfo.catchAllParam;
|
|
50
|
+
}
|
|
47
51
|
if (currentLayouts.length > 0) {
|
|
48
52
|
route.layouts = [...currentLayouts];
|
|
49
53
|
}
|
|
@@ -104,8 +108,9 @@ function parseSegment(segment) {
|
|
|
104
108
|
if (/^\(.+\)$/.test(segment)) {
|
|
105
109
|
return null;
|
|
106
110
|
}
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
const catchAllMatch = /^\[\.\.\.(.+)\]$/.exec(segment);
|
|
112
|
+
if (catchAllMatch) {
|
|
113
|
+
return { type: "catchall", param: catchAllMatch[1] };
|
|
109
114
|
}
|
|
110
115
|
if (/^\[(.+)\]$/.test(segment)) {
|
|
111
116
|
const param = segment.slice(1, -1);
|
|
@@ -114,11 +119,25 @@ function parseSegment(segment) {
|
|
|
114
119
|
return segment;
|
|
115
120
|
}
|
|
116
121
|
function buildRoutePath(segments) {
|
|
117
|
-
const filtered =
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
const filtered = [];
|
|
123
|
+
let catchAllParam = null;
|
|
124
|
+
for (const segment of segments) {
|
|
125
|
+
if (segment === null) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (typeof segment === "object" && segment.type === "catchall") {
|
|
129
|
+
catchAllParam = segment.param;
|
|
130
|
+
filtered.push("*");
|
|
131
|
+
} else {
|
|
132
|
+
filtered.push(segment);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const path3 = filtered.length === 0 ? "/" : "/" + filtered.join("/");
|
|
136
|
+
const result = { path: path3 };
|
|
137
|
+
if (catchAllParam) {
|
|
138
|
+
result.catchAllParam = catchAllParam;
|
|
120
139
|
}
|
|
121
|
-
return
|
|
140
|
+
return result;
|
|
122
141
|
}
|
|
123
142
|
async function generateManifest(routes, outFile, routesDir) {
|
|
124
143
|
const outDir = import_path.default.dirname(outFile);
|
package/build-output/builder.js
CHANGED
|
@@ -18,10 +18,14 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
18
18
|
}
|
|
19
19
|
const routes = [];
|
|
20
20
|
if (routeFiles.page) {
|
|
21
|
+
const pathInfo = buildRoutePath(segments);
|
|
21
22
|
const route = {
|
|
22
|
-
path:
|
|
23
|
+
path: pathInfo.path,
|
|
23
24
|
component: path.relative(baseDir, routeFiles.page)
|
|
24
25
|
};
|
|
26
|
+
if (pathInfo.catchAllParam) {
|
|
27
|
+
route.catchAllParam = pathInfo.catchAllParam;
|
|
28
|
+
}
|
|
25
29
|
if (currentLayouts.length > 0) {
|
|
26
30
|
route.layouts = [...currentLayouts];
|
|
27
31
|
}
|
|
@@ -82,8 +86,9 @@ function parseSegment(segment) {
|
|
|
82
86
|
if (/^\(.+\)$/.test(segment)) {
|
|
83
87
|
return null;
|
|
84
88
|
}
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
const catchAllMatch = /^\[\.\.\.(.+)\]$/.exec(segment);
|
|
90
|
+
if (catchAllMatch) {
|
|
91
|
+
return { type: "catchall", param: catchAllMatch[1] };
|
|
87
92
|
}
|
|
88
93
|
if (/^\[(.+)\]$/.test(segment)) {
|
|
89
94
|
const param = segment.slice(1, -1);
|
|
@@ -92,11 +97,25 @@ function parseSegment(segment) {
|
|
|
92
97
|
return segment;
|
|
93
98
|
}
|
|
94
99
|
function buildRoutePath(segments) {
|
|
95
|
-
const filtered =
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
const filtered = [];
|
|
101
|
+
let catchAllParam = null;
|
|
102
|
+
for (const segment of segments) {
|
|
103
|
+
if (segment === null) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (typeof segment === "object" && segment.type === "catchall") {
|
|
107
|
+
catchAllParam = segment.param;
|
|
108
|
+
filtered.push("*");
|
|
109
|
+
} else {
|
|
110
|
+
filtered.push(segment);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const path3 = filtered.length === 0 ? "/" : "/" + filtered.join("/");
|
|
114
|
+
const result = { path: path3 };
|
|
115
|
+
if (catchAllParam) {
|
|
116
|
+
result.catchAllParam = catchAllParam;
|
|
98
117
|
}
|
|
99
|
-
return
|
|
118
|
+
return result;
|
|
100
119
|
}
|
|
101
120
|
async function generateManifest(routes, outFile, routesDir) {
|
|
102
121
|
const outDir = path.dirname(outFile);
|