@gyoll/builder 0.5.0 → 0.7.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 +16 -2
- package/build-output/builder.js +16 -2
- package/package.json +1 -1
package/build-output/builder.cjs
CHANGED
|
@@ -29,7 +29,7 @@ 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 = [], parentLayouts = []) {
|
|
32
|
+
async function walkDirectory(dir, baseDir, segments = [], parentLayouts = [], activeGuard = null) {
|
|
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());
|
|
@@ -38,6 +38,10 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
38
38
|
if (routeFiles.layout) {
|
|
39
39
|
currentLayouts.push(import_path.default.relative(baseDir, routeFiles.layout));
|
|
40
40
|
}
|
|
41
|
+
let currentGuard = activeGuard;
|
|
42
|
+
if (routeFiles.guard) {
|
|
43
|
+
currentGuard = import_path.default.relative(baseDir, routeFiles.guard);
|
|
44
|
+
}
|
|
41
45
|
const routes = [];
|
|
42
46
|
if (routeFiles.page) {
|
|
43
47
|
const route = {
|
|
@@ -47,6 +51,9 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
47
51
|
if (currentLayouts.length > 0) {
|
|
48
52
|
route.layouts = [...currentLayouts];
|
|
49
53
|
}
|
|
54
|
+
if (currentGuard) {
|
|
55
|
+
route.guard = import_path.default.relative(baseDir, currentGuard);
|
|
56
|
+
}
|
|
50
57
|
if (routeFiles.error) {
|
|
51
58
|
route.error = import_path.default.relative(baseDir, routeFiles.error);
|
|
52
59
|
}
|
|
@@ -62,7 +69,8 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
62
69
|
subdirPath,
|
|
63
70
|
baseDir,
|
|
64
71
|
[...segments, segment],
|
|
65
|
-
currentLayouts
|
|
72
|
+
currentLayouts,
|
|
73
|
+
currentGuard
|
|
66
74
|
);
|
|
67
75
|
routes.push(...childRoutes);
|
|
68
76
|
}
|
|
@@ -71,6 +79,7 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
71
79
|
function collectRouteFiles(files, dir) {
|
|
72
80
|
const routeFiles = {
|
|
73
81
|
page: null,
|
|
82
|
+
guard: null,
|
|
74
83
|
layout: null,
|
|
75
84
|
error: null,
|
|
76
85
|
loading: null
|
|
@@ -84,6 +93,8 @@ function collectRouteFiles(files, dir) {
|
|
|
84
93
|
routeFiles.page = fullPath;
|
|
85
94
|
} else if (/^layout\.(jsx?|tsx?)$/.test(name)) {
|
|
86
95
|
routeFiles.layout = fullPath;
|
|
96
|
+
} else if (/^guard\.(jsx?|tsx?)$/.test(name)) {
|
|
97
|
+
routeFiles.guard = fullPath;
|
|
87
98
|
} else if (/^error\.(jsx?|tsx?)$/.test(name)) {
|
|
88
99
|
routeFiles.error = fullPath;
|
|
89
100
|
} else if (/^loading\.(jsx?|tsx?)$/.test(name)) {
|
|
@@ -132,6 +143,9 @@ async function generateManifest(routes, outFile, routesDir) {
|
|
|
132
143
|
return `() => import("./${importPath}")`;
|
|
133
144
|
});
|
|
134
145
|
return `"layouts": [${transformed}]`;
|
|
146
|
+
}).replace(/"guard": "(.+?)"/g, (match, p1) => {
|
|
147
|
+
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
148
|
+
return `"guard": () => import("./${importPath}")`;
|
|
135
149
|
}).replace(/"error": "(.+?)"/g, (match, p1) => {
|
|
136
150
|
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
137
151
|
return `"error": () => import("./${importPath}")`;
|
package/build-output/builder.js
CHANGED
|
@@ -7,7 +7,7 @@ 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 = [], parentLayouts = []) {
|
|
10
|
+
async function walkDirectory(dir, baseDir, segments = [], parentLayouts = [], activeGuard = null) {
|
|
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());
|
|
@@ -16,6 +16,10 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
16
16
|
if (routeFiles.layout) {
|
|
17
17
|
currentLayouts.push(path.relative(baseDir, routeFiles.layout));
|
|
18
18
|
}
|
|
19
|
+
let currentGuard = activeGuard;
|
|
20
|
+
if (routeFiles.guard) {
|
|
21
|
+
currentGuard = path.relative(baseDir, routeFiles.guard);
|
|
22
|
+
}
|
|
19
23
|
const routes = [];
|
|
20
24
|
if (routeFiles.page) {
|
|
21
25
|
const route = {
|
|
@@ -25,6 +29,9 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
25
29
|
if (currentLayouts.length > 0) {
|
|
26
30
|
route.layouts = [...currentLayouts];
|
|
27
31
|
}
|
|
32
|
+
if (currentGuard) {
|
|
33
|
+
route.guard = path.relative(baseDir, currentGuard);
|
|
34
|
+
}
|
|
28
35
|
if (routeFiles.error) {
|
|
29
36
|
route.error = path.relative(baseDir, routeFiles.error);
|
|
30
37
|
}
|
|
@@ -40,7 +47,8 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
40
47
|
subdirPath,
|
|
41
48
|
baseDir,
|
|
42
49
|
[...segments, segment],
|
|
43
|
-
currentLayouts
|
|
50
|
+
currentLayouts,
|
|
51
|
+
currentGuard
|
|
44
52
|
);
|
|
45
53
|
routes.push(...childRoutes);
|
|
46
54
|
}
|
|
@@ -49,6 +57,7 @@ async function walkDirectory(dir, baseDir, segments = [], parentLayouts = []) {
|
|
|
49
57
|
function collectRouteFiles(files, dir) {
|
|
50
58
|
const routeFiles = {
|
|
51
59
|
page: null,
|
|
60
|
+
guard: null,
|
|
52
61
|
layout: null,
|
|
53
62
|
error: null,
|
|
54
63
|
loading: null
|
|
@@ -62,6 +71,8 @@ function collectRouteFiles(files, dir) {
|
|
|
62
71
|
routeFiles.page = fullPath;
|
|
63
72
|
} else if (/^layout\.(jsx?|tsx?)$/.test(name)) {
|
|
64
73
|
routeFiles.layout = fullPath;
|
|
74
|
+
} else if (/^guard\.(jsx?|tsx?)$/.test(name)) {
|
|
75
|
+
routeFiles.guard = fullPath;
|
|
65
76
|
} else if (/^error\.(jsx?|tsx?)$/.test(name)) {
|
|
66
77
|
routeFiles.error = fullPath;
|
|
67
78
|
} else if (/^loading\.(jsx?|tsx?)$/.test(name)) {
|
|
@@ -110,6 +121,9 @@ async function generateManifest(routes, outFile, routesDir) {
|
|
|
110
121
|
return `() => import("./${importPath}")`;
|
|
111
122
|
});
|
|
112
123
|
return `"layouts": [${transformed}]`;
|
|
124
|
+
}).replace(/"guard": "(.+?)"/g, (match, p1) => {
|
|
125
|
+
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
126
|
+
return `"guard": () => import("./${importPath}")`;
|
|
113
127
|
}).replace(/"error": "(.+?)"/g, (match, p1) => {
|
|
114
128
|
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
115
129
|
return `"error": () => import("./${importPath}")`;
|