2026-08-23 05:25:15 +02:00
|
|
|
#!/usr/bin/env node
|
2026-08-24 14:42:38 +02:00
|
|
|
// Bumps public/sw.js's SHELL_VERSION so a deploy invalidates old shell
|
|
|
|
|
// caches — run this before cutting a release that changes SHELL_ASSETS or
|
|
|
|
|
// the shell's caching behavior. (The engine cache busts itself automatically
|
|
|
|
|
// from the installed vpinball-wasm version — see copy-engine-assets.mjs.)
|
2026-08-23 05:25:15 +02:00
|
|
|
import { readFile, writeFile } from "node:fs/promises";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
|
|
|
|
|
const rootDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
|
|
|
const swPath = path.join(rootDir, "public", "sw.js");
|
|
|
|
|
|
|
|
|
|
const contents = await readFile(swPath, "utf8");
|
2026-08-24 14:42:38 +02:00
|
|
|
const match = contents.match(/SHELL_VERSION = "v(\d+)"/);
|
2026-08-23 05:25:15 +02:00
|
|
|
if (!match) {
|
2026-08-24 14:42:38 +02:00
|
|
|
console.error(`Couldn't find SHELL_VERSION in ${swPath}`);
|
2026-08-23 05:25:15 +02:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
const next = Number(match[1]) + 1;
|
2026-08-24 14:42:38 +02:00
|
|
|
const updated = contents.replace(/SHELL_VERSION = "v\d+"/, `SHELL_VERSION = "v${next}"`);
|
2026-08-23 05:25:15 +02:00
|
|
|
await writeFile(swPath, updated);
|
2026-08-24 14:42:38 +02:00
|
|
|
console.log(`Bumped service worker SHELL_VERSION to v${next}`);
|