@pithyjs/vite-plugin 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +237 -0
- package/dist/aotCodegen/generateBindings.d.ts +184 -0
- package/dist/aotCodegen/generateBindings.d.ts.map +1 -0
- package/dist/aotCodegen/generateBindings.js +326 -0
- package/dist/aotCodegen/generateBindings.js.map +1 -0
- package/dist/aotCodegen/generateDomFactory.d.ts +59 -0
- package/dist/aotCodegen/generateDomFactory.d.ts.map +1 -0
- package/dist/aotCodegen/generateDomFactory.js +302 -0
- package/dist/aotCodegen/generateDomFactory.js.map +1 -0
- package/dist/aotCodegen/index.d.ts +18 -0
- package/dist/aotCodegen/index.d.ts.map +1 -0
- package/dist/aotCodegen/index.js +17 -0
- package/dist/aotCodegen/index.js.map +1 -0
- package/dist/aotCodegen/serializeNode.d.ts +74 -0
- package/dist/aotCodegen/serializeNode.d.ts.map +1 -0
- package/dist/aotCodegen/serializeNode.js +169 -0
- package/dist/aotCodegen/serializeNode.js.map +1 -0
- package/dist/aotCodegen/structuralCodegen.d.ts +38 -0
- package/dist/aotCodegen/structuralCodegen.d.ts.map +1 -0
- package/dist/aotCodegen/structuralCodegen.js +56 -0
- package/dist/aotCodegen/structuralCodegen.js.map +1 -0
- package/dist/aotCodegen/utils.d.ts +38 -0
- package/dist/aotCodegen/utils.d.ts.map +1 -0
- package/dist/aotCodegen/utils.js +48 -0
- package/dist/aotCodegen/utils.js.map +1 -0
- package/dist/babelPlugin/babelPlugin.d.ts +44 -0
- package/dist/babelPlugin/babelPlugin.d.ts.map +1 -0
- package/dist/babelPlugin/babelPlugin.js +392 -0
- package/dist/babelPlugin/babelPlugin.js.map +1 -0
- package/dist/babelPlugin/extractOriginalTagNames.d.ts +20 -0
- package/dist/babelPlugin/extractOriginalTagNames.d.ts.map +1 -0
- package/dist/babelPlugin/extractOriginalTagNames.js +44 -0
- package/dist/babelPlugin/extractOriginalTagNames.js.map +1 -0
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts +26 -0
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts.map +1 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js +206 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js.map +1 -0
- package/dist/buildPlugin/plugin.d.ts +79 -0
- package/dist/buildPlugin/plugin.d.ts.map +1 -0
- package/dist/buildPlugin/plugin.js +142 -0
- package/dist/buildPlugin/plugin.js.map +1 -0
- package/dist/designSystemPlugin/collector.d.ts +63 -0
- package/dist/designSystemPlugin/collector.d.ts.map +1 -0
- package/dist/designSystemPlugin/collector.js +175 -0
- package/dist/designSystemPlugin/collector.js.map +1 -0
- package/dist/designSystemPlugin/cssTokens.d.ts +34 -0
- package/dist/designSystemPlugin/cssTokens.d.ts.map +1 -0
- package/dist/designSystemPlugin/cssTokens.js +56 -0
- package/dist/designSystemPlugin/cssTokens.js.map +1 -0
- package/dist/designSystemPlugin/enumerate.d.ts +24 -0
- package/dist/designSystemPlugin/enumerate.d.ts.map +1 -0
- package/dist/designSystemPlugin/enumerate.js +430 -0
- package/dist/designSystemPlugin/enumerate.js.map +1 -0
- package/dist/designSystemPlugin/extractor.d.ts +95 -0
- package/dist/designSystemPlugin/extractor.d.ts.map +1 -0
- package/dist/designSystemPlugin/extractor.js +150 -0
- package/dist/designSystemPlugin/extractor.js.map +1 -0
- package/dist/designSystemPlugin/generator.d.ts +33 -0
- package/dist/designSystemPlugin/generator.d.ts.map +1 -0
- package/dist/designSystemPlugin/generator.js +256 -0
- package/dist/designSystemPlugin/generator.js.map +1 -0
- package/dist/designSystemPlugin/index.d.ts +18 -0
- package/dist/designSystemPlugin/index.d.ts.map +1 -0
- package/dist/designSystemPlugin/index.js +19 -0
- package/dist/designSystemPlugin/index.js.map +1 -0
- package/dist/designSystemPlugin/patterns/a11y.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/a11y.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/a11y.js +230 -0
- package/dist/designSystemPlugin/patterns/a11y.js.map +1 -0
- package/dist/designSystemPlugin/patterns/borders.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/borders.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/borders.js +474 -0
- package/dist/designSystemPlugin/patterns/borders.js.map +1 -0
- package/dist/designSystemPlugin/patterns/colors.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/colors.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/colors.js +134 -0
- package/dist/designSystemPlugin/patterns/colors.js.map +1 -0
- package/dist/designSystemPlugin/patterns/iconography.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/iconography.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/iconography.js +61 -0
- package/dist/designSystemPlugin/patterns/iconography.js.map +1 -0
- package/dist/designSystemPlugin/patterns/index.d.ts +22 -0
- package/dist/designSystemPlugin/patterns/index.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/index.js +44 -0
- package/dist/designSystemPlugin/patterns/index.js.map +1 -0
- package/dist/designSystemPlugin/patterns/layout.d.ts +34 -0
- package/dist/designSystemPlugin/patterns/layout.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/layout.js +917 -0
- package/dist/designSystemPlugin/patterns/layout.js.map +1 -0
- package/dist/designSystemPlugin/patterns/motion.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/motion.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/motion.js +162 -0
- package/dist/designSystemPlugin/patterns/motion.js.map +1 -0
- package/dist/designSystemPlugin/patterns/radius.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/radius.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/radius.js +107 -0
- package/dist/designSystemPlugin/patterns/radius.js.map +1 -0
- package/dist/designSystemPlugin/patterns/shadows.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/shadows.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/shadows.js +161 -0
- package/dist/designSystemPlugin/patterns/shadows.js.map +1 -0
- package/dist/designSystemPlugin/patterns/smartContainer.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/smartContainer.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/smartContainer.js +96 -0
- package/dist/designSystemPlugin/patterns/smartContainer.js.map +1 -0
- package/dist/designSystemPlugin/patterns/spacing.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/spacing.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/spacing.js +333 -0
- package/dist/designSystemPlugin/patterns/spacing.js.map +1 -0
- package/dist/designSystemPlugin/patterns/typography.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/typography.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/typography.js +416 -0
- package/dist/designSystemPlugin/patterns/typography.js.map +1 -0
- package/dist/designSystemPlugin/plugin.d.ts +39 -0
- package/dist/designSystemPlugin/plugin.d.ts.map +1 -0
- package/dist/designSystemPlugin/plugin.js +351 -0
- package/dist/designSystemPlugin/plugin.js.map +1 -0
- package/dist/designSystemPlugin/types.d.ts +156 -0
- package/dist/designSystemPlugin/types.d.ts.map +1 -0
- package/dist/designSystemPlugin/types.js +49 -0
- package/dist/designSystemPlugin/types.js.map +1 -0
- package/dist/htmlTransform/htmlTransform.d.ts +47 -0
- package/dist/htmlTransform/htmlTransform.d.ts.map +1 -0
- package/dist/htmlTransform/htmlTransform.js +86 -0
- package/dist/htmlTransform/htmlTransform.js.map +1 -0
- package/dist/iconsPlugin/index.d.ts +18 -0
- package/dist/iconsPlugin/index.d.ts.map +1 -0
- package/dist/iconsPlugin/index.js +17 -0
- package/dist/iconsPlugin/index.js.map +1 -0
- package/dist/iconsPlugin/optimize.d.ts +54 -0
- package/dist/iconsPlugin/optimize.d.ts.map +1 -0
- package/dist/iconsPlugin/optimize.js +253 -0
- package/dist/iconsPlugin/optimize.js.map +1 -0
- package/dist/iconsPlugin/plugin.d.ts +49 -0
- package/dist/iconsPlugin/plugin.d.ts.map +1 -0
- package/dist/iconsPlugin/plugin.js +242 -0
- package/dist/iconsPlugin/plugin.js.map +1 -0
- package/dist/iconsPlugin/types.d.ts +49 -0
- package/dist/iconsPlugin/types.d.ts.map +1 -0
- package/dist/iconsPlugin/types.js +30 -0
- package/dist/iconsPlugin/types.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/pithyPlugin/plugin.d.ts +38 -0
- package/dist/pithyPlugin/plugin.d.ts.map +1 -0
- package/dist/pithyPlugin/plugin.js +119 -0
- package/dist/pithyPlugin/plugin.js.map +1 -0
- package/dist/routerPlugin/manifest.d.ts +33 -0
- package/dist/routerPlugin/manifest.d.ts.map +1 -0
- package/dist/routerPlugin/manifest.js +223 -0
- package/dist/routerPlugin/manifest.js.map +1 -0
- package/dist/routerPlugin/plugin.d.ts +51 -0
- package/dist/routerPlugin/plugin.d.ts.map +1 -0
- package/dist/routerPlugin/plugin.js +164 -0
- package/dist/routerPlugin/plugin.js.map +1 -0
- package/dist/routerPlugin/scanner.d.ts +69 -0
- package/dist/routerPlugin/scanner.d.ts.map +1 -0
- package/dist/routerPlugin/scanner.js +290 -0
- package/dist/routerPlugin/scanner.js.map +1 -0
- package/dist/ssrPlugin/plugin.d.ts +76 -0
- package/dist/ssrPlugin/plugin.d.ts.map +1 -0
- package/dist/ssrPlugin/plugin.js +439 -0
- package/dist/ssrPlugin/plugin.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-router.manifest",
|
|
4
|
+
"title": "Route Manifest Generator",
|
|
5
|
+
"category": "compiler",
|
|
6
|
+
"description": "Generates typed TypeScript route manifests and CLI-formatted route tables from a route tree.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "manifest.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to get correct filename for route file types
|
|
18
|
+
*/
|
|
19
|
+
function filenameFor(type) {
|
|
20
|
+
return `${type}.ts`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Generate TypeScript code for the route manifest
|
|
24
|
+
* Creates virtual:pithy/routes.gen module with typed RouteNode tree
|
|
25
|
+
*/
|
|
26
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.manifest","name":"generateManifest","stability":"stable","signature":"(routes: RouteNode[]) => string"} */
|
|
27
|
+
export function generateManifest(routes) {
|
|
28
|
+
const imports = generateImports(routes);
|
|
29
|
+
const routeTree = generateRouteTree(routes);
|
|
30
|
+
const manifest = `// Auto-generated route manifest - do not edit manually
|
|
31
|
+
// Generated at: ${new Date().toISOString()}
|
|
32
|
+
|
|
33
|
+
${imports}
|
|
34
|
+
|
|
35
|
+
/** @typedef {import("../../router/src/types").RouteNode} RouteNode */
|
|
36
|
+
/** @type {Array<RouteNode>} */
|
|
37
|
+
export const routes = ${routeTree};
|
|
38
|
+
|
|
39
|
+
// For TS consumers that import types:
|
|
40
|
+
export {};
|
|
41
|
+
`;
|
|
42
|
+
return manifest;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generate import statements for all route files
|
|
46
|
+
*/
|
|
47
|
+
function generateImports(routes) {
|
|
48
|
+
const imports = [];
|
|
49
|
+
const importMap = new Map();
|
|
50
|
+
let importCounter = 0;
|
|
51
|
+
// Collect all unique file paths and generate import names
|
|
52
|
+
for (const route of routes) {
|
|
53
|
+
for (const [type] of Object.entries(route.imports)) {
|
|
54
|
+
// Build the correct import path relative to the virtual module location
|
|
55
|
+
const segments = route.segments.length > 0 ? route.segments : [];
|
|
56
|
+
let importPath = '/src/routes';
|
|
57
|
+
if (segments.length > 0) {
|
|
58
|
+
// Convert segments back to file system format (keep route groups for file paths)
|
|
59
|
+
const fileSegments = segments.map((segment) => {
|
|
60
|
+
if (segment.startsWith(':')) {
|
|
61
|
+
return `[${segment.slice(1)}]`; // :id -> [id]
|
|
62
|
+
}
|
|
63
|
+
if (segment === '*') {
|
|
64
|
+
return '[...slug]'; // * -> [...slug]
|
|
65
|
+
}
|
|
66
|
+
return segment; // Keep route groups like (mkt) for file paths
|
|
67
|
+
});
|
|
68
|
+
if (fileSegments.length > 0) {
|
|
69
|
+
importPath += '/' + fileSegments.join('/');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const fullPath = `${importPath}/${filenameFor(type)}`;
|
|
73
|
+
if (!importMap.has(fullPath)) {
|
|
74
|
+
const importName = `route_${importCounter++}_${type}`;
|
|
75
|
+
importMap.set(fullPath, importName);
|
|
76
|
+
imports.push(`const ${importName} = () => import("${fullPath}");`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return imports.length > 0 ? imports.join('\n') : '// No imports needed';
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Generate the route tree structure
|
|
84
|
+
*/
|
|
85
|
+
function generateRouteTree(routes) {
|
|
86
|
+
// Build import map first
|
|
87
|
+
const importMap = new Map();
|
|
88
|
+
let importCounter = 0;
|
|
89
|
+
for (const route of routes) {
|
|
90
|
+
for (const [type] of Object.entries(route.imports)) {
|
|
91
|
+
const segments = route.segments.length > 0 ? route.segments : [];
|
|
92
|
+
let importPath = '/src/routes';
|
|
93
|
+
if (segments.length > 0) {
|
|
94
|
+
const fileSegments = segments.map((segment) => {
|
|
95
|
+
if (segment.startsWith(':')) {
|
|
96
|
+
return `[${segment.slice(1)}]`;
|
|
97
|
+
}
|
|
98
|
+
if (segment === '*') {
|
|
99
|
+
return '[...slug]';
|
|
100
|
+
}
|
|
101
|
+
return segment;
|
|
102
|
+
});
|
|
103
|
+
if (fileSegments.length > 0) {
|
|
104
|
+
importPath += '/' + fileSegments.join('/');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const fullPath = `${importPath}/${filenameFor(type)}`;
|
|
108
|
+
if (!importMap.has(fullPath)) {
|
|
109
|
+
const importName = `route_${importCounter++}_${type}`;
|
|
110
|
+
importMap.set(fullPath, importName);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const routeObjects = routes.map(route => generateRouteObject(route, importMap));
|
|
115
|
+
return `[\n${routeObjects.map(obj => ` ${obj}`).join(',\n')}\n]`;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generate a single route object
|
|
119
|
+
*/
|
|
120
|
+
function generateRouteObject(route, importMap) {
|
|
121
|
+
const imports = generateRouteImports(route, importMap);
|
|
122
|
+
const metadata = route.metadata
|
|
123
|
+
? JSON.stringify(route.metadata, null, 2)
|
|
124
|
+
: '{}';
|
|
125
|
+
return `{
|
|
126
|
+
id: ${JSON.stringify(route.id)},
|
|
127
|
+
pattern: ${JSON.stringify(route.pattern)},
|
|
128
|
+
path: ${JSON.stringify(route.path)},
|
|
129
|
+
segments: ${JSON.stringify(route.segments)},
|
|
130
|
+
params: ${JSON.stringify(route.params)},
|
|
131
|
+
imports: ${imports},
|
|
132
|
+
children: [],
|
|
133
|
+
metadata: ${metadata}
|
|
134
|
+
}`;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Generate imports object for a route
|
|
138
|
+
*/
|
|
139
|
+
function generateRouteImports(route, importMap) {
|
|
140
|
+
const importEntries = [];
|
|
141
|
+
// Generate import entries based on what imports exist
|
|
142
|
+
for (const [type] of Object.entries(route.imports)) {
|
|
143
|
+
// Build the correct import path relative to the virtual module location
|
|
144
|
+
const segments = route.segments.length > 0 ? route.segments : [];
|
|
145
|
+
let importPath = '/src/routes';
|
|
146
|
+
if (segments.length > 0) {
|
|
147
|
+
// Convert segments back to file system format (keep route groups for file paths)
|
|
148
|
+
const fileSegments = segments.map((segment) => {
|
|
149
|
+
if (segment.startsWith(':')) {
|
|
150
|
+
return `[${segment.slice(1)}]`; // :id -> [id]
|
|
151
|
+
}
|
|
152
|
+
if (segment === '*') {
|
|
153
|
+
return '[...slug]'; // * -> [...slug]
|
|
154
|
+
}
|
|
155
|
+
return segment; // Keep route groups like (mkt) for file paths
|
|
156
|
+
});
|
|
157
|
+
if (fileSegments.length > 0) {
|
|
158
|
+
importPath += '/' + fileSegments.join('/');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const fullPath = `${importPath}/${filenameFor(type)}`;
|
|
162
|
+
// Use the generated import constant if available
|
|
163
|
+
const importName = importMap.get(fullPath);
|
|
164
|
+
if (importName) {
|
|
165
|
+
importEntries.push(`${type}: ${importName}`);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// Fallback to inline import
|
|
169
|
+
importEntries.push(`${type}: () => import("${fullPath}")`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return `{\n ${importEntries.join(',\n ')}\n }`;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Generate CLI command output for route tree inspection
|
|
176
|
+
*/
|
|
177
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.manifest","name":"generateCliOutput","stability":"stable","signature":"(routes: RouteNode[]) => string"} */
|
|
178
|
+
export function generateCliOutput(routes) {
|
|
179
|
+
const lines = [];
|
|
180
|
+
lines.push('📁 Route Tree:');
|
|
181
|
+
lines.push('');
|
|
182
|
+
for (const route of routes) {
|
|
183
|
+
lines.push(`🔗 ${route.pattern}`);
|
|
184
|
+
lines.push(` ID: ${route.id}`);
|
|
185
|
+
lines.push(` Files: ${Object.keys(route.imports).join(', ')}`);
|
|
186
|
+
if (route.metadata?.isGroup) {
|
|
187
|
+
lines.push(' 🏷️ Uses route groups');
|
|
188
|
+
}
|
|
189
|
+
lines.push('');
|
|
190
|
+
}
|
|
191
|
+
return lines.join('\n');
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Validate generated manifest for common issues
|
|
195
|
+
*/
|
|
196
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.manifest","name":"validateManifest","stability":"stable","signature":"(routes: RouteNode[]) => string[]"} */
|
|
197
|
+
export function validateManifest(routes) {
|
|
198
|
+
const errors = [];
|
|
199
|
+
const patterns = new Set();
|
|
200
|
+
const ids = new Set();
|
|
201
|
+
for (const route of routes) {
|
|
202
|
+
// Check for duplicate patterns
|
|
203
|
+
if (patterns.has(route.pattern)) {
|
|
204
|
+
errors.push(`Duplicate route pattern: ${route.pattern}`);
|
|
205
|
+
}
|
|
206
|
+
patterns.add(route.pattern);
|
|
207
|
+
// Check for duplicate IDs
|
|
208
|
+
if (ids.has(route.id)) {
|
|
209
|
+
errors.push(`Duplicate route ID: ${route.id}`);
|
|
210
|
+
}
|
|
211
|
+
ids.add(route.id);
|
|
212
|
+
// Validate required page import
|
|
213
|
+
if (!route.imports.page) {
|
|
214
|
+
errors.push(`Route ${route.pattern} missing required page component`);
|
|
215
|
+
}
|
|
216
|
+
// Validate file paths exist (basic check)
|
|
217
|
+
if (!route.path) {
|
|
218
|
+
errors.push(`Route ${route.pattern} missing file path`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return errors;
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/routerPlugin/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAIF;;GAEG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,GAAG,IAAI,KAAK,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,4JAA4J;AAC5J,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAExC,MAAM,S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AC1D,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-router",
|
|
4
|
+
"title": "Vite Plugin for PithyJS Router",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "File-based routing plugin that scans a routes directory and generates a typed route manifest as a virtual module.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "experimental",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "plugin.test.ts" },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import type { Plugin } from 'vite';
|
|
17
|
+
/**
|
|
18
|
+
* Vite plugin options
|
|
19
|
+
*/
|
|
20
|
+
export interface PithyRouterPluginOptions {
|
|
21
|
+
/** Routes directory relative to project root */
|
|
22
|
+
routesDir?: string;
|
|
23
|
+
/** File extensions to scan */
|
|
24
|
+
extensions?: string[];
|
|
25
|
+
/** Enable TypeScript support */
|
|
26
|
+
typescript?: boolean;
|
|
27
|
+
/** Enable debug logging */
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Vite plugin for PithyJS file-based routing.
|
|
32
|
+
*
|
|
33
|
+
* Scans a routes directory for `page`, `layout`, `loading`, `error`,
|
|
34
|
+
* `loader`, and `config` files, then generates a typed route manifest
|
|
35
|
+
* exposed as the `virtual:pithy/routes.gen` virtual module.
|
|
36
|
+
*
|
|
37
|
+
* @param options - Plugin configuration for routes directory, extensions, and debug mode
|
|
38
|
+
* @returns A Vite plugin that provides file-based route generation
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { pithyRouter } from '@pithyjs/vite-plugin';
|
|
43
|
+
*
|
|
44
|
+
* export default defineConfig({
|
|
45
|
+
* plugins: [pithyRouter({ routesDir: 'src/routes' })],
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router","name":"pithyRouter","stability":"experimental","signature":"(options?: PithyRouterPluginOptions) => Plugin"} */
|
|
50
|
+
export declare function pithyRouter(options?: PithyRouterPluginOptions): Plugin;
|
|
51
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/routerPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AASnC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8BAA8B;IAC9B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,gCAAgC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,mKAAmK;AACnK,wBAAgB,WAAW,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAkK1E"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-router",
|
|
4
|
+
"title": "Vite Plugin for PithyJS Router",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "File-based routing plugin that scans a routes directory and generates a typed route manifest as a virtual module.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "experimental",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "plugin.test.ts" },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import { join } from 'path';
|
|
17
|
+
import { scanRoutes, buildRouteTree, validateRoutes } from './scanner';
|
|
18
|
+
import { generateManifest, generateCliOutput, validateManifest, } from './manifest';
|
|
19
|
+
/**
|
|
20
|
+
* Vite plugin for PithyJS file-based routing.
|
|
21
|
+
*
|
|
22
|
+
* Scans a routes directory for `page`, `layout`, `loading`, `error`,
|
|
23
|
+
* `loader`, and `config` files, then generates a typed route manifest
|
|
24
|
+
* exposed as the `virtual:pithy/routes.gen` virtual module.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Plugin configuration for routes directory, extensions, and debug mode
|
|
27
|
+
* @returns A Vite plugin that provides file-based route generation
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { pithyRouter } from '@pithyjs/vite-plugin';
|
|
32
|
+
*
|
|
33
|
+
* export default defineConfig({
|
|
34
|
+
* plugins: [pithyRouter({ routesDir: 'src/routes' })],
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router","name":"pithyRouter","stability":"experimental","signature":"(options?: PithyRouterPluginOptions) => Plugin"} */
|
|
39
|
+
export function pithyRouter(options = {}) {
|
|
40
|
+
const { routesDir = 'src/routes', extensions = ['ts', 'js'], typescript = true, debug = false, } = options;
|
|
41
|
+
let resolvedRoutesDir;
|
|
42
|
+
let cachedManifest = null;
|
|
43
|
+
// Helper function to generate route manifest
|
|
44
|
+
async function generateRouteManifest() {
|
|
45
|
+
try {
|
|
46
|
+
// Scan routes directory
|
|
47
|
+
const routeFiles = await scanRoutes({
|
|
48
|
+
routesDir: resolvedRoutesDir,
|
|
49
|
+
extensions,
|
|
50
|
+
typescript,
|
|
51
|
+
});
|
|
52
|
+
if (debug) {
|
|
53
|
+
console.log(`[pithy-router] Found ${routeFiles.length} route files`);
|
|
54
|
+
}
|
|
55
|
+
// Build route tree
|
|
56
|
+
const routes = buildRouteTree(routeFiles);
|
|
57
|
+
// Validate routes
|
|
58
|
+
const routeErrors = validateRoutes(routes);
|
|
59
|
+
const manifestErrors = validateManifest(routes);
|
|
60
|
+
const allErrors = [...routeErrors, ...manifestErrors];
|
|
61
|
+
if (allErrors.length > 0) {
|
|
62
|
+
console.error('[pithy-router] Route validation errors:');
|
|
63
|
+
allErrors.forEach(error => console.error(` - ${error}`));
|
|
64
|
+
// In development, continue with warnings
|
|
65
|
+
// In production, this might throw
|
|
66
|
+
if (process.env.NODE_ENV === 'production') {
|
|
67
|
+
throw new Error(`Route validation failed: ${allErrors.join(', ')}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Generate manifest
|
|
71
|
+
cachedManifest = generateManifest(routes);
|
|
72
|
+
if (debug) {
|
|
73
|
+
console.log('[pithy-router] Generated route tree:');
|
|
74
|
+
console.log(generateCliOutput(routes));
|
|
75
|
+
}
|
|
76
|
+
return cachedManifest;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error('[pithy-router] Failed to generate route manifest:', error);
|
|
80
|
+
// Return empty manifest as fallback
|
|
81
|
+
cachedManifest = `
|
|
82
|
+
// Route generation failed - fallback manifest
|
|
83
|
+
export const routes = [];
|
|
84
|
+
export type RouteManifest = typeof routes;
|
|
85
|
+
`;
|
|
86
|
+
return cachedManifest;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
name: 'pithy-router',
|
|
91
|
+
configResolved(config) {
|
|
92
|
+
// Resolve routes directory relative to project root
|
|
93
|
+
resolvedRoutesDir = join(config.root, routesDir);
|
|
94
|
+
if (debug) {
|
|
95
|
+
console.log(`[pithy-router] Routes directory: ${resolvedRoutesDir}`);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
async buildStart() {
|
|
99
|
+
// Initial route scanning and validation
|
|
100
|
+
await generateRouteManifest();
|
|
101
|
+
},
|
|
102
|
+
resolveId(id) {
|
|
103
|
+
// Handle virtual module imports
|
|
104
|
+
if (id === 'virtual:pithy/routes.gen') {
|
|
105
|
+
return id;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
},
|
|
109
|
+
async load(id) {
|
|
110
|
+
// Serve the generated route manifest
|
|
111
|
+
if (id === 'virtual:pithy/routes.gen') {
|
|
112
|
+
if (!cachedManifest) {
|
|
113
|
+
await generateRouteManifest();
|
|
114
|
+
}
|
|
115
|
+
return cachedManifest;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
},
|
|
119
|
+
// Watch for route file changes in development
|
|
120
|
+
configureServer(server) {
|
|
121
|
+
// Watch routes directory for changes
|
|
122
|
+
server.watcher.add(resolvedRoutesDir);
|
|
123
|
+
server.watcher.on('change', async (file) => {
|
|
124
|
+
if (file.startsWith(resolvedRoutesDir)) {
|
|
125
|
+
if (debug) {
|
|
126
|
+
console.log(`[pithy-router] Route file changed: ${file}`);
|
|
127
|
+
}
|
|
128
|
+
// Invalidate cached manifest
|
|
129
|
+
cachedManifest = null;
|
|
130
|
+
// Trigger HMR for the virtual module
|
|
131
|
+
const module = server.moduleGraph.getModuleById('virtual:pithy/routes.gen');
|
|
132
|
+
if (module) {
|
|
133
|
+
server.reloadModule(module);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
server.watcher.on('add', async (file) => {
|
|
138
|
+
if (file.startsWith(resolvedRoutesDir)) {
|
|
139
|
+
if (debug) {
|
|
140
|
+
console.log(`[pithy-router] Route file added: ${file}`);
|
|
141
|
+
}
|
|
142
|
+
cachedManifest = null;
|
|
143
|
+
const module = server.moduleGraph.getModuleById('virtual:pithy/routes.gen');
|
|
144
|
+
if (module) {
|
|
145
|
+
server.reloadModule(module);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
server.watcher.on('unlink', async (file) => {
|
|
150
|
+
if (file.startsWith(resolvedRoutesDir)) {
|
|
151
|
+
if (debug) {
|
|
152
|
+
console.log(`[pithy-router] Route file removed: ${file}`);
|
|
153
|
+
}
|
|
154
|
+
cachedManifest = null;
|
|
155
|
+
const module = server.moduleGraph.getModuleById('virtual:pithy/routes.gen');
|
|
156
|
+
if (module) {
|
|
157
|
+
server.reloadModule(module);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/routerPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAgBpB;;;;;;;;;;;;;;;;;;GAkBG;AACH,mKAAmK;AACnK,MAAM,UAAU,WAAW,CAAC,UAAoC,EAAE;IAChE,MAAM,EACJ,SAAS,GAAG,YAAY,EACxB,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,EACzB,UAAU,GAAG,IAAI,EACjB,KAAK,GAAG,KAAK,GACd,GAAG,OAAO,CAAC;IAEZ,IAAI,iBAAyB,CAAC;IAC9B,IAAI,cAAc,GAAkB,IAAI,CAAC;IAEzC,6CAA6C;IAC7C,KAAK,UAAU,qBAAqB;QAClC,IAAI,CAAC;YACH,wBAAwB;YACxB,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC;gBAClC,SAAS,EAAE,iBAAiB;gBAC5B,UAAU;gBACV,UAAU;aACX,CAAC,CAAC;YAEH,IAAI,KAAK,EAAE,CAAC;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,69 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-router.scanner",
|
|
4
|
+
"title": "Route File System Scanner",
|
|
5
|
+
"category": "compiler",
|
|
6
|
+
"description": "Scans the file system for route files and builds a route tree with dynamic segments, catch-all routes, and route groups.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "scanner.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import { RouteNode } from '@pithyjs/router';
|
|
17
|
+
/**
|
|
18
|
+
* Route file types that can be discovered
|
|
19
|
+
*/
|
|
20
|
+
export interface RouteFile {
|
|
21
|
+
/** File path relative to routes directory */
|
|
22
|
+
path: string;
|
|
23
|
+
/** Absolute file path */
|
|
24
|
+
absolutePath: string;
|
|
25
|
+
/** Route type (page, layout, error, loading, loader, config) */
|
|
26
|
+
type: 'page' | 'layout' | 'error' | 'loading' | 'loader' | 'config';
|
|
27
|
+
/** Route pattern derived from file path */
|
|
28
|
+
pattern: string;
|
|
29
|
+
/** Route segments */
|
|
30
|
+
segments: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Scanner configuration options
|
|
34
|
+
*/
|
|
35
|
+
export interface ScannerConfig {
|
|
36
|
+
/** Routes directory path */
|
|
37
|
+
routesDir: string;
|
|
38
|
+
/** File extensions to scan */
|
|
39
|
+
extensions?: string[];
|
|
40
|
+
/** Whether to include TypeScript files */
|
|
41
|
+
typescript?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Scan the routes directory and discover route files
|
|
45
|
+
*/
|
|
46
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"scanRoutes","stability":"stable","signature":"(config: ScannerConfig) => Promise<RouteFile[]>"} */
|
|
47
|
+
export declare function scanRoutes(config: ScannerConfig): Promise<RouteFile[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Parse a route file path into route information
|
|
50
|
+
*/
|
|
51
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"parseRouteFile","stability":"stable","signature":"(filePath: string, routesDir: string) => RouteFile | null"} */
|
|
52
|
+
export declare function parseRouteFile(filePath: string, routesDir: string): RouteFile | null;
|
|
53
|
+
/**
|
|
54
|
+
* Build route pattern from directory path
|
|
55
|
+
* Converts file system path to URL pattern
|
|
56
|
+
*/
|
|
57
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"buildRoutePattern","stability":"stable","signature":"(dirPath: string) => string"} */
|
|
58
|
+
export declare function buildRoutePattern(dirPath: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Build route tree from discovered route files
|
|
61
|
+
*/
|
|
62
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"buildRouteTree","stability":"stable","signature":"(routeFiles: RouteFile[]) => RouteNode[]"} */
|
|
63
|
+
export declare function buildRouteTree(routeFiles: RouteFile[]): RouteNode[];
|
|
64
|
+
/**
|
|
65
|
+
* Validate route tree for conflicts and issues
|
|
66
|
+
*/
|
|
67
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.scanner","name":"validateRoutes","stability":"stable","signature":"(routes: RouteNode[]) => string[]"} */
|
|
68
|
+
export declare function validateRoutes(routes: RouteNode[]): string[];
|
|
69
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../src/routerPlugin/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,C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