4b86b2a660
- server-dev start/stop/deploy 및 Gitea push 자동 배포 - local-dev 로컬 개발 환경 Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
const webRoot = path.resolve(scriptDir, "..");
|
|
const outRoot = path.join(webRoot, "out");
|
|
const sourceDir = outRoot;
|
|
const targetName = process.env.EXPORT_TARGET_DIR || "public";
|
|
const targetDir = path.join(webRoot, "..", targetName);
|
|
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "/chatbot/app";
|
|
const uiMode = process.env.NEXT_PUBLIC_UI_MODE || "app";
|
|
|
|
if (!fs.existsSync(sourceDir)) {
|
|
console.error(`[export-public] 빌드 출력 없음: ${sourceDir}`);
|
|
console.error("NEXT_PUBLIC_BASE_PATH=/chatbot/app npm run build:deploy");
|
|
process.exit(1);
|
|
}
|
|
|
|
function copyRecursive(src, dest) {
|
|
fs.mkdirSync(dest, { recursive: true });
|
|
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
const from = path.join(src, entry.name);
|
|
const to = path.join(dest, entry.name);
|
|
if (entry.isDirectory()) {
|
|
copyRecursive(from, to);
|
|
} else {
|
|
fs.copyFileSync(from, to);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (const name of fs.existsSync(targetDir) ? fs.readdirSync(targetDir) : []) {
|
|
const p = path.join(targetDir, name);
|
|
if (name === ".gitkeep") continue;
|
|
fs.rmSync(p, { recursive: true, force: true });
|
|
}
|
|
|
|
copyRecursive(sourceDir, targetDir);
|
|
|
|
const versionPath = path.join(targetDir, "VERSION");
|
|
const version = fs.existsSync(versionPath)
|
|
? fs.readFileSync(versionPath, "utf8").trim()
|
|
: "3.0.0";
|
|
const stamp = `${version} (${uiMode}@${basePath})`;
|
|
fs.writeFileSync(versionPath, `${stamp}\n`, "utf8");
|
|
|
|
console.log(`[export-public] ✅ ${sourceDir} → ${targetDir} (${stamp})`);
|