// Stages WebAssembly runtimes for DWG conversion into apps/web/public // so that AutoCAD drawings (.dwg) can be converted directly in the browser // without requiring native software or backend servers. import { cp, mkdir, readdir } from "node:fs/promises"; import { existsSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const root = join(dirname(fileURLToPath(import.meta.url)), ".."); // 1. Stage dwgdxf (acadrust Rust WASM - 820 KB) const dwgdxfSrc = join(root, "node_modules", "dwgdxf", "dist", "wasm"); const dwgdxfDest = join(root, "apps", "web", "public", "dwgdxf"); if (existsSync(dwgdxfSrc)) { await mkdir(dwgdxfDest, { recursive: true }); const entries = await readdir(dwgdxfSrc); const wanted = entries.filter((name) => name.endsWith(".js") || name.endsWith(".wasm")); await Promise.all(wanted.map((name) => cp(join(dwgdxfSrc, name), join(dwgdxfDest, name)))); console.log(`[copy-dwg-wasm] staged ${wanted.length} files into apps/web/public/dwgdxf/`); } // 2. Stage @mlightcad/libredwg-web wasm const mlightSrc = join(root, "node_modules", "@mlightcad", "libredwg-web", "wasm"); const mlightDest = join(root, "apps", "web", "public", "libredwg-web"); if (existsSync(mlightSrc)) { await mkdir(mlightDest, { recursive: true }); const entries = await readdir(mlightSrc); const wanted = entries.filter((name) => name.endsWith(".js") || name.endsWith(".wasm")); await Promise.all(wanted.map((name) => cp(join(mlightSrc, name), join(mlightDest, name)))); console.log(`[copy-dwg-wasm] staged ${wanted.length} files into apps/web/public/libredwg-web/`); } // 3. Stage legacy dwg2dxf-converter wasm const legacySrc = join(root, "node_modules", "dwg2dxf-converter", "wasm"); const legacyDest = join(root, "apps", "web", "public", "libredwg"); if (existsSync(legacySrc)) { await mkdir(legacyDest, { recursive: true }); const entries = await readdir(legacySrc); const wanted = entries.filter((name) => name.endsWith(".js") || name.endsWith(".wasm")); await Promise.all(wanted.map((name) => cp(join(legacySrc, name), join(legacyDest, name)))); console.log(`[copy-dwg-wasm] staged ${wanted.length} files into apps/web/public/libredwg/`); }