eCourt-note/scripts/copy-swagger-ui.mjs

31 lines
2 KiB
JavaScript
Raw Normal View History

2026-10-07 10:16:12 +07:00
// คัดลอก asset ของ Swagger UI (swagger-ui-dist) จาก node_modules ไป public/
// ให้ route handler GET /api/template อ้าง URL ได้ (/docedit/note/swagger-ui/…)
// — ระบบใช้ใน intranet จึง self-host ทุกอย่าง (ไม่โหลดจาก CDN เหมือนเรื่องฟอนต์)
//
// ไฟล์ที่ต้องมีครบ 2 ตัว: bundle (JS) + CSS — หายตัวไหน (เช่นเปลี่ยนชื่อหลัง
// อัปเกรด swagger-ui-dist) = exit 1 ดัง ๆ ทันที ไม่ปล่อยให้หน้า Swagger UI
// เป็นหน้าเปล่าเงียบ ๆ (pattern เดียวกับ scripts/patch-pdf-worker.mjs)
import { copyFileSync, mkdirSync } from "node:fs";
import { dirname } from "node:path";
// statics ของแอปอยู่ใต้ public/note/** (URL /docedit/note/… — basePath /docedit + route prefix /note)
const FILES = [
["node_modules/swagger-ui-dist/swagger-ui-bundle.js", "public/note/swagger-ui/swagger-ui-bundle.js"],
["node_modules/swagger-ui-dist/swagger-ui.css", "public/note/swagger-ui/swagger-ui.css"],
];
for (const [src, dest] of FILES) {
try {
// Dockerfile mkdir แค่ public/ เปล่า ๆ — script ต้องสร้าง dir ปลายทางเอง
mkdirSync(dirname(dest), { recursive: true });
copyFileSync(src, dest);
} catch {
console.error(
`[copy-swagger-ui] คัดลอก ${src} ไม่ได้ — ` +
`เช็คว่า swagger-ui-dist ติดตั้งแล้ว/ชื่อไฟล์ยังเหมือนเดิมหลังอัปเกรด (ปรับ FILES ใน scripts/copy-swagger-ui.mjs)`,
);
process.exit(1);
}
}
console.log("[copy-swagger-ui] คัดลอก Swagger UI asset เรียบร้อย");