| 249 | } |
| 250 | |
| 251 | export function getAllPathsWithDirectories( |
| 252 | nodes: FileTreeNode[], |
| 253 | basePath: string = '', |
| 254 | ): PathInfo[] { |
| 255 | return nodes.flatMap((node) => { |
| 256 | const nodePath = basePath ? path.join(basePath, node.name) : node.name |
| 257 | if (node.type === 'file') { |
| 258 | return [{ path: nodePath, isDirectory: false }] |
| 259 | } |
| 260 | // Include the directory itself, plus recurse into children |
| 261 | const dirEntry: PathInfo = { path: nodePath, isDirectory: true } |
| 262 | const children = getAllPathsWithDirectories(node.children || [], nodePath) |
| 263 | return [dirEntry, ...children] |
| 264 | }) |
| 265 | } |
| 266 | |
| 267 | export function flattenTree(nodes: FileTreeNode[]): FileTreeNode[] { |
| 268 | return nodes.flatMap((node) => { |