forked from Lilly-Protocol/lily-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-route.mjs
More file actions
executable file
Β·136 lines (112 loc) Β· 3.94 KB
/
Copy pathadd-route.mjs
File metadata and controls
executable file
Β·136 lines (112 loc) Β· 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env node
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";
import { createInterface } from "readline";
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = resolve(__dirname, "..");
const VALID_SECTIONS = ["marketing", "auth", "legal", "docs", "dashboard"];
const rl = createInterface({
input: process.stdin,
output: process.stdout,
});
function ask(question) {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer.trim());
});
});
}
async function main() {
console.log("π£οΈ Lily Protocol Route Scaffolding Generator\n");
const id = await ask("Route ID (kebab-case, e.g. 'pricing'): ");
if (!id || !/^[a-z0-9-]+$/.test(id)) {
console.error("β Invalid ID. Use lowercase kebab-case.");
process.exit(1);
}
const title = await ask("Page Title (e.g. 'Pricing'): ");
if (!title) {
console.error("β Title is required.");
process.exit(1);
}
const path = await ask("Route Path (e.g. '/pricing' or '/app/settings/billing'): ");
if (!path || !path.startsWith("/")) {
console.error("β Path must start with /.");
process.exit(1);
}
console.log(`\nAvailable sections: ${VALID_SECTIONS.join(", ")}`);
const section = await ask("Section key: ");
if (!VALID_SECTIONS.includes(section)) {
console.error(`β Invalid section. Must be one of: ${VALID_SECTIONS.join(", ")}`);
process.exit(1);
}
const purpose = await ask("Purpose (one-liner description): ");
const includeInSitemap = (await ask("Include in sitemap? (y/N): ")).toLowerCase() === "y";
// Generate page file content
const pageContent = `import { createScaffoldPage, createScaffoldMetadata } from "@/features/scaffold/page-factory";
export default createScaffoldPage("${id}");
export const metadata = createScaffoldMetadata("${id}");
`;
// Determine file path based on section
let pageDir;
switch (section) {
case "marketing":
pageDir = `src/app/(marketing)/${id.replace(/^\//, "")}`;
break;
case "auth":
pageDir = `src/app/(auth)/${id.replace(/^\//, "")}`;
break;
case "legal":
case "docs":
pageDir = `src/app/(support)/${id.replace(/^\//, "")}`;
break;
case "dashboard":
pageDir = `src/app/app/${id.replace(/^\/app\//, "").replace(/^\//, "")}`;
break;
default:
pageDir = `src/app/${id}`;
}
const pageFilePath = `${pageDir}/page.tsx`;
// Registry entry to insert
const registryEntry = ` {
id: "${id}",
title: "${title}",
path: "${path}",
section: "${section}",
purpose: "${purpose || "TODO: Describe the purpose of this route."}",
figmaScope: "TODO: Define the Figma scope for this route.",
implementationAreas: [
"TODO: Define implementation areas",
],
includeInSitemap: ${includeInSitemap},
},`;
console.log("\nβ
Generated scaffold configuration:\n");
console.log("π Page file:", pageFilePath);
console.log("---");
console.log(pageContent);
console.log("---\n");
console.log("π Add this entry to src/config/routes.ts (routeScaffolds array):\n");
console.log(registryEntry);
console.log("");
console.log("π Update src/types/site.ts StaticSiteRoute union to include:");
console.log(` | "${path}"`);
console.log("");
console.log("π§ͺ Update src/config/routes.test.ts route count assertion if needed.");
console.log("");
// Optionally write the page file
const writeFile = (await ask(`Write page file to ${pageFilePath}? (y/N): `)).toLowerCase() === "y";
if (writeFile) {
const fullPath = resolve(ROOT, pageFilePath);
const dir = dirname(fullPath);
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
writeFileSync(fullPath, pageContent, "utf-8");
console.log(`β
Written: ${fullPath}`);
}
rl.close();
}
main().catch((err) => {
console.error(err);
process.exit(1);
});