@@ -6,7 +6,7 @@ interface Metadata {
66 blueprint : Blueprint
77}
88
9- type File = RouteLayoutContext & { layout : string }
9+ type File = RouteLayoutContext & RouteIndexLayoutContext & { layout : string }
1010
1111const rootPath = 'src/lib/seam/connect/routes'
1212
@@ -23,6 +23,8 @@ export const connect = (
2323 rootRouteFile . layout = 'route.hbs'
2424 setRootRouteLayoutContext ( rootRouteFile , blueprint )
2525
26+ const routeIndexes : Record < string , Set < string > > = { }
27+
2628 for ( const route of Object . values ( blueprint . routes ?? { } ) ) {
2729 const k = `${ rootPath } /${ route . path
2830 . slice ( 1 )
@@ -34,9 +36,28 @@ export const connect = (
3436 const file = files [ k ] as unknown as File
3537 file . layout = 'route.hbs'
3638 setRouteLayoutContext ( file , route , blueprint )
39+
40+ const parentPath = route . parentPath ?? ''
41+ routeIndexes [ parentPath ] ??= new Set ( )
42+ routeIndexes [ parentPath ] ?. add ( `${ kebabCase ( route . name ) } .js` )
43+ }
44+
45+ for ( const [ parentPath , routes ] of Object . entries ( routeIndexes ) ) {
46+ const k =
47+ parentPath === ''
48+ ? `${ rootPath } /index.js`
49+ : `${ rootPath } /${ kebabCase ( parentPath ) } /index.js`
50+ files [ k ] = { contents : Buffer . from ( '\n' ) }
51+ const file = files [ k ] as unknown as File
52+ file . layout = 'route-index.hbs'
53+ file . routes = [ ...routes ]
3754 }
3855}
3956
57+ interface RouteIndexLayoutContext {
58+ routes : string [ ]
59+ }
60+
4061interface RouteLayoutContext {
4162 className : string
4263 endpoints : EndpointLayoutContext [ ]
0 commit comments