{"version":3,"file":"copy-files-plugin.cjs","names":[],"sources":["../../src/copy-files-plugin.ts"],"sourcesContent":["import { copyFile, mkdir } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport { glob } from 'tinyglobby'\nimport type { Plugin } from 'vite'\n\nexport function copyFilesPlugin({\n  fromDir,\n  toDir,\n  pattern = '**',\n}: {\n  pattern?: string | Array<string>\n  fromDir: string\n  toDir: string\n}): Plugin {\n  return {\n    name: 'copy-files',\n    async writeBundle() {\n      const entries = await glob(pattern, { cwd: fromDir })\n      if (entries.length === 0) {\n        throw new Error(\n          `No files found matching pattern \"${pattern}\" in directory \"${fromDir}\"`,\n        )\n      }\n\n      for (const entry of entries) {\n        const srcPath = join(fromDir, entry)\n        const destPath = join(toDir, entry)\n        // Ensure the destination directory exists\n        await mkdir(dirname(destPath), { recursive: true })\n        await copyFile(srcPath, destPath)\n      }\n    },\n  }\n}\n"],"mappings":";;;;AAKA,SAAgB,gBAAgB,EAC9B,SACA,OACA,UAAU,QAKD;CACT,OAAO;EACL,MAAM;EACN,MAAM,cAAc;GAClB,MAAM,UAAU,OAAA,GAAA,WAAA,MAAW,SAAS,EAAE,KAAK,QAAQ,CAAC;GACpD,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MACR,oCAAoC,QAAQ,kBAAkB,QAAQ,EACxE;GAGF,KAAK,MAAM,SAAS,SAAS;IAC3B,MAAM,WAAA,GAAA,MAAA,MAAe,SAAS,KAAK;IACnC,MAAM,YAAA,GAAA,MAAA,MAAgB,OAAO,KAAK;IAElC,OAAA,GAAA,iBAAA,QAAA,GAAA,MAAA,SAAoB,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;IAClD,OAAA,GAAA,iBAAA,UAAe,SAAS,QAAQ;GAClC;EACF;CACF;AACF"}