output-files
Version:
Output a tree of files and directories by providing an object. Especially useful for testing with real files.
12 lines • 517 B
JavaScript
import pathLib from "node:path";
import fs from "fs-extra";
const outputFiles = async (...args) => {
const path = (typeof args[0] === "string" ? args[0] : "") || ".";
const files = (typeof args[0] === "string" ? args[1] : args[0]) || {};
await fs.ensureDir(path);
return Promise.all(Object.entries(files).map(([localPath, child]) => {
const absPath = pathLib.join(path, localPath);
return (typeof child === "string" ? fs.outputFile : outputFiles)(absPath, child);
}));
};
export default outputFiles;