import { cpSync, existsSync, mkdirSync } from 'fs'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'

const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const src = join(root, 'node_modules/three/examples/jsm/libs/draco/gltf')
const dest = join(root, 'public/draco/gltf')

if (!existsSync(src)) {
  console.warn('[copy-draco] three draco libs not found, skip')
  process.exit(0)
}

mkdirSync(dest, { recursive: true })
for (const name of ['draco_decoder.wasm', 'draco_wasm_wrapper.js']) {
  cpSync(join(src, name), join(dest, name), { force: true })
}
console.log('[copy-draco] copied draco decoder to public/draco/gltf')
