#!/usr/bin/env node // Generates docs/demo-dev.html from docs/demo.html with CDN URLs replaced // by the local asset server so no manual editing of demo.html is ever needed. // // CDN pattern replaced: // https://cdn.jsdelivr.net/npm/@kreuzberg/wasm@*/... // → http://localhost:9000/... // // Also patches pkg/web/kreuzberg_wasm.js (gitignored, wasm-pack generated) to // replace bare specifier imports ("env", "wasi_snapshot_preview1") with inline // browser shims. The local 5.x WASM binary is compiled with WASI syscalls via // tesseract's C layer; the importmap approach does not propagate into Workers // loading cross-origin modules, so we shim the generated JS directly. // // The output file is gitignored and regenerated on every `task demo:dev`. import { readFileSync, writeFileSync, existsSync } from "node:fs"; import { join, dirname } from "node:path"; import { fileURLToPath } from "node:url"; const root = join(dirname(fileURLToPath(import.meta.url)), "..", ".."); const src = join(root, "docs", "demo.html"); const dest = join(root, "docs", "demo-dev.html"); const ASSET_PORT = process.env.ASSET_PORT ?? "9000"; const cdnRe = /https:\/\/cdn\.jsdelivr\.net\/npm\/@kreuzberg\/wasm@[^/'"]+/g; const patched = readFileSync(src, "utf8") .replace(cdnRe, `http://localhost:${ASSET_PORT}`) .replace(/