@gyoll/builder 0.4.0 → 0.5.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 +19 -10
- package/build-output/builder.js +19 -10
- package/package.json +1 -1
package/build-output/builder.cjs
CHANGED
|
@@ -29,19 +29,23 @@ async function scanRoutes(routesDir) {
|
|
|
29
29
|
const routes = await walkDirectory(routesDir, routesDir);
|
|
30
30
|
return routes;
|
|
31
31
|
}
|
|
32
|
-
async function walkDirectory(dir, baseDir, segments = []) {
|
|
32
|
+
async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
33
33
|
const entries = await import_promises.default.readdir(dir, { withFileTypes: true });
|
|
34
34
|
const files = entries.filter((e) => e.isFile());
|
|
35
35
|
const dirs = entries.filter((e) => e.isDirectory());
|
|
36
36
|
const routeFiles = collectRouteFiles(files, dir);
|
|
37
|
+
const currentLayouts = [...parentLayouts];
|
|
38
|
+
if (routeFiles.layout) {
|
|
39
|
+
currentLayouts.push(import_path.default.relative(baseDir, routeFiles.layout));
|
|
40
|
+
}
|
|
37
41
|
const routes = [];
|
|
38
42
|
if (routeFiles.page) {
|
|
39
43
|
const route = {
|
|
40
44
|
path: buildRoutePath(segments),
|
|
41
45
|
component: import_path.default.relative(baseDir, routeFiles.page)
|
|
42
46
|
};
|
|
43
|
-
if (
|
|
44
|
-
route.
|
|
47
|
+
if (currentLayouts.length > 0) {
|
|
48
|
+
route.layouts = [...currentLayouts];
|
|
45
49
|
}
|
|
46
50
|
if (routeFiles.error) {
|
|
47
51
|
route.error = import_path.default.relative(baseDir, routeFiles.error);
|
|
@@ -54,10 +58,12 @@ async function walkDirectory(dir, baseDir, segments = []) {
|
|
|
54
58
|
for (const subdir of dirs) {
|
|
55
59
|
const segment = parseSegment(subdir.name);
|
|
56
60
|
const subdirPath = import_path.default.join(dir, subdir.name);
|
|
57
|
-
const childRoutes = await walkDirectory(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
const childRoutes = await walkDirectory(
|
|
62
|
+
subdirPath,
|
|
63
|
+
baseDir,
|
|
64
|
+
[...segments, segment],
|
|
65
|
+
currentLayouts
|
|
66
|
+
);
|
|
61
67
|
routes.push(...childRoutes);
|
|
62
68
|
}
|
|
63
69
|
return routes;
|
|
@@ -120,9 +126,12 @@ async function generateManifest(routes, outFile, routesDir) {
|
|
|
120
126
|
const adjustedRoutes = JSON.stringify(routes, null, 2).replace(/"component": "(.+?)"/g, (match, p1) => {
|
|
121
127
|
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
122
128
|
return `"component": () => import("./${importPath}")`;
|
|
123
|
-
}).replace(/"
|
|
124
|
-
const
|
|
125
|
-
|
|
129
|
+
}).replace(/"layouts": \[([\s\S]*?)\]/g, (match, layoutsContent) => {
|
|
130
|
+
const transformed = layoutsContent.replace(/"(.+?)"/g, (m, p1) => {
|
|
131
|
+
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
132
|
+
return `() => import("./${importPath}")`;
|
|
133
|
+
});
|
|
134
|
+
return `"layouts": [${transformed}]`;
|
|
126
135
|
}).replace(/"error": "(.+?)"/g, (match, p1) => {
|
|
127
136
|
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
128
137
|
return `"error": () => import("./${importPath}")`;
|
package/build-output/builder.js
CHANGED
|
@@ -7,19 +7,23 @@ async function scanRoutes(routesDir) {
|
|
|
7
7
|
const routes = await walkDirectory(routesDir, routesDir);
|
|
8
8
|
return routes;
|
|
9
9
|
}
|
|
10
|
-
async function walkDirectory(dir, baseDir, segments = []) {
|
|
10
|
+
async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
11
11
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
12
12
|
const files = entries.filter((e) => e.isFile());
|
|
13
13
|
const dirs = entries.filter((e) => e.isDirectory());
|
|
14
14
|
const routeFiles = collectRouteFiles(files, dir);
|
|
15
|
+
const currentLayouts = [...parentLayouts];
|
|
16
|
+
if (routeFiles.layout) {
|
|
17
|
+
currentLayouts.push(path.relative(baseDir, routeFiles.layout));
|
|
18
|
+
}
|
|
15
19
|
const routes = [];
|
|
16
20
|
if (routeFiles.page) {
|
|
17
21
|
const route = {
|
|
18
22
|
path: buildRoutePath(segments),
|
|
19
23
|
component: path.relative(baseDir, routeFiles.page)
|
|
20
24
|
};
|
|
21
|
-
if (
|
|
22
|
-
route.
|
|
25
|
+
if (currentLayouts.length > 0) {
|
|
26
|
+
route.layouts = [...currentLayouts];
|
|
23
27
|
}
|
|
24
28
|
if (routeFiles.error) {
|
|
25
29
|
route.error = path.relative(baseDir, routeFiles.error);
|
|
@@ -32,10 +36,12 @@ async function walkDirectory(dir, baseDir, segments = []) {
|
|
|
32
36
|
for (const subdir of dirs) {
|
|
33
37
|
const segment = parseSegment(subdir.name);
|
|
34
38
|
const subdirPath = path.join(dir, subdir.name);
|
|
35
|
-
const childRoutes = await walkDirectory(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const childRoutes = await walkDirectory(
|
|
40
|
+
subdirPath,
|
|
41
|
+
baseDir,
|
|
42
|
+
[...segments, segment],
|
|
43
|
+
currentLayouts
|
|
44
|
+
);
|
|
39
45
|
routes.push(...childRoutes);
|
|
40
46
|
}
|
|
41
47
|
return routes;
|
|
@@ -98,9 +104,12 @@ async function generateManifest(routes, outFile, routesDir) {
|
|
|
98
104
|
const adjustedRoutes = JSON.stringify(routes, null, 2).replace(/"component": "(.+?)"/g, (match, p1) => {
|
|
99
105
|
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
100
106
|
return `"component": () => import("./${importPath}")`;
|
|
101
|
-
}).replace(/"
|
|
102
|
-
const
|
|
103
|
-
|
|
107
|
+
}).replace(/"layouts": \[([\s\S]*?)\]/g, (match, layoutsContent) => {
|
|
108
|
+
const transformed = layoutsContent.replace(/"(.+?)"/g, (m, p1) => {
|
|
109
|
+
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
110
|
+
return `() => import("./${importPath}")`;
|
|
111
|
+
});
|
|
112
|
+
return `"layouts": [${transformed}]`;
|
|
104
113
|
}).replace(/"error": "(.+?)"/g, (match, p1) => {
|
|
105
114
|
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
106
115
|
return `"error": () => import("./${importPath}")`;
|