#!/usr/bin/env node // Render this clip, STUBBED (E2E_UMTOOL_CLIP_RENDER_SCRIPT, set in // playwright.config.ts): the command line of build-video.mjs --clip-preview // (`node build-video.mjs --out [--variant v] --skip-fetch // --clip-preview --progress ndjson`) and its outputs -- // `//clip-preview/.mp4` and the record beside it -- with no // render: the "render" is a copy of the project's cached window. The suite // tests the button, the job and the file shown, not a render (the real run is // report-to-video's, proven on a copy of a real cut: plans/live-preview.md). import { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises"; import path from "node:path"; const argv = process.argv.slice(2); const flag = (n) => { const i = argv.indexOf(n); return i < 0 ? null : argv[i + 1]; }; const manifestPath = argv[0]; const id = flag("--clip-preview"); const variant = flag("--variant") ?? "sourced"; const out = flag("--out"); if (!manifestPath || !id || !out || !argv.includes("--skip-fetch")) { console.error("stub: expected --out --skip-fetch --clip-preview "); process.exit(2); } const manifest = JSON.parse(await readFile(manifestPath, "utf8")); const entry = (manifest.timeline ?? []).find((e) => e.id === id); if (!entry) { console.log(JSON.stringify({ ev: "error", message: `no entry ${id}` })); process.exit(1); } const emit = (ev, f = {}) => console.log(JSON.stringify({ ev, ...f })); emit("clip", { id, i: 0, n: 1 }); const raw = path.join(out, "clips-raw"); const name = (await readdir(raw)).find((f) => f.endsWith(".mp4")); const dir = path.join(out, variant, "clip-preview"); await mkdir(dir, { recursive: true }); emit("chrome", { phase: "render", region: "deck" }); await copyFile(path.join(raw, name), path.join(dir, `${id}.mp4`)); await writeFile(path.join(dir, `${id}.json`), JSON.stringify({ version: 1, id, builtAt: new Date().toISOString(), start: 0, duration: entry.end - entry.start, estimated: true, window: { start: entry.start, end: entry.end, cutStart: entry.cutStart ?? null, cutEnd: entry.cutEnd ?? null }, }, null, 2) + "\n"); emit("done", { out: path.join(dir, `${id}.mp4`), failures: [] });