const sharp = require('sharp');
const fs = require('fs');
const path = require('path');

// /app/data 디렉토리 사용
const DATA_DIR = path.join(__dirname, 'data');
const svgPath = path.join(DATA_DIR, 'icon.svg');

// icon.svg가 존재하는지 확인
if (!fs.existsSync(svgPath)) {
    console.error(`File not found: ${svgPath}`);
    process.exit(1);
}

const svgBuffer = fs.readFileSync(svgPath);

async function convert() {
    try {
        console.log('Converting icons from:', svgPath);
        await sharp(svgBuffer).resize(64, 64).png().toFile(path.join(DATA_DIR, 'favicon.png'));
        await sharp(svgBuffer).resize(192, 192).png().toFile(path.join(DATA_DIR, 'pwa-192x192.png'));
        await sharp(svgBuffer).resize(512, 512).png().toFile(path.join(DATA_DIR, 'pwa-512x512.png'));
        await sharp(svgBuffer).resize(180, 180).png().toFile(path.join(DATA_DIR, 'apple-touch-icon.png'));
        console.log('Conversion complete. Files saved to:', DATA_DIR);
    } catch (err) {
        console.error('Error converting icons:', err);
        process.exit(1);
    }
}
convert();
