#!/usr/bin/env node // Bumps public/sw.js's CACHE_VERSION so a deploy invalidates old caches — // run this before cutting a release that changes the app shell or updates // the vendored vpinball-wasm engine build. 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(/CACHE_VERSION = "v(\d+)"/); if (!match) { console.error(`Couldn't find CACHE_VERSION in ${swPath}`); process.exit(1); } const next = Number(match[1]) + 1; const updated = contents.replace(/CACHE_VERSION = "v\d+"/, `CACHE_VERSION = "v${next}"`); await writeFile(swPath, updated); console.log(`Bumped service worker CACHE_VERSION to v${next}`);