election-game/web/scripts/sync-fixtures.mjs

23 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 從後端複製已產出的資料包到 public/fixtures,前端開發時不需要跑整套後端(docs/16)。
// 用法:pnpm sync-fixtures [縣市代碼...](預設 68000)
import { cpSync, existsSync, mkdirSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const backendPacks = process.env.BACKEND_PACKS ?? join(root, "..", "backend", "data", "build", "packs");
const counties = process.argv.slice(2).length ? process.argv.slice(2) : ["68000"];
for (const county of counties) {
const src = join(backendPacks, county);
if (!existsSync(src)) {
process.stderr.write(`找不到 ${src};請先在後端執行 election-data pack --county ${county}\n`);
process.exitCode = 1;
continue;
}
const dest = join(root, "public", "fixtures", "packs", county);
mkdirSync(dest, { recursive: true });
cpSync(src, dest, { recursive: true, filter: (p) => !p.endsWith("report.md") });
process.stdout.write(`已複製 ${county} → ${dest}\n`);
}