Files
Battle-for-Tismo/scripts/generate-devlog.js
adrien f3e94a3d53 Added the devlog, fixed the map labels and reworked joining
- Political map country names were invisible because the label SVG had a zero-sized viewport, which some browsers never paint; size it to the world and guard it with a test.
- Added a Devlog button showing the ten latest commits, generated into client/js/devlog_data.js by scripts/generate-devlog.js and refreshed by the pre-commit hook.
- Worked through FIXME.md: the city button and a unit double-click now open the city, and the stat tooltip escapes the HUD so the unit panel cannot cover it.
- The server creates its game at startup and clients only join it; the Create game screen and the configure_game path are gone, and testing is a --testing server flag.
- A page on a loopback host signs in as adrien, claims France and gets the free, instant testing buttons, while the server grants free orders only to a loopback socket whose Origin is also loopback.
2026-09-21 23:08:05 +02:00

75 lines
2.4 KiB
JavaScript

#!/usr/bin/env node
// Regenerates the devlog data module from the last few commits. The client has
// no build step, so the list the main menu shows has to live in the tree; this
// script keeps it current and is run by the pre-commit hook (and by hand with
// `node scripts/generate-devlog.js`).
//
// The file is written only when it changes, so an unchanged history does not
// touch the working tree.
import { execFileSync } from "node:child_process";
import { readFileSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
const OUT = join(ROOT, "client", "js", "devlog_data.js");
// How many commits the Devlog shows.
const COUNT = 10;
// Field separator inside a commit record and the record separator between
// commits. Neither byte is legal in a git commit message.
const FIELD = "\x1f";
const RECORD = "\x1e";
function lastCommits() {
const pretty = `--pretty=format:%h${FIELD}%cs${FIELD}%s${FIELD}%b${RECORD}`;
const out = execFileSync("git", ["log", `-n${COUNT}`, pretty], {
cwd: ROOT,
encoding: "utf8",
});
return out
.split(RECORD)
// `git log` puts a newline between records; drop the leading ones.
.map((record) => record.replace(/^\n+/, ""))
.filter((record) => record.trim().length > 0)
.map((record) => {
const [hash, date, subject, body = ""] = record.split(FIELD);
return {
hash: hash.trim(),
date: date.trim(),
subject: subject.trim(),
body: body.trim(),
};
});
}
function source(commits) {
return (
"// Generated by scripts/generate-devlog.js from `git log`; do not edit.\n" +
"// The pre-commit hook refreshes it so the main menu shows the latest commits.\n" +
`export const DEVLOG = ${JSON.stringify(commits, null, 2)};\n`
);
}
let commits;
try {
commits = lastCommits();
} catch (error) {
console.warn(`generate-devlog: could not read the git history (${error.message})`);
process.exit(0);
}
const next = source(commits);
let previous = "";
try {
previous = readFileSync(OUT, "utf8");
} catch {
// First run: the file does not exist yet.
}
if (next === previous) {
console.log(`generate-devlog: ${OUT} is already up to date (${commits.length} commits)`);
} else {
writeFileSync(OUT, next);
console.log(`generate-devlog: wrote ${commits.length} commits to ${OUT}`);
}