Files
robertseares/frontend/prepare-standalone.mjs
a2a-platform 7aab2dccb9 deploy
2026-06-11 23:13:20 +00:00

49 lines
1.3 KiB
JavaScript

import { cpSync, existsSync, mkdirSync, readdirSync } from "node:fs";
import { join } from "node:path";
const standalone = ".next/standalone";
const staticSource = ".next/static";
const publicSource = "public";
function copyDir(source, target) {
if (!existsSync(source)) {
return;
}
mkdirSync(target, { recursive: true });
cpSync(source, target, { recursive: true });
}
function serverDirs() {
if (!existsSync(standalone)) {
return [];
}
const dirs = [];
if (existsSync(join(standalone, "server.js"))) {
dirs.push(standalone);
}
for (const entry of readdirSync(standalone, { withFileTypes: true })) {
if (!entry.isDirectory()) {
continue;
}
const candidate = join(standalone, entry.name);
if (existsSync(join(candidate, "server.js"))) {
dirs.push(candidate);
}
}
return dirs;
}
for (const dir of serverDirs()) {
copyDir(staticSource, join(dir, ".next/static"));
copyDir(publicSource, join(dir, "public"));
}
if (!existsSync(join(standalone, "server.js"))) {
const nested = serverDirs().find((dir) => dir !== standalone);
if (nested) {
cpSync(nested, standalone, { recursive: true });
copyDir(staticSource, join(standalone, ".next/static"));
copyDir(publicSource, join(standalone, "public"));
}
}