v0.8.0.15 wrote a Quickstart for a tester who has never played and then left it in docs/, where a tester does not look — reachable only by somebody who already has the repository. Nobody handed the box had it. build-web.ts now copies it to dist/quickstart.md and the splash page offers it under the three doors, as a line rather than a fourth door: reading the guide is not a way to play, and giving it equal weight in that grid would say it is. COPIED, NEVER RE-WRITTEN. The Markdown document stays the one copy. A hand-written HTML twin drifts from it on the first edit, which is the failure #15a was raised about and precisely what the v0.8.0.15 pass spent itself undoing. It is served as PLAIN TEXT, which is honest rather than good — tables render as pipes and the links do not click. Rendering it into a styled page wants a small Markdown converter and is filed as TODO #109; build-web.ts's comment names that number rather than gesturing at "the next step", so the file and the worklist cannot drift the way the references just did. Two things had to be true and tsc checks neither, so both are tests. The href on the splash page and the filename the build writes are two strings with nothing connecting them: rename the document and the build quietly publishes nothing while the page keeps offering a link that 404s. And a .md file must not arrive as a download — the server's MIME fallback is application/octet-stream, which a browser saves instead of displaying, so the link would have handed a tester a file to save rather than a page to read. '.md' is in http.ts's table now, and the test reads that table out of the source rather than asserting on a copy of it, which would pass while the real one was wrong. VERIFIED AGAINST A RUNNING SERVER, not only compiled: 200, text/plain; charset=utf-8, the guide's own first lines, and the splash link resolving. THE sortsCars COMMENT. Asked after v0.8.0.15 whether everything now agreed, and the audit turned up one place that did not — the field's own doc comment named the card's printed text as though it were the flag's meaning. Nothing reads it to permit a sort; its two readers, resolveExtraStart in apply.ts and the enumeration in legal.ts, both ask whether this is the one Mainline card with a Yard Limit and therefore the one an Extra may be made up and started on. Comment only, and worth the bump because of where it is: it is what a developer reads before using the flag, and it is the likeliest source of the sentence v0.8.0.15 had to correct off the board. The name is kept for its link to the card face and the comment now says outright that the name is not the meaning. The five references and docs/design.md read v0.8.0.16. They describe this build because the audit re-checked them against it, not because the number was swept forward — a stamp bumped without a reading is worth less than none. 1001 fast tests and 35 sim tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MUizFYCMHRWhbWwXhp7WPR
233 lines
9.8 KiB
TypeScript
233 lines
9.8 KiB
TypeScript
/**
|
|
* Build the static solitaire site into `dist/`.
|
|
*
|
|
* Everything here is BUILD-time. The output is plain files on disk — upload them anywhere that
|
|
* serves static content and the game runs entirely in the visitor's browser. No server, no API, no
|
|
* network call at runtime.
|
|
*
|
|
* The one thing a browser cannot do is run TypeScript: Node 22's type-stripping is a Node feature.
|
|
* So `tsc` emits ES2022 modules, rewriting the `.ts` import extensions the engine uses into `.js`.
|
|
*/
|
|
|
|
import { execFileSync } from 'node:child_process';
|
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
/**
|
|
* Overridable so a test can point the build at an isolated directory instead of the shared
|
|
* `dist/` the rest of the suite reads — see `test/web.test.ts`'s "builds, and needs nothing but a
|
|
* static host". Must be a sibling of `dist/`, not nested inside it: this script's own `rmSync`
|
|
* below wipes the whole directory it is given, so nesting one inside the other would still race.
|
|
*/
|
|
const dist = join(root, process.env['BUILD_DIST_DIR'] ?? 'dist');
|
|
|
|
rmSync(dist, { recursive: true, force: true });
|
|
mkdirSync(dist, { recursive: true });
|
|
|
|
execFileSync(
|
|
'npx',
|
|
[
|
|
'tsc',
|
|
'--ignoreConfig',
|
|
'src/web/main.ts',
|
|
'src/web/splash.ts',
|
|
'src/web/replays.ts',
|
|
'--outDir', dist,
|
|
'--rootDir', 'src',
|
|
'--target', 'es2022',
|
|
'--module', 'es2022',
|
|
'--moduleResolution', 'bundler',
|
|
'--lib', 'es2022,dom',
|
|
'--types', '',
|
|
'--strict',
|
|
'--allowImportingTsExtensions',
|
|
'--rewriteRelativeImportExtensions',
|
|
],
|
|
{ cwd: root, stdio: 'inherit' },
|
|
);
|
|
|
|
/**
|
|
* Stamp the build into the page.
|
|
*
|
|
* Once this is published, "what is actually deployed?" stops being answerable by looking at the
|
|
* source. The stamp is written into index.html at copy time rather than generated into `src/`, so
|
|
* no generated file has to be ignored, imported, or kept in step.
|
|
*
|
|
* `-dirty` marks a build made from an uncommitted tree — the honest state of most test deploys, and
|
|
* exactly the thing you want to know when a fix appears to have had no effect.
|
|
*/
|
|
function buildStamp(): string {
|
|
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as { version: string };
|
|
/**
|
|
* THE FALLBACK HAS TO BE UNIQUE PER BUILD, because this string is also the cache-bust key.
|
|
*
|
|
* It used to be the literal `nogit`, which is exactly what the `.s9pk` build produces — the
|
|
* Dockerfile copies the working tree in without `.git`, so `git rev-parse` fails there every time.
|
|
* Every packaged release therefore published `?v=nogit`, byte-identical to the release before it,
|
|
* and a returning player's browser had no reason to refetch a single module. v0.7.5's setup screen
|
|
* and v0.7.6's fix to it both shipped correctly to `phoenix.local` and neither reached the browser
|
|
* that asked for them (Jesse, twice, 2026-08-29 — "setup did not work").
|
|
*
|
|
* A marker plus the build's own timestamp is always distinct, needs nothing from the environment,
|
|
* and stays honest: two builds of the same commit ARE two deploys, and a cache key that says so
|
|
* costs one refetch, while one that lies costs a release nobody receives.
|
|
*
|
|
* NOT THE VERSION, which is what this used to lead with. The stamp below already begins with
|
|
* `v${pkg.version}`, so on exactly the builds that take this path — every `.s9pk`, which has no
|
|
* `.git` — the header read "v0.8.0.10 · 0.8.0.10-mfq2p1 · …" and the version appeared twice
|
|
* (Jesse, playtest 2026-09-16). The timestamp alone carries the uniqueness; the version is
|
|
* already said once, properly, at the front.
|
|
*/
|
|
let git = `nogit-${Date.now().toString(36)}`;
|
|
try {
|
|
const sha = execFileSync('git', ['rev-parse', '--short', 'HEAD'], { cwd: root })
|
|
.toString()
|
|
.trim();
|
|
const dirty =
|
|
execFileSync('git', ['status', '--porcelain'], { cwd: root }).toString().trim().length > 0;
|
|
git = sha + (dirty ? '-dirty' : '');
|
|
} catch {
|
|
// A build from a tarball with no git history is still a valid build.
|
|
}
|
|
const when = new Date().toISOString().replace('T', ' ').slice(0, 16);
|
|
return `v${pkg.version} · ${git} · ${when}Z`;
|
|
}
|
|
|
|
const stamp = buildStamp();
|
|
|
|
/**
|
|
* Cache-bust every module.
|
|
*
|
|
* A returning visitor gets a fresh index.html and STALE JavaScript, because a static host caches
|
|
* .js and the filenames never change. That is not a cosmetic staleness: it mixes new HTML with old
|
|
* code, and the first mismatch is fatal. It happened on the first real deploy — index.html had
|
|
* dropped an element that the cached main.js still asked for, so the page threw
|
|
* `missing element: target` and the game never started.
|
|
*
|
|
* Appending the build tag to every relative import makes each deploy a new set of URLs, so a
|
|
* browser cannot serve half of one build and half of another.
|
|
*/
|
|
const tag = encodeURIComponent(stamp.split(' · ')[1] ?? stamp);
|
|
|
|
function bustImports(dir: string): number {
|
|
let count = 0;
|
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
const full = join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
count += bustImports(full);
|
|
continue;
|
|
}
|
|
if (!entry.name.endsWith('.js')) continue;
|
|
const src = readFileSync(full, 'utf8');
|
|
const next = src.replace(
|
|
/^(\s*(?:import|export)[^'"\n]*?from\s+['"])(\.[^'"]+\.js)(['"])/gm,
|
|
(_m, head: string, spec: string, tail: string) => `${head}${spec}?v=${tag}${tail}`,
|
|
);
|
|
if (next !== src) {
|
|
writeFileSync(full, next);
|
|
count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
const busted = bustImports(dist);
|
|
|
|
// Three pages now: the splash, the game, and the replay directory. Each is stamped and each has
|
|
// its entry script cache-busted, or a returning visitor gets new HTML against old modules.
|
|
for (const name of ['index.html', 'play.html', 'replays.html']) {
|
|
const page = readFileSync(join(root, 'src/web', name), 'utf8')
|
|
.replaceAll('__BUILD__', stamp)
|
|
.replace(/(<script type="module" src="[^"]+?\.js)(")/, `$1?v=${tag}$2`);
|
|
writeFileSync(join(dist, name), page);
|
|
}
|
|
|
|
/**
|
|
* Publish whatever replays are in `public/replays/`, plus an index of them.
|
|
*
|
|
* Static hosting cannot list a directory, so the page needs a manifest. A replay is a save — seed
|
|
* plus moves — so these are a few hundred bytes each, not megabytes.
|
|
*/
|
|
const replaySrc = join(root, 'public/replays');
|
|
const replayOut = join(dist, 'replays');
|
|
mkdirSync(replayOut, { recursive: true });
|
|
const manifest: { file: string; title: string; note?: string; seed?: number }[] = [];
|
|
if (existsSync(replaySrc)) {
|
|
for (const f of readdirSync(replaySrc).filter((n) => n.endsWith('.json') && n !== 'manifest.json')) {
|
|
const raw = readFileSync(join(replaySrc, f), 'utf8');
|
|
try {
|
|
const save = JSON.parse(raw) as { seed?: number; title?: string; note?: string; history?: unknown[] };
|
|
if (typeof save.seed !== 'number' || !Array.isArray(save.history)) {
|
|
console.warn(` skipped ${f} — not a Station Master save`);
|
|
continue;
|
|
}
|
|
writeFileSync(join(replayOut, f), raw);
|
|
manifest.push({
|
|
file: f,
|
|
title: save.title ?? f.replace(/\.json$/, ''),
|
|
...(save.note ? { note: save.note } : {}),
|
|
seed: save.seed,
|
|
});
|
|
} catch {
|
|
console.warn(` skipped ${f} — could not be parsed`);
|
|
}
|
|
}
|
|
}
|
|
writeFileSync(join(replayOut, 'manifest.json'), JSON.stringify(manifest, null, 1));
|
|
|
|
/**
|
|
* Static images — the splash artwork and whatever joins it. Copied verbatim, unlike the replays
|
|
* above: an image needs no validation, only a place in `dist/` to be served from.
|
|
*/
|
|
const imageSrc = join(root, 'public/images');
|
|
if (existsSync(imageSrc)) {
|
|
const imageOut = join(dist, 'images');
|
|
mkdirSync(imageOut, { recursive: true });
|
|
for (const f of readdirSync(imageSrc)) copyFileSync(join(imageSrc, f), join(imageOut, f));
|
|
}
|
|
|
|
/**
|
|
* The Quickstart, published beside the game so a tester can reach it from the box.
|
|
*
|
|
* COPIED, NOT RE-WRITTEN. `docs/StationMaster-Quickstart.md` is the one copy; a hand-written HTML
|
|
* twin would drift from it on the first edit, which is the whole lesson of TODO #15a and of the
|
|
* 2026-09-20 documentation pass that found four references a month out of date.
|
|
*
|
|
* SERVED AS PLAIN TEXT for now, which is honest rather than good: tables render as pipes and the
|
|
* links do not click. Rendering it into a styled page needs a small Markdown converter and is
|
|
* filed as TODO #109 — this is the fifteen-minute version that gets the guide in front of testers
|
|
* for this round rather than leaving them without one.
|
|
*/
|
|
const guideSrc = join(root, 'docs/StationMaster-Quickstart.md');
|
|
if (existsSync(guideSrc)) {
|
|
copyFileSync(guideSrc, join(dist, 'quickstart.md'));
|
|
} else {
|
|
// Loud rather than silent: a missing guide is a broken link on the splash page, and the build is
|
|
// the only place that can still notice.
|
|
console.error('WARNING: docs/StationMaster-Quickstart.md is missing — the splash link will 404');
|
|
}
|
|
|
|
// A tiny note for whoever unzips this later and wonders what it needs.
|
|
writeFileSync(
|
|
join(dist, 'README.txt'),
|
|
[
|
|
'Station Master — solitaire, static build.',
|
|
'',
|
|
'Upload the contents of this folder to any static host and open index.html.',
|
|
'There is no server component. The game runs entirely in the browser and saves',
|
|
'to localStorage. Add ?seed=1234 to the URL for a reproducible deal.',
|
|
'',
|
|
'Note: ES modules require the files to be SERVED over http(s). Opening',
|
|
'index.html directly from the filesystem will be blocked by the browser.',
|
|
'To try it locally: npx http-server dist (or any static file server)',
|
|
'',
|
|
].join('\n'),
|
|
);
|
|
|
|
console.log(
|
|
`built -> ${dist}\n ${stamp}\n cache-busted ${busted} modules with ?v=${tag}` +
|
|
`\n ${manifest.length} replay(s) published`,
|
|
);
|