Files
snapcad-studio/scripts/copy-planegcs-wasm.mjs
T

25 lines
1.1 KiB
JavaScript
Raw Normal View History

// Stages the FreeCAD PlaneGCS WebAssembly 2D constraint solver (planegcs.js +
// 484 KB planegcs.wasm) into apps/web/public/planegcs/ so the browser runtime can
// load it via a webpackIgnore dynamic import without bundler friction.
import { cp, mkdir } 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)), "..");
const srcDir = join(root, "node_modules", "@salusoft89", "planegcs", "dist", "planegcs_dist");
const destDir = join(root, "apps", "web", "public", "planegcs");
const required = ["planegcs.js", "planegcs.wasm"];
for (const fileName of required) {
const fullPath = join(srcDir, fileName);
if (!existsSync(fullPath)) {
console.error(`[copy-planegcs-wasm] Missing ${fullPath}. Run \`npm install\` first.`);
process.exit(1);
}
}
await mkdir(destDir, { recursive: true });
await Promise.all(required.map((fileName) => cp(join(srcDir, fileName), join(destDir, fileName))));
console.log("[copy-planegcs-wasm] staged planegcs.js + planegcs.wasm into apps/web/public/planegcs/");