aboutsummaryrefslogtreecommitdiff
path: root/src/deepReadDir.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/deepReadDir.tsx')
-rw-r--r--src/deepReadDir.tsx12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/deepReadDir.tsx b/src/deepReadDir.tsx
new file mode 100644
index 0000000..ec585ec
--- /dev/null
+++ b/src/deepReadDir.tsx
@@ -0,0 +1,12 @@
+import {lstat, readdir} from 'node:fs/promises'
+import {join} from 'node:path'
+
+const deepReadDir = async (dirPath: string): Promise<string[]> => await Promise.all(
+ (await readdir(dirPath)).map(async (entity) => {
+ const path = join(dirPath, entity)
+ return (await lstat(path)).isDirectory() ? await deepReadDir(path) : path
+ }),
+).then(arr => arr.flat());
+
+
+export default deepReadDir;