2026-08-17 16:03:48 +03:00
|
|
|
import { spawnSync } from "node:child_process";
|
|
|
|
|
import fs from "node:fs";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
|
|
|
|
|
const desktopDir = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
const repoRoot = path.resolve(desktopDir, "..", "..");
|
|
|
|
|
const nextBin = path.join(repoRoot, "node_modules", "next", "dist", "bin", "next");
|
2026-11-12 10:12:35 +03:00
|
|
|
const wasmCopyScripts = [
|
|
|
|
|
path.join(repoRoot, "scripts", "copy-occt-wasm.mjs"),
|
|
|
|
|
path.join(repoRoot, "scripts", "copy-dwg-wasm.mjs"),
|
|
|
|
|
path.join(repoRoot, "scripts", "copy-ifc-wasm.mjs"),
|
|
|
|
|
path.join(repoRoot, "scripts", "copy-planegcs-wasm.mjs"),
|
|
|
|
|
];
|
2026-08-17 16:03:48 +03:00
|
|
|
|
|
|
|
|
function runNode(args, env = process.env) {
|
|
|
|
|
const result = spawnSync(process.execPath, args, {
|
|
|
|
|
cwd: repoRoot,
|
|
|
|
|
stdio: "inherit",
|
|
|
|
|
env,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (result.error) {
|
|
|
|
|
console.error(result.error);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 0) {
|
|
|
|
|
process.exit(result.status ?? 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-12 10:12:35 +03:00
|
|
|
for (const scriptPath of wasmCopyScripts) {
|
|
|
|
|
runNode([scriptPath]);
|
|
|
|
|
}
|
2026-08-17 16:03:48 +03:00
|
|
|
runNode([nextBin, "build", "apps/web"], {
|
|
|
|
|
...process.env,
|
|
|
|
|
SKETCHFORGE_DOCKER_BUILD: "true",
|
|
|
|
|
NEXT_TELEMETRY_DISABLED: "1",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const requiredPaths = [
|
|
|
|
|
path.join(repoRoot, "apps", "web", ".next", "standalone", "apps", "web", "server.js"),
|
2026-11-12 10:12:35 +03:00
|
|
|
path.join(repoRoot, "apps", "web", ".next", "standalone", "node_modules"),
|
2026-08-17 16:03:48 +03:00
|
|
|
path.join(repoRoot, "apps", "web", ".next", "static"),
|
|
|
|
|
path.join(repoRoot, "apps", "web", "public"),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const requiredPath of requiredPaths) {
|
|
|
|
|
if (!fs.existsSync(requiredPath)) {
|
|
|
|
|
console.error(`[desktop:web:build] Missing expected build output: ${requiredPath}`);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-12 10:12:35 +03:00
|
|
|
const standaloneModulesSrc = path.join(repoRoot, "apps", "web", ".next", "standalone", "node_modules");
|
|
|
|
|
const stagedRuntimeModules = path.join(repoRoot, "apps", "web", ".next", "desktop-runtime_modules");
|
|
|
|
|
fs.rmSync(stagedRuntimeModules, { recursive: true, force: true });
|
|
|
|
|
fs.cpSync(standaloneModulesSrc, stagedRuntimeModules, { recursive: true, dereference: true });
|
|
|
|
|
|
|
|
|
|
console.log("[desktop:web:build] Standalone SnapCAD web bundle is ready.");
|