import { cp, rm } from "node:fs/promises"; import { spawnSync } from "node:child_process"; import { fileURLToPath } from "node:url"; import path from "node:path"; const scriptsDir = path.dirname(fileURLToPath(import.meta.url)); const projectRoot = path.resolve(scriptsDir, ".."); const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm"; function run(command, args, cwd) { const result = spawnSync(command, args, { cwd, stdio: "inherit" }); if (result.status !== 0) process.exit(result.status ?? 1); } run(npmCommand, ["run", "build"], path.join(projectRoot, "web")); run(npmCommand, ["run", "build"], path.join(projectRoot, "admin")); const adminTarget = path.join(projectRoot, "web", "dist", "admin"); await rm(adminTarget, { recursive: true, force: true }); await cp(path.join(projectRoot, "admin", "dist"), adminTarget, { recursive: true });