(node: TreeNode, prefix: string, isLast: boolean, depth: number)
| 2108 | } |
| 2109 | |
| 2110 | const renderNode = (node: TreeNode, prefix: string, isLast: boolean, depth: number): void => { |
| 2111 | if (maxDepth !== undefined && depth > maxDepth) return; |
| 2112 | |
| 2113 | const glyphs = getGlyphs(); |
| 2114 | const connector = isLast ? glyphs.treeLast : glyphs.treeBranch; |
| 2115 | const childPrefix = isLast ? ' ' : glyphs.treePipe; |
| 2116 | |
| 2117 | if (node.name) { |
| 2118 | let line = prefix + connector + node.name; |
| 2119 | if (node.file && includeMetadata) { |
| 2120 | line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`); |
| 2121 | } |
| 2122 | console.log(line); |
| 2123 | } |
| 2124 | |
| 2125 | const children = [...node.children.values()]; |
| 2126 | children.sort((a, b) => { |
| 2127 | const aIsDir = a.children.size > 0 && !a.file; |
| 2128 | const bIsDir = b.children.size > 0 && !b.file; |
| 2129 | if (aIsDir !== bIsDir) return aIsDir ? -1 : 1; |
| 2130 | return a.name.localeCompare(b.name); |
| 2131 | }); |
| 2132 | |
| 2133 | for (let i = 0; i < children.length; i++) { |
| 2134 | const child = children[i]!; |
| 2135 | const nextPrefix = node.name ? prefix + childPrefix : prefix; |
| 2136 | renderNode(child, nextPrefix, i === children.length - 1, depth + 1); |
| 2137 | } |
| 2138 | }; |
| 2139 | |
| 2140 | renderNode(root, '', true, 0); |
| 2141 | } |
no test coverage detected