/** * copy-pwa-icons.mjs — rename the @vite-pwa/assets-generator outputs to the * stable filenames the hand-maintained manifest references (WR-08). * * The generator emits preset-named files (pwa-192x192.png, …). The manifest in * vite.config.ts references stable names (/icon-192.png, …) so a generator * version bump that renames its outputs surfaces here as a clear, named error * rather than an opaque shell `cp: cannot stat`. This replaces a Unix-only `cp` * chain so Windows contributors and minimal CI containers can run `pwa:icons`. * * Keep COPIES in sync with the manifest `icons` array in vite.config.ts. * * NOTE (IN-02): public/favicon.ico is NOT produced by this script — the * minimal2023Preset does not emit a .ico. It is hand-maintained and committed * directly in public/, and referenced by index.html (``). When the brand mark changes, regenerate favicon.ico * manually so it does not go stale relative to the SVG/PNG outputs below. */ import { copyFileSync, existsSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; const here = dirname(fileURLToPath(import.meta.url)); const publicDir = join(here, '..', 'public'); /** [generated source name, stable destination name referenced by the manifest] */ const COPIES = [ ['pwa-192x192.png', 'icon-192.png'], ['pwa-512x512.png', 'icon-512.png'], ['maskable-icon-512x512.png', 'icon-maskable-512.png'], ['apple-touch-icon-180x180.png', 'apple-touch-icon.png'], ['logo.svg', 'favicon.svg'], ]; let failed = false; for (const [src, dest] of COPIES) { const from = join(publicDir, src); const to = join(publicDir, dest); if (!existsSync(from)) { console.error( `[pwa:icons] expected generated file not found: public/${src}\n` + ` The assets generator output names may have changed — update COPIES in\n` + ` apps/pwa/scripts/copy-pwa-icons.mjs and the manifest in vite.config.ts.`, ); failed = true; continue; } copyFileSync(from, to); console.log(`[pwa:icons] public/${src} → public/${dest}`); } if (failed) process.exit(1);