(node: TreeNode, prefix: string, isLast: boolean, depth: number)
| 2187 | } |
| 2188 | |
| 2189 | const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => { |
| 2190 | if (maxDepth !== undefined && depth > maxDepth) return; |
| 2191 | |
| 2192 | const glyphs = getGlyphs(); |
| 2193 | const connector = isLast ? glyphs.treeLast : glyphs.treeBranch; |
| 2194 | const childPrefix = isLast ? ' ' : glyphs.treePipe; |
| 2195 | |
| 2196 | if (node.name) { |
| 2197 | let line = prefix + connector + node.name; |
| 2198 | if (node.file && includeMetadata) { |
| 2199 | line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`); |
| 2200 | } |
| 2201 | console.log(line); |
| 2202 | } |
| 2203 | |
| 2204 | const children = [...node.children.values()]; |
| 2205 | children.sort((a, b) => { |
| 2206 | const aIsDir = a.children.size > 0 && !a.file; |
| 2207 | const bIsDir = b.children.size > 0 && !b.file; |
| 2208 | if (aIsDir !== bIsDir) return aIsDir ? -1 : 1; |
| 2209 | return a.name.localeCompare(b.name); |
| 2210 | }); |
| 2211 | |
| 2212 | for (let i = 0; i < children.length; i++) { |
| 2213 | const child = children[i]!; |
| 2214 | const nextPrefix = node.name ? prefix + childPrefix : prefix; |
| 2215 | renderNode(child, nextPrefix, i === children.length - 1, depth + 1); |
| 2216 | } |
| 2217 | }; |
| 2218 | |
| 2219 | renderNode(root, '', true, 0); |
| 2220 | } |
no test coverage detected