11 lines
856 B
JavaScript
11 lines
856 B
JavaScript
import sharp from 'sharp';
|
|
import { readFile } from 'node:fs/promises';
|
|
const brand = (await readFile(new URL('../public/logo.svg', import.meta.url), 'utf8'))
|
|
.replace(/<\?xml[^>]*\?>/, '').replace(/<svg[^>]*>/, '').replace(/<\/svg>\s*$/, '');
|
|
for (const [name, size, inset] of [['icon-192.png', 192, 15], ['icon-512.png', 512, 15], ['icon-maskable.png', 512, 25], ['apple-touch-icon.png', 180, 15]]) {
|
|
const side = 100 - inset * 2;
|
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100"><rect width="100" height="100" fill="#f3f3fa"/><g transform="translate(${inset} ${inset}) scale(${side / 59})">${brand}</g></svg>`;
|
|
await sharp(Buffer.from(svg)).resize(size, size).png().toFile(new URL(`../public/${name}`, import.meta.url).pathname);
|
|
}
|
|
console.log('RideBus PWA icons generated');
|