import { copyFile, mkdir } from "node:fs/promises"; import { resolve } from "node:path"; const root = resolve(import.meta.dir, ".."); const benchmark = process.argv.includes("--benchmark"); for (const feature of benchmark ? ["benchmark"] : ["gif", "png"]) { const target = resolve(root, `native/build/raster-${feature}`); const output = resolve(target, "wasm32-wasip1/release/sinter_raster.wasm"); const destination = benchmark ? resolve(root, "../demo/src/benchmark.wasm") : resolve(root, process.argv.includes("--copy-dist") ? "dist" : "src/codecs", `${feature}.wasm`); if (!process.argv.includes("--copy-dist")) { const p = Bun.spawn(["cargo", "build", "--manifest-path", resolve(root,"native/raster/Cargo.toml"), "--target", "wasm32-wasip1", "--release", "--locked", "--no-default-features", "--features", feature, "--target-dir", target], {stdout:"inherit",stderr:"inherit"}); if(await p.exited) throw new Error(`${feature} WASM build failed`); } await mkdir(resolve(destination, ".."), {recursive:true}); await copyFile(output, destination); }