| 18 | |
| 19 | // fallow-ignore-next-line complexity |
| 20 | async function waitForStudioDist(dir) { |
| 21 | const deadline = Date.now() + STUDIO_WAIT_TIMEOUT_MS; |
| 22 | while (Date.now() < deadline) { |
| 23 | try { |
| 24 | const entries = new Set(readdirSync(dir)); |
| 25 | // vite emits `assets/` before rewriting `index.html` at the end of the |
| 26 | // build — so once both are present, the tree is complete. |
| 27 | if (entries.has("index.html") && entries.has("assets")) return; |
| 28 | } catch { |
| 29 | // dir doesn't exist yet — vite will create it |
| 30 | } |
| 31 | await sleep(STUDIO_POLL_INTERVAL_MS); |
| 32 | } |
| 33 | throw new Error(`[build-copy] timed out waiting for studio dist at ${dir}`); |
| 34 | } |
| 35 | |
| 36 | function copyDir(src, dest) { |
| 37 | cpSync(src, dest, { recursive: true, force: true }); |