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;
