@gyoll/builder 0.1.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 +31 -6
- package/build-output/builder.js +31 -6
- package/package.json +1 -1
package/build-output/builder.cjs
CHANGED
|
@@ -69,10 +69,12 @@ function collectRouteFiles(files, dir) {
|
|
|
69
69
|
error: null,
|
|
70
70
|
loading: null
|
|
71
71
|
};
|
|
72
|
+
const foundPages = [];
|
|
72
73
|
for (const file of files) {
|
|
73
74
|
const name = file.name;
|
|
74
75
|
const fullPath = import_path.default.join(dir, name);
|
|
75
|
-
if (/^page\.(jsx?|tsx?)$/.test(name)) {
|
|
76
|
+
if (/^(page|index)\.(jsx?|tsx?)$/.test(name)) {
|
|
77
|
+
foundPages.push(name);
|
|
76
78
|
routeFiles.page = fullPath;
|
|
77
79
|
} else if (/^layout\.(jsx?|tsx?)$/.test(name)) {
|
|
78
80
|
routeFiles.layout = fullPath;
|
|
@@ -82,6 +84,14 @@ function collectRouteFiles(files, dir) {
|
|
|
82
84
|
routeFiles.loading = fullPath;
|
|
83
85
|
}
|
|
84
86
|
}
|
|
87
|
+
if (foundPages.length > 1) {
|
|
88
|
+
console.warn(
|
|
89
|
+
`\u26A0\uFE0F Warning: Multiple page files found in ${dir}:
|
|
90
|
+
${foundPages.join(", ")}
|
|
91
|
+
Using: ${import_path.default.basename(routeFiles.page)}
|
|
92
|
+
Please use only one page file per directory.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
85
95
|
return routeFiles;
|
|
86
96
|
}
|
|
87
97
|
function parseSegment(segment) {
|
|
@@ -104,9 +114,24 @@ function buildRoutePath(segments) {
|
|
|
104
114
|
}
|
|
105
115
|
return "/" + filtered.join("/");
|
|
106
116
|
}
|
|
107
|
-
async function generateManifest(routes, outFile) {
|
|
108
|
-
const
|
|
109
|
-
|
|
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
|
+
});
|
|
133
|
+
const content = `// Auto-generated by @gyoll/builder - DO NOT EDIT
|
|
134
|
+
export const routes = ${adjustedRoutes};
|
|
110
135
|
`;
|
|
111
136
|
await import_promises.default.writeFile(outFile, content, "utf-8");
|
|
112
137
|
}
|
|
@@ -119,7 +144,7 @@ var args = process.argv.slice(2);
|
|
|
119
144
|
var command = args[0];
|
|
120
145
|
function parseArgs(args2) {
|
|
121
146
|
const options2 = {
|
|
122
|
-
dir: "./src/
|
|
147
|
+
dir: "./src/pages",
|
|
123
148
|
out: "./src/gyoll-manifest.js",
|
|
124
149
|
version: false
|
|
125
150
|
};
|
|
@@ -139,7 +164,7 @@ async function build(options2) {
|
|
|
139
164
|
const outFile = import_path2.default.resolve(options2.out);
|
|
140
165
|
console.log(`Scanning routes in ${routesDir}...`);
|
|
141
166
|
const routes = await scanRoutes(routesDir);
|
|
142
|
-
await generateManifest(routes, outFile);
|
|
167
|
+
await generateManifest(routes, outFile, routesDir);
|
|
143
168
|
console.log(`\u2713 Generated ${outFile}`);
|
|
144
169
|
}
|
|
145
170
|
async function watch(options2) {
|
package/build-output/builder.js
CHANGED
|
@@ -47,10 +47,12 @@ function collectRouteFiles(files, dir) {
|
|
|
47
47
|
error: null,
|
|
48
48
|
loading: null
|
|
49
49
|
};
|
|
50
|
+
const foundPages = [];
|
|
50
51
|
for (const file of files) {
|
|
51
52
|
const name = file.name;
|
|
52
53
|
const fullPath = path.join(dir, name);
|
|
53
|
-
if (/^page\.(jsx?|tsx?)$/.test(name)) {
|
|
54
|
+
if (/^(page|index)\.(jsx?|tsx?)$/.test(name)) {
|
|
55
|
+
foundPages.push(name);
|
|
54
56
|
routeFiles.page = fullPath;
|
|
55
57
|
} else if (/^layout\.(jsx?|tsx?)$/.test(name)) {
|
|
56
58
|
routeFiles.layout = fullPath;
|
|
@@ -60,6 +62,14 @@ function collectRouteFiles(files, dir) {
|
|
|
60
62
|
routeFiles.loading = fullPath;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
65
|
+
if (foundPages.length > 1) {
|
|
66
|
+
console.warn(
|
|
67
|
+
`\u26A0\uFE0F Warning: Multiple page files found in ${dir}:
|
|
68
|
+
${foundPages.join(", ")}
|
|
69
|
+
Using: ${path.basename(routeFiles.page)}
|
|
70
|
+
Please use only one page file per directory.`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
63
73
|
return routeFiles;
|
|
64
74
|
}
|
|
65
75
|
function parseSegment(segment) {
|
|
@@ -82,9 +92,24 @@ function buildRoutePath(segments) {
|
|
|
82
92
|
}
|
|
83
93
|
return "/" + filtered.join("/");
|
|
84
94
|
}
|
|
85
|
-
async function generateManifest(routes, outFile) {
|
|
86
|
-
const
|
|
87
|
-
|
|
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
|
+
});
|
|
111
|
+
const content = `// Auto-generated by @gyoll/builder - DO NOT EDIT
|
|
112
|
+
export const routes = ${adjustedRoutes};
|
|
88
113
|
`;
|
|
89
114
|
await fs.writeFile(outFile, content, "utf-8");
|
|
90
115
|
}
|
|
@@ -97,7 +122,7 @@ var args = process.argv.slice(2);
|
|
|
97
122
|
var command = args[0];
|
|
98
123
|
function parseArgs(args2) {
|
|
99
124
|
const options2 = {
|
|
100
|
-
dir: "./src/
|
|
125
|
+
dir: "./src/pages",
|
|
101
126
|
out: "./src/gyoll-manifest.js",
|
|
102
127
|
version: false
|
|
103
128
|
};
|
|
@@ -117,7 +142,7 @@ async function build(options2) {
|
|
|
117
142
|
const outFile = path2.resolve(options2.out);
|
|
118
143
|
console.log(`Scanning routes in ${routesDir}...`);
|
|
119
144
|
const routes = await scanRoutes(routesDir);
|
|
120
|
-
await generateManifest(routes, outFile);
|
|
145
|
+
await generateManifest(routes, outFile, routesDir);
|
|
121
146
|
console.log(`\u2713 Generated ${outFile}`);
|
|
122
147
|
}
|
|
123
148
|
async function watch(options2) {
|