1- import type { Blueprint , Route } from '@seamapi/blueprint'
2- import { kebabCase , pascalCase } from 'change-case'
1+ import type { Blueprint , Namespace , Route } from '@seamapi/blueprint'
2+ import { camelCase , kebabCase , pascalCase } from 'change-case'
33import type Metalsmith from 'metalsmith'
44
55interface Metadata {
@@ -19,11 +19,12 @@ export const connect = (
1919
2020 const rootRouteKey = `${ rootPath } /seam-http.js`
2121 files [ rootRouteKey ] = { contents : Buffer . from ( '\n' ) }
22- const rootRouteFile = files [ rootRouteKey ] as unknown as File
23- rootRouteFile . layout = 'route.hbs'
24- setRootRouteLayoutContext ( rootRouteFile , blueprint )
22+ const file = files [ rootRouteKey ] as unknown as File
23+ file . layout = 'route.hbs'
24+ setRouteLayoutContext ( file , null , blueprint )
2525
2626 const routeIndexes : Record < string , Set < string > > = { }
27+ console . log ( file )
2728
2829 for ( const route of Object . values ( blueprint . routes ?? { } ) ) {
2930 const k = `${ rootPath } /${ route . path
@@ -62,6 +63,7 @@ interface RouteLayoutContext {
6263 className : string
6364 endpoints : EndpointLayoutContext [ ]
6465 subroutes : SubrouteLayoutContext [ ]
66+ namespaces : SubrouteLayoutContext [ ]
6567 isClientSessionRoute : boolean
6668 isActionAttemptsRoute : boolean
6769 needsActionAttempts : boolean
@@ -76,27 +78,35 @@ interface SubrouteLayoutContext {
7678 className : string
7779}
7880
79- const setRootRouteLayoutContext = (
80- file : Partial < RouteLayoutContext > ,
81- _blueprint : Blueprint ,
82- ) : void => {
83- file . className = 'SeamHttp'
84- file . needsActionAttempts = false
85- file . isClientSessionRoute = false
86- file . isActionAttemptsRoute = false
87- file . endpoints = [ ]
88- file . subroutes = [ ]
89- }
81+ const getClassName = ( name : string | null ) : string =>
82+ `SeamHttp${ pascalCase ( name ?? '' ) } `
9083
9184const setRouteLayoutContext = (
9285 file : Partial < RouteLayoutContext > ,
93- route : Route ,
94- _blueprint : Blueprint ,
86+ route : Route | null ,
87+ blueprint : Blueprint ,
9588) : void => {
96- file . className = `SeamHttp${ pascalCase ( route . name ) } `
97- file . needsActionAttempts = false
98- file . isClientSessionRoute = route . name === '/client_sessions'
99- file . isActionAttemptsRoute = route . name === '/action_attempts'
100- file . endpoints = [ ]
101- file . subroutes = [ ]
89+ file . className = getClassName ( route ?. name ?? null )
90+ file . needsActionAttempts = false // TODO
91+ file . isClientSessionRoute = route ?. name === '/client_sessions'
92+ file . isActionAttemptsRoute = route ?. name === '/action_attempts'
93+
94+ file . endpoints = [ ] // TODO
95+
96+ file . namespaces = blueprint . namespaces
97+ . filter ( ( { parentPath } ) => parentPath === ( route ?. path ?? null ) )
98+ . map ( ( r ) => getSubrouteLayoutContext ( r ) )
99+
100+ file . subroutes = blueprint . routes
101+ . filter ( ( { parentPath } ) => parentPath === ( route ?. path ?? null ) )
102+ . map ( ( r ) => getSubrouteLayoutContext ( r ) )
103+ }
104+
105+ const getSubrouteLayoutContext = (
106+ node : Route | Namespace ,
107+ ) : SubrouteLayoutContext => {
108+ return {
109+ methodName : camelCase ( node . name ) ,
110+ className : getClassName ( node . path ) ,
111+ }
102112}
0 commit comments