forked from nikita/muzika-gromche
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import sharp from 'sharp';
|
|
import toIco from 'png-to-ico';
|
|
import { promises as fs } from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const sourceIcon = path.resolve(__dirname, '../../icon.png');
|
|
const outputDir = path.resolve(__dirname, '../public');
|
|
|
|
async function generateIcons() {
|
|
await fs.mkdir(outputDir, { recursive: true });
|
|
|
|
// Generate PNGs
|
|
const sizes = [32, 192, 256];
|
|
for (const size of sizes) {
|
|
const outputPath = path.join(outputDir, `icon-${size}.png`);
|
|
await sharp(sourceIcon)
|
|
.resize(size, size)
|
|
.toFile(outputPath);
|
|
console.log(`Generated ${outputPath}`);
|
|
}
|
|
|
|
// Generate apple-touch-icon
|
|
const appleIconPath = path.join(outputDir, 'apple-touch-icon.png');
|
|
await sharp(sourceIcon)
|
|
.resize(180, 180)
|
|
.toFile(appleIconPath);
|
|
console.log(`Generated ${appleIconPath}`);
|
|
|
|
// Generate favicon.ico
|
|
const icoSizes = [16, 24, 32, 48];
|
|
const buffers = await Promise.all(icoSizes.map(size =>
|
|
sharp(sourceIcon)
|
|
.resize(size, size)
|
|
.png()
|
|
.toBuffer()
|
|
));
|
|
const icoBuffer = await toIco(buffers);
|
|
const icoPath = path.join(outputDir, 'favicon.ico');
|
|
await fs.writeFile(icoPath, icoBuffer);
|
|
console.log(`Generated ${icoPath}`);
|
|
}
|
|
|
|
generateIcons().catch(err => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|