The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** |
| 2 | * Rebuilds out/capture/intro/intro.json whenever intro/steps.ts, a snippet, |
| 3 | * or the shared intro types change. Remotion Studio's `intro-live` |
| 4 | * composition picks up each rebuild without a reload. Started by `pnpm dev`. |
| 5 | */ |
| 6 | import { spawn } from "node:child_process"; |
| 7 | import { watch } from "node:fs"; |
| 8 | import path from "node:path"; |
| 9 | |
| 10 | const dir = import.meta.dirname; |
| 11 | let running = false; |
| 12 | let again = false; |
| 13 | |
| 14 | const build = () => { |
| 15 | if (running) { |
| 16 | again = true; |
| 17 | return; |
| 18 | } |
| 19 | running = true; |
| 20 | const started = Date.now(); |
| 21 | // Both decks, one after the other: they share the snippet type-check cache. |
| 22 | const child = spawn( |
| 23 | "sh", |
| 24 | [ |
| 25 | "-c", |
| 26 | `"${process.execPath}" "${path.join(dir, "build.ts")}" intro && "${process.execPath}" "${path.join(dir, "build.ts")}" loop`, |
| 27 | ], |
| 28 | { |
| 29 | stdio: ["ignore", "pipe", "pipe"], |
| 30 | }, |
| 31 | ); |
| 32 | let output = ""; |
| 33 | child.stdout.on("data", (d) => (output += d)); |
| 34 | child.stderr.on("data", (d) => (output += d)); |
| 35 | child.on("exit", (code) => { |
| 36 | running = false; |
| 37 | const took = ((Date.now() - started) / 1000).toFixed(1); |
| 38 | if (code === 0) console.log(`✔ intro rebuilt (${took}s)`); |
| 39 | else console.error(`✘ intro build failed (${took}s)\n${output.trim()}`); |
| 40 | if (again) { |
| 41 | again = false; |
| 42 | build(); |
| 43 | } |
| 44 | }); |
| 45 | }; |
| 46 | |
| 47 | let timer: NodeJS.Timeout | undefined; |
| 48 | const schedule = (file: string | null) => { |
| 49 | if (file && !/\.(ts|tsx|json)$/.test(file)) return; |
| 50 | clearTimeout(timer); |
| 51 | timer = setTimeout(build, 150); |
| 52 | }; |
| 53 | |
| 54 | watch(dir, { recursive: true }, (_, file) => { |
| 55 | if ( |
| 56 | file && |
| 57 | file.startsWith(`snippets${path.sep}`) === false && |
| 58 | file !== "steps.ts" && |
| 59 | file !== "loop.ts" |
| 60 | ) |
| 61 | return; |
| 62 | schedule(file); |
| 63 | }); |
| 64 | watch(path.join(dir, "..", "shared"), (_, file) => schedule(file)); |
| 65 | console.log("● watching intro/steps.ts, intro/loop.ts and intro/snippets"); |
| 66 | build(); |