UNPKG

memserver

Version:

in-memory database/ORM and http mock server you can run in-browser and node environments. Built for large frontend teams, fast tests and rapid prototyping

32 lines (26 loc) 716 B
import path from 'path'; import fs from 'fs/promises'; export default async function recursiveCopy(sourcePath, targetPath) { try { await fs.access(sourcePath); let stats = await fs.stat(sourcePath); if (stats.isDirectory()) { try { await fs.access(targetPath); } catch { await fs.mkdir(targetPath); } let entries = await fs.readdir(sourcePath); await Promise.all( entries.map((entry) => recursiveCopy(path.join(sourcePath, entry), path.join(targetPath, entry)) ) ); } else { await fs.copyFile(sourcePath, targetPath); } } catch (error) { console.log("Recursive copy error:"); throw error; } }