aboutsummaryrefslogtreecommitdiff
path: root/src/deepReadDir.tsx
blob: ec585ec36e02bf7010130f50630d2465a1f35162 (plain)
1
2
3
4
5
6
7
8
9
10
11
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;