Skip to content

Commit 629fbad

Browse files
committed
Add index generation
1 parent 9487e95 commit 629fbad

4 files changed

Lines changed: 25 additions & 233 deletions

File tree

codegen/layouts/route-index.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#each routes}}
2+
export * from './{{.}}'
3+
{{/each}}

codegen/lib/connect.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

1111
const 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+
4061
interface RouteLayoutContext {
4162
className: string
4263
endpoints: EndpointLayoutContext[]

src/lib/seam/connect/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export {
1111
SeamActionAttemptTimeoutError,
1212
} from './resolve-action-attempt.js'
1313
export * from './routes/index.js'
14-
export * from './seam-http.js'
1514
export * from './seam-http-error.js'
1615
export * from './seam-http-multi-workspace.js'
1716
export * from './seam-http-request.js'

src/lib/seam/connect/seam-http.ts

Lines changed: 0 additions & 231 deletions
This file was deleted.

0 commit comments

Comments
 (0)