diff --git a/package.json b/package.json index 322becd..85164a2 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,11 @@ "url": "git+https://github.com/fjaeckel/seriesoftubes.git" }, "scripts": { - "test": "node --test --test-concurrency=1 tests/game.test.js tests/build.test.js tests/persist.test.js tests/services.test.js tests/peering.test.js tests/inbox.test.js tests/latency.test.js tests/supply.test.js tests/issues.test.js tests/regions.test.js tests/modes.test.js tests/levels.test.js tests/speed.test.js tests/i18n.test.js tests/routing-reference.test.js tests/perf.test.js tests/sea-routing.test.js tests/subsea-upgrade-timing.test.js", - "build": "bash scripts/build.sh", + "test": "node scripts/test.js", + "build": "node scripts/build.js", "i18n:check": "node scripts/i18n-check.js", + "dev": "node scripts/dev.js", + "page": "node scripts/lib/page.js", "serve": "npm run build && npx --yes serve@14.2.4 _site", "perf": "node scripts/perf-bench.js" }, diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 0000000..60e6159 --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node +// Builds the deployable site into _site/ (or $OUT) for GitHub Pages: copies the static files in site/, +// assembles the game page from src/ into one index.html, and stamps the version (from package.json) and +// the build date into the files that carry them. The output is plain static files and nothing else, +// because GitHub Pages is where the game lives (docs/adr/0001-github-pages-only.md). +// +// npm run build VERSION, BUILD_DATE and OUT can be set in the environment +// REQUIRE_NOTES=1 npm run build fail when CHANGELOG.md has no bullets for this version +const fs = require('node:fs'); +const path = require('node:path'); +const { execFileSync } = require('node:child_process'); +const { assemble, ROOT } = require('./lib/page'); + +const VERSION = process.env.VERSION || require(path.join(ROOT, 'package.json')).version; +const BUILD_DATE = process.env.BUILD_DATE || new Date().toISOString().slice(0, 10); +const OUT = path.resolve(ROOT, process.env.OUT || '_site'); +const die = (msg) => { console.error(`error: ${msg}`); process.exit(1); }; + +if (!/^[0-9]+\.[0-9]+\.[0-9]+([-.+][0-9A-Za-z.-]+)?$/.test(VERSION)) die(`VERSION '${VERSION}' is not a semantic version`); +if (!/^\d{4}-\d{2}-\d{2}$/.test(BUILD_DATE)) die(`BUILD_DATE '${BUILD_DATE}' is not YYYY-MM-DD`); +if (OUT === ROOT || OUT === path.join(ROOT, 'site') || OUT === path.join(ROOT, 'src')) die(`refusing to build into ${OUT}`); + +fs.rmSync(OUT, { recursive: true, force: true }); +fs.cpSync(path.join(ROOT, 'site'), OUT, { recursive: true }); +if (fs.existsSync(path.join(OUT, 'index.html'))) die('site/index.html must not exist: the page is assembled from src/'); +fs.writeFileSync(path.join(OUT, 'index.html'), assemble().html); + +for (const f of ['index.html', 'sitemap.xml', 'llms.txt', 'sw.js']) { + const p = path.join(OUT, f); + fs.writeFileSync(p, fs.readFileSync(p, 'utf8').replaceAll('__VERSION__', VERSION).replaceAll('__BUILD_DATE__', BUILD_DATE)); +} + +// Release notes for this version, baked into the page ("What's new") and published as version.json so +// open games can spot a newer release. +const notes = execFileSync(process.execPath, [path.join(__dirname, 'release-notes.js'), VERSION], { encoding: 'utf8' }); +if (process.env.REQUIRE_NOTES === '1' && notes === '[]') die(`CHANGELOG.md has no '## [${VERSION}]' section with bullets (still under [Unreleased]?)`); +const page = path.join(OUT, 'index.html'), PH = '/*__RELEASE_NOTES__*/[]', html = fs.readFileSync(page, 'utf8'); +if (!html.includes(PH)) die('release-notes placeholder missing from the page'); +// Function replacer: no $& / $$ expansion. Escape "<" so a note can never close the '; +const clients = new Set(); + +function page() { + const { html, map } = assemble(); + // Errors report a line of the assembled page; the console also says which file under src/ that is. + const hint = ``; + return html.replace('
-A free cartoon browser game about how the internet works. Start as a tiny network in one city, launch home broadband, buy IP transit from Tier 1 and Tier 2 carriers, peer at internet exchanges, set up private interconnects and embedded CDN caches, and lay terrestrial fiber, subsea waves and your own dark fiber with DWDM and ZR optics. Sign enterprise, hosting, high-frequency trading, AI GPU and hyperscaler customers, and keep them happy while backhoes, sharks, fat fingers, route leaks, DDoS attacks and geopolitics break things.
-