(files: string[])
| 339 | // ============================================================================ |
| 340 | |
| 341 | function buildTree(files: string[]): TreeNode { |
| 342 | const root: TreeNode = { name: "", isDir: true, fullPath: "", children: new Map() } |
| 343 | |
| 344 | for (const filePath of files) { |
| 345 | const parts = filePath.split("/") |
| 346 | let current = root |
| 347 | let pathSoFar = "" |
| 348 | |
| 349 | for (let i = 0; i < parts.length; i++) { |
| 350 | const part = parts[i] |
| 351 | pathSoFar = pathSoFar ? `${pathSoFar}/${part}` : part |
| 352 | const isLast = i === parts.length - 1 |
| 353 | |
| 354 | if (!current.children.has(part)) { |
| 355 | current.children.set(part, { |
| 356 | name: part, |
| 357 | isDir: !isLast, |
| 358 | fullPath: pathSoFar, |
| 359 | children: new Map(), |
| 360 | }) |
| 361 | } |
| 362 | current = current.children.get(part)! |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | return root |
| 367 | } |
| 368 | |
| 369 | function lookupTree(root: TreeNode, treePath: string): TreeNode | null { |
| 370 | if (!treePath) return root |
no test coverage detected