#!/usr/bin/env node // `next build --webpack` (see next.config.ts's `output: "standalone"`) // emits .next/standalone/server.js but - deliberately, per Next's own docs - // leaves out public/ and .next/static/. The Dockerfile copies both in by // hand for the container image; this does the same thing for local Electron // dev and packaging, so every path boots the exact same artifact. import { cpSync, existsSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const rootDir = path.dirname(path.dirname(fileURLToPath(import.meta.url))); const standaloneDir = path.join(rootDir, ".next", "standalone"); if (!existsSync(standaloneDir)) { console.error(`Missing ${standaloneDir} - run "next build --webpack" first.`); process.exit(1); } const publicSrc = path.join(rootDir, "public"); const publicDest = path.join(standaloneDir, "public"); rmSync(publicDest, { recursive: true, force: true }); cpSync(publicSrc, publicDest, { recursive: true }); const staticSrc = path.join(rootDir, ".next", "static"); const staticDest = path.join(standaloneDir, ".next", "static"); rmSync(staticDest, { recursive: true, force: true }); cpSync(staticSrc, staticDest, { recursive: true }); console.log("Assembled standalone server at", standaloneDir);