mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 18:44:17 +00:00
25 lines
598 B
JavaScript
25 lines
598 B
JavaScript
import fs from "node:fs"
|
|
import path from "node:path"
|
|
|
|
async function readDirRecurse(dir, maxDepth = 3, current = 0) {
|
|
if (current > maxDepth) {
|
|
return []
|
|
}
|
|
|
|
const files = await fs.promises.readdir(dir)
|
|
|
|
const promises = files.map(async (file) => {
|
|
const filePath = path.join(dir, file)
|
|
const stat = await fs.promises.stat(filePath)
|
|
|
|
if (stat.isDirectory()) {
|
|
return readDirRecurse(filePath, maxDepth, current + 1)
|
|
}
|
|
|
|
return filePath
|
|
})
|
|
|
|
return (await Promise.all(promises)).flat()
|
|
}
|
|
|
|
export default readDirRecurse |