import { existsSync, mkdirSync, readdirSync, copyFileSync } from "node:fs"
import path from "node:path"
import { fileURLToPath } from "node:url"

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const drawImageDir = path.resolve(__dirname, "..")
const lucideSrc = path.join(drawImageDir, "node_modules", "lucide-static", "icons")
const lucideDst = path.join(drawImageDir, "icons", "lucide")

if (!existsSync(lucideSrc)) {
  console.log("lucide-static not installed, skipping icon sync")
  process.exit(0)
}

mkdirSync(lucideDst, { recursive: true })
let count = 0
for (const file of readdirSync(lucideSrc)) {
  if (file.endsWith(".svg")) {
    copyFileSync(path.join(lucideSrc, file), path.join(lucideDst, file))
    count++
  }
}
console.log(`synced ${count} lucide icons`)