import sharp from 'sharp'
import * as fs from 'fs'
import * as path from 'path'
import { consola } from 'consola'
;(async () => {
  try {
    const dirPath = path.resolve('../../../public')

    if (fs.existsSync(dirPath)) {
      const inputSrc = '../../assets/images/logo.png'
      const favicon = dirPath + '/favicon.png'
      const faviconBuffer = await sharp(inputSrc).png({ quality: 90 }).resize(50).toBuffer()
      await sharp(faviconBuffer).toFile(favicon)
      consola.success('Favicon generated successfully')
    } else {
      consola.error('Directory does not exist:', dirPath)
    }
  } catch (error) {
    consola.error('Error generating favicon:', error)
  }
})()
