23 lines
1.1 KiB
JavaScript
23 lines
1.1 KiB
JavaScript
// 從後端複製已產出的資料包到 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`);
|
||
}
|