diff --git a/packages/nano-remix/src/build.ts b/packages/nano-remix/src/build.ts new file mode 100644 index 0000000..c08377e --- /dev/null +++ b/packages/nano-remix/src/build.ts @@ -0,0 +1,29 @@ +import { join } from "node:path" + +export type BuildRouteOptions = { + distDir: string + routeName: string + filepath: string +} + +export const buildDynamicRoute = async ({ distDir, routeName, filepath }: BuildRouteOptions) => { + const scriptPath = join(import.meta.dirname, "../scripts/build.ts") + + const proc = Bun.spawn({ + cmd: ["bun", "run", scriptPath, distDir, routeName, filepath], + stdout: "pipe", + stderr: "pipe", + }) + + const exitCode = await proc.exited + + if (exitCode !== 0) { + const stderr = await new Response(proc.stderr).text() + throw new Error(`Build process failed with exit code ${exitCode}: ${stderr}`) + } + + const stdout = await new Response(proc.stdout).text() + console.log(stdout) + + return { success: true } +}