Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/short-vans-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-kit-routes': minor
---

also generate routes during build
20 changes: 12 additions & 8 deletions packages/vite-plugin-kit-routes/src/lib/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ const arrayToRecord = (arr?: string[]) => {
return `: Record<string, never>`
}

export const run = (atStart: boolean, o?: Options) => {
export const run = async (atStart: boolean, o?: Options) => {
const options = getDefaultOption(o)

const files = getFilesUnder(routes_path())
Expand Down Expand Up @@ -960,10 +960,14 @@ ${objTypes
})
}

const exitPromise = new Promise<void>(resolve => {
child.on('close', () => resolve())
})

await exitPromise

if (shouldLog('update', options)) {
child.on('close', () => {
theEnd(atStart, result, objTypes, options)
})
theEnd(atStart, result, objTypes, options)
}
} else {
theEnd(atStart, result, objTypes, options)
Expand Down Expand Up @@ -1069,8 +1073,8 @@ export function kitRoutes<T extends ExtendTypes = ExtendTypes>(options?: Options
// Run the thing at startup
{
name: 'kit-routes',
configureServer() {
run(true, options)
async buildStart() {
await run(true, options)
},
},

Expand All @@ -1080,8 +1084,8 @@ export function kitRoutes<T extends ExtendTypes = ExtendTypes>(options?: Options
name: 'kit-routes-watch',
logs: [],
watch: ['**/+page.svelte', '**/+page.server.ts', '**/+server.ts'],
run: () => {
run(false, options)
run: async () => {
await run(false, options)
},
},
]),
Expand Down
12 changes: 6 additions & 6 deletions packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ describe('run()', async () => {
for (let i = 0; i < runs.length; i++) {
const toRun = runs[i]
it(`run ${toRun.pathFile}`, async () => {
const ret = run(false, {
const ret = await run(false, {
format: toRun.format,
generated_file_path: getPathROUTES(toRun.pathFile),
...toRun.extra,
Expand All @@ -474,7 +474,7 @@ describe('run()', async () => {
const toRun = getToRunShortened(runs[i])

it(`run ${toRun.pathFile}`, async () => {
const ret = run(false, {
const ret = await run(false, {
format: toRun.format,
generated_file_path: getPathROUTES(toRun.pathFile),
...toRun.extra,
Expand Down Expand Up @@ -769,19 +769,19 @@ describe('run()', async () => {
})
}

it('post_update_run', () => {
it('post_update_run', async () => {
const generated_file_path = 'src/test/ROUTES_post-update.ts'
run(false, {
await run(false, {
generated_file_path,
post_update_run: 'echo done',
})

expect(true).toBe(true)
})

it('with path base', () => {
it('with path base', async () => {
const generated_file_path = 'src/test/ROUTES_base.ts'
run(false, {
await run(false, {
generated_file_path,
path_base: true,
})
Expand Down