@gyoll/builder 0.1.0 → 0.3.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 +13 -3
- package/build-output/builder.js +13 -3
- 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) {
|
|
@@ -105,7 +115,7 @@ function buildRoutePath(segments) {
|
|
|
105
115
|
return "/" + filtered.join("/");
|
|
106
116
|
}
|
|
107
117
|
async function generateManifest(routes, outFile) {
|
|
108
|
-
const content = `// Auto-generated by @gyoll/
|
|
118
|
+
const content = `// Auto-generated by @gyoll/builder - DO NOT EDIT
|
|
109
119
|
export const routes = ${JSON.stringify(routes, null, 2).replace(/"component": "(.+?)"/g, '"component": () => import("./$1")').replace(/"layout": "(.+?)"/g, '"layout": () => import("./$1")').replace(/"error": "(.+?)"/g, '"error": () => import("./$1")').replace(/"loading": "(.+?)"/g, '"loading": () => import("./$1")')};
|
|
110
120
|
`;
|
|
111
121
|
await import_promises.default.writeFile(outFile, content, "utf-8");
|
|
@@ -119,7 +129,7 @@ var args = process.argv.slice(2);
|
|
|
119
129
|
var command = args[0];
|
|
120
130
|
function parseArgs(args2) {
|
|
121
131
|
const options2 = {
|
|
122
|
-
dir: "./src/
|
|
132
|
+
dir: "./src/pages",
|
|
123
133
|
out: "./src/gyoll-manifest.js",
|
|
124
134
|
version: false
|
|
125
135
|
};
|
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) {
|
|
@@ -83,7 +93,7 @@ function buildRoutePath(segments) {
|
|
|
83
93
|
return "/" + filtered.join("/");
|
|
84
94
|
}
|
|
85
95
|
async function generateManifest(routes, outFile) {
|
|
86
|
-
const content = `// Auto-generated by @gyoll/
|
|
96
|
+
const content = `// Auto-generated by @gyoll/builder - DO NOT EDIT
|
|
87
97
|
export const routes = ${JSON.stringify(routes, null, 2).replace(/"component": "(.+?)"/g, '"component": () => import("./$1")').replace(/"layout": "(.+?)"/g, '"layout": () => import("./$1")').replace(/"error": "(.+?)"/g, '"error": () => import("./$1")').replace(/"loading": "(.+?)"/g, '"loading": () => import("./$1")')};
|
|
88
98
|
`;
|
|
89
99
|
await fs.writeFile(outFile, content, "utf-8");
|
|
@@ -97,7 +107,7 @@ var args = process.argv.slice(2);
|
|
|
97
107
|
var command = args[0];
|
|
98
108
|
function parseArgs(args2) {
|
|
99
109
|
const options2 = {
|
|
100
|
-
dir: "./src/
|
|
110
|
+
dir: "./src/pages",
|
|
101
111
|
out: "./src/gyoll-manifest.js",
|
|
102
112
|
version: false
|
|
103
113
|
};
|