// Build libghostty-vt as wasm for the terminal extension, from a pinned ghostty, into // extensions/terminal/ghostty-vt.wasm. Run it as `deno task ghostty`; it needs git and zig 0.16 on PATH. import { join } from "node:path"; const GHOSTTY = "7ec9e26a29399b30ef78f06985fc75045b3cecb6"; const home = Deno.env.get("HOME") ?? "."; const source = join(Deno.env.get("XDG_CACHE_HOME") ?? join(home, ".cache"), "berry", "ghostty"); const target = new URL("./ghostty-vt.wasm", import.meta.url); async function run(cwd: string, program: string, ...args: string[]) { console.error(`$ ${program} ${args.join(" ")}`); const { success } = await new Deno.Command(program, { args, cwd, stdout: "inherit", stderr: "inherit", }) .output(); if (!success) throw new Error(`${program} failed`); } await Deno.mkdir(source, { recursive: true }); await run(source, "git", "init", "--quiet"); await run( source, "git", "fetch", "--quiet", "--depth", "1", "https://github.com/ghostty-org/ghostty", GHOSTTY, ); await run(source, "git", "checkout", "--quiet", "--force", "FETCH_HEAD"); await run( source, "zig", "build", "-Demit-lib-vt", "-Dtarget=wasm32-freestanding", "-Doptimize=ReleaseSmall", ); await Deno.copyFile(join(source, "zig-out", "bin", "ghostty-vt.wasm"), target); console.error(`built ${target.pathname}`);