// Generates PWA icons from the USWDS `accessible_forward` glyph (public domain / MIT). import { readFile, writeFile } from 'node:fs/promises'; import sharp from 'sharp'; const sprite = await readFile('public/uswds/sprite.svg', 'utf8'); const inner = sprite.match(/]*id="accessible_forward"[^>]*>([\s\S]*?)<\/symbol>/)?.[1]; if (!inner) throw new Error('glyph not found'); const svg = (size, scale, rounded) => ` ${inner} `; await writeFile('public/icons/icon.svg', svg(512, 512 * 0.62 / 24, true)); for (const [name, size, scale, rounded] of [ ['icon-192.png', 192, 192 * 0.62 / 24, true], ['icon-512.png', 512, 512 * 0.62 / 24, true], ['icon-maskable-512.png', 512, 512 * 0.5 / 24, false], ['apple-touch-icon.png', 180, 180 * 0.62 / 24, false], ]) { await sharp(Buffer.from(svg(size, scale, rounded))).png().toFile(`public/icons/${name}`); } console.log('icons ok');