@gyoll/builder 0.3.0 → 0.4.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 +18 -3
- package/build-output/builder.js +18 -3
- package/package.json +1 -1
package/build-output/builder.cjs
CHANGED
|
@@ -114,9 +114,24 @@ function buildRoutePath(segments) {
|
|
|
114
114
|
}
|
|
115
115
|
return "/" + filtered.join("/");
|
|
116
116
|
}
|
|
117
|
-
async function generateManifest(routes, outFile) {
|
|
117
|
+
async function generateManifest(routes, outFile, routesDir) {
|
|
118
|
+
const outDir = import_path.default.dirname(outFile);
|
|
119
|
+
const relativeRoutesDir = import_path.default.relative(outDir, routesDir);
|
|
120
|
+
const adjustedRoutes = JSON.stringify(routes, null, 2).replace(/"component": "(.+?)"/g, (match, p1) => {
|
|
121
|
+
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
122
|
+
return `"component": () => import("./${importPath}")`;
|
|
123
|
+
}).replace(/"layout": "(.+?)"/g, (match, p1) => {
|
|
124
|
+
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
125
|
+
return `"layout": () => import("./${importPath}")`;
|
|
126
|
+
}).replace(/"error": "(.+?)"/g, (match, p1) => {
|
|
127
|
+
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
128
|
+
return `"error": () => import("./${importPath}")`;
|
|
129
|
+
}).replace(/"loading": "(.+?)"/g, (match, p1) => {
|
|
130
|
+
const importPath = import_path.default.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
131
|
+
return `"loading": () => import("./${importPath}")`;
|
|
132
|
+
});
|
|
118
133
|
const content = `// Auto-generated by @gyoll/builder - DO NOT EDIT
|
|
119
|
-
export const routes = ${
|
|
134
|
+
export const routes = ${adjustedRoutes};
|
|
120
135
|
`;
|
|
121
136
|
await import_promises.default.writeFile(outFile, content, "utf-8");
|
|
122
137
|
}
|
|
@@ -149,7 +164,7 @@ async function build(options2) {
|
|
|
149
164
|
const outFile = import_path2.default.resolve(options2.out);
|
|
150
165
|
console.log(`Scanning routes in ${routesDir}...`);
|
|
151
166
|
const routes = await scanRoutes(routesDir);
|
|
152
|
-
await generateManifest(routes, outFile);
|
|
167
|
+
await generateManifest(routes, outFile, routesDir);
|
|
153
168
|
console.log(`\u2713 Generated ${outFile}`);
|
|
154
169
|
}
|
|
155
170
|
async function watch(options2) {
|
package/build-output/builder.js
CHANGED
|
@@ -92,9 +92,24 @@ function buildRoutePath(segments) {
|
|
|
92
92
|
}
|
|
93
93
|
return "/" + filtered.join("/");
|
|
94
94
|
}
|
|
95
|
-
async function generateManifest(routes, outFile) {
|
|
95
|
+
async function generateManifest(routes, outFile, routesDir) {
|
|
96
|
+
const outDir = path.dirname(outFile);
|
|
97
|
+
const relativeRoutesDir = path.relative(outDir, routesDir);
|
|
98
|
+
const adjustedRoutes = JSON.stringify(routes, null, 2).replace(/"component": "(.+?)"/g, (match, p1) => {
|
|
99
|
+
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
100
|
+
return `"component": () => import("./${importPath}")`;
|
|
101
|
+
}).replace(/"layout": "(.+?)"/g, (match, p1) => {
|
|
102
|
+
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
103
|
+
return `"layout": () => import("./${importPath}")`;
|
|
104
|
+
}).replace(/"error": "(.+?)"/g, (match, p1) => {
|
|
105
|
+
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
106
|
+
return `"error": () => import("./${importPath}")`;
|
|
107
|
+
}).replace(/"loading": "(.+?)"/g, (match, p1) => {
|
|
108
|
+
const importPath = path.join(relativeRoutesDir, p1).replace(/\\/g, "/");
|
|
109
|
+
return `"loading": () => import("./${importPath}")`;
|
|
110
|
+
});
|
|
96
111
|
const content = `// Auto-generated by @gyoll/builder - DO NOT EDIT
|
|
97
|
-
export const routes = ${
|
|
112
|
+
export const routes = ${adjustedRoutes};
|
|
98
113
|
`;
|
|
99
114
|
await fs.writeFile(outFile, content, "utf-8");
|
|
100
115
|
}
|
|
@@ -127,7 +142,7 @@ async function build(options2) {
|
|
|
127
142
|
const outFile = path2.resolve(options2.out);
|
|
128
143
|
console.log(`Scanning routes in ${routesDir}...`);
|
|
129
144
|
const routes = await scanRoutes(routesDir);
|
|
130
|
-
await generateManifest(routes, outFile);
|
|
145
|
+
await generateManifest(routes, outFile, routesDir);
|
|
131
146
|
console.log(`\u2713 Generated ${outFile}`);
|
|
132
147
|
}
|
|
133
148
|
async function watch(options2) {
|