fix(17): WR-08 replace cp icon chain with cross-platform Node copy script
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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);
|
||||
Reference in New Issue
Block a user