import { copyFileSync, existsSync, readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'

export function copyFilesFlat(srcDir, destDir, { exclude = [] } = {}) {
  const skip = new Set(exclude)
  for (const name of readdirSync(srcDir)) {
    if (skip.has(name)) continue
    const from = join(srcDir, name)
    if (statSync(from).isDirectory()) continue
    const to = join(destDir, name)
    if (existsSync(to)) {
      throw new Error(`asset collision: ${name} (from ${srcDir}, already present in ${destDir})`)
    }
    copyFileSync(from, to)
  }
}
