Skip to content

Commit

Permalink
chore: Update readDir.js
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnAngela authored Jul 31, 2023
1 parent 2fb11dd commit ac8eb1c
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions scripts/modules/readDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ import fs from "fs";
* @param {boolean} [removePrefix]
* @returns {Promise<string[]>}
*/
const readDir = async (p, removePrefix = false) => {
const result = await Promise.all((await Promise.all((await fs.promises.readdir(p, { withFileTypes: true })).map((dirent) => path.join(p, dirent.name)).map(async (n) => [n, await fs.promises.stat(n)]))).filter(([, stat]) => stat.isFile() || stat.isDirectory()).map(async ([n, stat]) => stat.isFile() ? removePrefix ? n.replace(`${p}/`, "") : n : await readDir(path.join(n), removePrefix)));
return result.flat(999);
};
const readDir = async (p, removePrefix = false) => (await fs.promises.readdir(p, { recursive: true })).map((n) => removePrefix ? n : path.join(p, n));
export default readDir;

0 comments on commit ac8eb1c

Please sign in to comment.