#!/usr/bin/env node // Génère les fallbacks PNG du favicon (apple-touch-icon + 32px) depuis public/favicon.svg. // Lancé à la demande quand le SVG change : `node scripts/build-favicon.mjs`. import sharp from 'sharp'; import { readFileSync } from 'node:fs'; import { resolve, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; const __dirname = dirname(fileURLToPath(import.meta.url)); const SVG = resolve(__dirname, '../public/favicon.svg'); const buf = readFileSync(SVG); const outputs = [ { path: '../public/apple-touch-icon.png', size: 180 }, { path: '../public/favicon-32.png', size: 32 }, { path: '../public/favicon-192.png', size: 192 }, ]; for (const o of outputs) { const dest = resolve(__dirname, o.path); await sharp(buf, { density: 384 }) .resize(o.size, o.size, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } }) .png({ compressionLevel: 9 }) .toFile(dest); console.log(`Wrote ${dest} (${o.size}×${o.size})`); }