| 27 | * @returns {Promise<string[]>} |
| 28 | */ |
| 29 | export async function walk(dir, ext) { |
| 30 | const itemsInDir = await fs.readdir(dir); |
| 31 | const result = []; |
| 32 | for (const itemInDir of itemsInDir) { |
| 33 | const fullPath = path.join(dir, itemInDir); |
| 34 | let stats; |
| 35 | try { |
| 36 | stats = await fs.stat(fullPath); |
| 37 | } catch { |
| 38 | continue; |
| 39 | } |
| 40 | if (stats.isDirectory()) { |
| 41 | result.push(...(await walk(fullPath, ext))); |
| 42 | } else if (itemInDir.endsWith(ext)) { |
| 43 | result.push(fullPath); |
| 44 | } |
| 45 | } |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @param {string} [suffix=''] |