( node: PathTreeNode, prefix: string, isLast: boolean, parentRawPath: string | undefined, formatPath: (path: string) => string, )
| 102 | } |
| 103 | |
| 104 | function renderNode( |
| 105 | node: PathTreeNode, |
| 106 | prefix: string, |
| 107 | isLast: boolean, |
| 108 | parentRawPath: string | undefined, |
| 109 | formatPath: (path: string) => string, |
| 110 | ): string[] { |
| 111 | const flattened = flattenSingleChildChain(node); |
| 112 | const displayName = appendDirectorySlash( |
| 113 | parentRawPath === undefined |
| 114 | ? formatPath(flattened.rawPath) |
| 115 | : relativeRawPath(parentRawPath, flattened.rawPath), |
| 116 | flattened.children.size > 0, |
| 117 | ); |
| 118 | const branch = isLast ? '└── ' : '├── '; |
| 119 | const lines = [`${prefix}${branch}${formatLeaf(flattened, displayName)}`]; |
| 120 | const children = [...flattened.children.values()].sort((left, right) => |
| 121 | left.name.localeCompare(right.name), |
| 122 | ); |
| 123 | const childPrefix = `${prefix}${isLast ? ' ' : '│ '}`; |
| 124 | |
| 125 | children.forEach((child, index) => { |
| 126 | lines.push( |
| 127 | ...renderNode( |
| 128 | child, |
| 129 | childPrefix, |
| 130 | index === children.length - 1, |
| 131 | flattened.rawPath, |
| 132 | formatPath, |
| 133 | ), |
| 134 | ); |
| 135 | }); |
| 136 | |
| 137 | return lines; |
| 138 | } |
| 139 | |
| 140 | function topLevelNodes(root: PathTreeNode): PathTreeNode[] { |
| 141 | const children = [...root.children.values()]; |
no test coverage detected