Something went wrong. Try again.
Web frontend and supporting services for lance.blue
Something went wrong. Try again.
2.4 kB · 71 lines
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172/** * Copies the daily-challenge scenario files into web/public/ so the site can * hand one to a player as a download. * * npm run daily-public * npm run daily-public -- --check * * They live under services/api/src/matches/daily/ because the API launches * from them — it sends the file itself in the launch manifest, so it has to * be inside the API's own build context, and web/ is not. The copies here are * the same bytes, served statically: a download that went through the control * plane would be a download that fails whenever the control plane does, and * this file is what says the two copies agree. * * Sibling of megamek-units.mjs, and the same bargain: the output is committed, * so neither the build nor the tests need this to have been run. */import { readdir, readFile, writeFile } from "node:fs/promises";import { join } from "node:path";import { fileURLToPath } from "node:url";
const repo = fileURLToPath(new URL("../..", import.meta.url));const from = join(repo, "services/api/src/matches/daily");const to = join(repo, "web/public/daily");const check = process.argv.includes("--check");
const names = (await readdir(from)).filter((n) => n.endsWith(".mms")).sort();if (names.length === 0) { console.error(`no scenario files in ${from}`); process.exit(1);}
let stale = 0;for (const name of names) { const source = await readFile(join(from, name)); let current = null; try { current = await readFile(join(to, name)); } catch { /* not copied yet */ } if (current && current.equals(source)) continue; stale += 1; if (check) { console.error( `${name}: web/public/daily/ is ${current ? "stale" : "missing it"}`, ); } else { await writeFile(join(to, name), source); console.log(`copied ${name}`); }}
// A file in public/ that no longer has a source is a scenario a player can// still download and nothing can still launch.const copied = (await readdir(to)).filter((n) => n.endsWith(".mms"));for (const name of copied) { if (names.includes(name)) continue; stale += 1; console.error(`${name}: in web/public/daily/ with no scenario behind it`);}
if (check && stale > 0) { console.error(`\n${stale} file(s) out of step; run: npm run daily-public`); process.exit(1);}console.log( check ? `${names.length} scenario files match` : `${names.length} scenario files in public/`,);