Skip to content

Commit

Permalink
chore: 简化 readDir (#287)
Browse files Browse the repository at this point in the history
* chore: Update readDir.js

* chore: Update package.json
  • Loading branch information
AnnAngela authored Jul 31, 2023
1 parent 2fb11dd commit 977d625
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"url": "https://github.com/MoegirlPediaInterfaceAdmins/MoegirlPediaInterfaceCodes.git"
},
"license": "",
"private": true,
"private": true,,
"engines": {
"node": "16.* || 18.*"
},
"node": "^18.17 || ^20.1"
}
"scripts": {
"test": "eslint src && stylelint src/**/*.css && v8r && node scripts/emailmapChecker/index.js",
"format": "eslint src --fix && stylelint src/**/*.css --fix",
Expand Down
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 977d625

Please sign in to comment.