Open source CapCut alternative.
TypeScript
import { mkdir, rm, writeFile } from "node:fs/promises";
import path from "node:path";
// ChatGPT caches the widget HTML it reads over MCP, so the entry script and
// stylesheet keep stable names and revalidate on every load; the chunks the
// entry imports stay hashed, so MP4 playback never downloads the HLS decoder.
const root = path.resolve(import.meta.dir, "..");
const outdir = path.join(root, "public/clients/chatgpt");
await rm(outdir, { recursive: true, force: true });
await mkdir(outdir, { recursive: true });
const result = await Bun.build({
entrypoints: [path.join(root, "src/clients/chatgpt/ui/main.tsx")],
target: "browser", format: "esm", splitting: true, minify: true, outdir,
naming: { entry: "[name].[ext]", chunk: "[name]-[hash].[ext]", asset: "[name]-[hash].[ext]" },
define: { "process.env.NODE_ENV": JSON.stringify("production") },
});
if (!result.success) throw new AggregateError(result.logs, "ChatGPT widget build failed");
const entry = result.outputs.find((o) => o.kind === "entry-point" && o.path.endsWith(".js"))!;
const css = result.outputs.find((o) => o.path.endsWith(".css"));
const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Donkey Cut preview</title>${css ? `<link rel="stylesheet" href="WIDGET_ORIGIN/clients/chatgpt/${path.basename(css.path)}">` : ""}</head><body><div id="root"></div><script type="module" src="WIDGET_ORIGIN/clients/chatgpt/${path.basename(entry.path)}"></script></body></html>`;
const output = path.join(root, "src/clients/chatgpt/widget.generated.ts");
await writeFile(output, `// Generated by scripts/build-chatgpt-widget.ts\nexport const widgetHtml = (origin: string) => ${JSON.stringify(html)}.replaceAll("WIDGET_ORIGIN", origin);\n`);
console.log(`ChatGPT widget entry: ${Math.round(entry.size / 1024)} KiB; HLS loads on demand`);