| 62 | baseDir = path.normalize(baseDir); |
| 63 | |
| 64 | const next = async (dir: string, toPrint: string) => { |
| 65 | const entry = this._find(dir); |
| 66 | |
| 67 | if (!entry) { |
| 68 | return toPrint; |
| 69 | } |
| 70 | |
| 71 | const indent = Array.from({ length: (dir.match(/\//g) || []).length }).join('| '); |
| 72 | |
| 73 | if (entry.type === 'dir') { |
| 74 | if (entry.path !== baseDir) { |
| 75 | toPrint += `${indent}${entry.name}/\n`; |
| 76 | } |
| 77 | |
| 78 | for (const name of await this.readdir(dir)) { |
| 79 | toPrint = await next(path.join(dir, name), toPrint); |
| 80 | } |
| 81 | } else { |
| 82 | toPrint += `${indent}${entry.name}\n`; |
| 83 | } |
| 84 | |
| 85 | return toPrint; |
| 86 | }; |
| 87 | |
| 88 | console.log(await next(baseDir, '')); |
| 89 | } |