@@ -2,17 +2,24 @@ import type { Blueprint } from '@seamapi/blueprint'
22import { kebabCase } from 'change-case'
33import type Metalsmith from 'metalsmith'
44
5+ import {
6+ type EndpointsLayoutContext ,
7+ setEndpointsLayoutContext ,
8+ } from './layouts/endpoints.js'
59import {
610 type RouteIndexLayoutContext ,
711 type RouteLayoutContext ,
812 setRouteLayoutContext ,
13+ toFilePath ,
914} from './layouts/route.js'
1015
1116interface Metadata {
1217 blueprint : Blueprint
1318}
1419
15- type File = RouteLayoutContext & RouteIndexLayoutContext & { layout : string }
20+ type File = RouteLayoutContext &
21+ RouteIndexLayoutContext &
22+ EndpointsLayoutContext & { layout : string }
1623
1724const rootPath = 'src/lib/seam/connect/routes'
1825
@@ -34,15 +41,22 @@ export const connect = (
3441
3542 const routeIndexes : Record < string , Set < string > > = { }
3643
37- const rootRouteKey = `${ rootPath } /seam-http.ts`
38- files [ rootRouteKey ] = { contents : Buffer . from ( '\n' ) }
39- const file = files [ rootRouteKey ] as unknown as File
44+ const k = `${ rootPath } /seam-http.ts`
45+ files [ k ] = { contents : Buffer . from ( '\n' ) }
46+ const file = files [ k ] as unknown as File
4047 file . layout = 'route.hbs'
4148 setRouteLayoutContext ( file , null , nodes )
4249
4350 routeIndexes [ '' ] ??= new Set ( )
4451 routeIndexes [ '' ] ?. add ( 'seam-http.js' )
4552
53+ const endpointsKey = `${ rootPath } /seam-http-endpoints.ts`
54+ files [ endpointsKey ] = { contents : Buffer . from ( '\n' ) }
55+ const endpointFile = files [ endpointsKey ] as unknown as File
56+ endpointFile . layout = 'endpoints.hbs'
57+ setEndpointsLayoutContext ( endpointFile , routes )
58+ routeIndexes [ '' ] ?. add ( 'seam-http-endpoints.js' )
59+
4660 for ( const node of nodes ) {
4761 const path = toFilePath ( node . path )
4862 const name = kebabCase ( node . name )
@@ -75,10 +89,3 @@ export const connect = (
7589 file . routes = [ ...routes ]
7690 }
7791}
78-
79- const toFilePath = ( path : string ) : string =>
80- path
81- . slice ( 1 )
82- . split ( '/' )
83- . map ( ( p ) => kebabCase ( p ) )
84- . join ( '/' )
0 commit comments