Files

23 lines
1010 B
JavaScript
Raw Permalink Normal View History

#!/usr/bin/env node
// 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.)
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");
const match = contents.match(/SHELL_VERSION = "v(\d+)"/);
if (!match) {
console.error(`Couldn't find SHELL_VERSION in ${swPath}`);
process.exit(1);
}
const next = Number(match[1]) + 1;
const updated = contents.replace(/SHELL_VERSION = "v\d+"/, `SHELL_VERSION = "v${next}"`);
await writeFile(swPath, updated);
console.log(`Bumped service worker SHELL_VERSION to v${next}`);