import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import sharp from "sharp";

const __dirname = dirname(fileURLToPath(import.meta.url));
const publicDir = join(__dirname, "..", "public");
const source = join(publicDir, "logo.png");

if (!existsSync(source)) {
	console.warn("[generate-icons] logo.png not found, skipping");
	process.exit(0);
}

for (const size of [192, 512]) {
	const out = join(publicDir, `logo${size}.png`);
	await sharp(source)
		.resize(size, size, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } })
		.png()
		.toFile(out);
	console.log(`[generate-icons] wrote ${out}`);
}
