2025-12-22 09:18:21 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare standalone directory for Electron packaging
|
|
|
|
|
* Copies the Next.js standalone output to a temp directory
|
|
|
|
|
* that electron-builder can properly include
|
|
|
|
|
*/
|
|
|
|
|
|
2026-10-12 08:11:10 +09:00
|
|
|
import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs"
|
2025-12-22 09:18:21 +08:00
|
|
|
import { join } from "node:path"
|
|
|
|
|
import { fileURLToPath } from "node:url"
|
2026-10-12 08:11:10 +09:00
|
|
|
import copyDereferenced from "./copy-dereferenced.cjs"
|
2025-12-22 09:18:21 +08:00
|
|
|
|
|
|
|
|
const __dirname = fileURLToPath(new URL(".", import.meta.url))
|
|
|
|
|
const rootDir = join(__dirname, "..")
|
|
|
|
|
|
|
|
|
|
const standaloneDir = join(rootDir, ".next", "standalone")
|
|
|
|
|
const staticDir = join(rootDir, ".next", "static")
|
|
|
|
|
const targetDir = join(rootDir, "electron-standalone")
|
|
|
|
|
|
|
|
|
|
console.log("Preparing Electron build...")
|
|
|
|
|
|
|
|
|
|
// Clean target directory
|
|
|
|
|
if (existsSync(targetDir)) {
|
|
|
|
|
console.log("Cleaning previous build...")
|
|
|
|
|
rmSync(targetDir, { recursive: true })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create target directory
|
|
|
|
|
mkdirSync(targetDir, { recursive: true })
|
|
|
|
|
|
|
|
|
|
// Copy standalone (includes node_modules)
|
|
|
|
|
console.log("Copying standalone directory...")
|
2026-01-18 19:57:38 +09:00
|
|
|
copyDereferenced(standaloneDir, targetDir)
|
2025-12-22 09:18:21 +08:00
|
|
|
|
2026-10-05 22:39:32 +09:00
|
|
|
// Next.js copies the build machine's .env files into standalone; don't ship
|
|
|
|
|
// them, they can hold the builder's API keys
|
|
|
|
|
for (const entry of readdirSync(targetDir)) {
|
|
|
|
|
if (entry.startsWith(".env")) {
|
|
|
|
|
console.warn(`Removing ${entry} so it is not packaged into the app`)
|
|
|
|
|
rmSync(join(targetDir, entry))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 09:18:21 +08:00
|
|
|
// Copy static files
|
|
|
|
|
console.log("Copying static files...")
|
|
|
|
|
const targetStaticDir = join(targetDir, ".next", "static")
|
2026-01-18 19:57:38 +09:00
|
|
|
copyDereferenced(staticDir, targetStaticDir)
|
2025-12-22 09:18:21 +08:00
|
|
|
|
2026-10-11 20:32:23 +09:00
|
|
|
// Copy public folder (required for favicons and other assets)
|
2026-01-09 10:40:44 +05:30
|
|
|
console.log("Copying public folder...")
|
|
|
|
|
const publicDir = join(rootDir, "public")
|
|
|
|
|
const targetPublicDir = join(targetDir, "public")
|
|
|
|
|
if (existsSync(publicDir)) {
|
2026-01-18 19:57:38 +09:00
|
|
|
copyDereferenced(publicDir, targetPublicDir)
|
2026-01-09 10:40:44 +05:30
|
|
|
}
|
|
|
|
|
|
2025-12-22 09:18:21 +08:00
|
|
|
console.log("Done! Files prepared in electron-standalone/")
|