forked from nikita/muzika-gromche
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { promises as fs } from 'node:fs'
|
|
import path from 'node:path'
|
|
import process from 'node:process'
|
|
import { fileURLToPath } from 'node:url'
|
|
import toIco from 'png-to-ico'
|
|
import sharp from 'sharp'
|
|
|
|
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)
|
|
})
|