( path: string, depth: number, maxDepth: number, ops: TreeOps )
| 325 | } |
| 326 | |
| 327 | async function buildTreeNode( |
| 328 | path: string, |
| 329 | depth: number, |
| 330 | maxDepth: number, |
| 331 | ops: TreeOps |
| 332 | ): Promise<StateTreeNode> { |
| 333 | const stat = await ops.lstat(path); |
| 334 | if (!stat) { |
| 335 | throw new Error(`ENOENT: no such file or directory: ${path}`); |
| 336 | } |
| 337 | const node: StateTreeNode = { |
| 338 | path, |
| 339 | name: path === "/" ? "/" : path.slice(path.lastIndexOf("/") + 1), |
| 340 | type: stat.type, |
| 341 | size: stat.size |
| 342 | }; |
| 343 | if (stat.type === "directory" && depth < maxDepth) { |
| 344 | const entries = await ops.readdirWithFileTypes(path); |
| 345 | node.children = []; |
| 346 | for (const entry of entries) { |
| 347 | const childPath = await ops.resolvePath(path, entry.name); |
| 348 | node.children.push( |
| 349 | await buildTreeNode(childPath, depth + 1, maxDepth, ops) |
| 350 | ); |
| 351 | } |
| 352 | } |
| 353 | return node; |
| 354 | } |
| 355 | |
| 356 | function summarizeNode( |
| 357 | node: StateTreeNode, |
no test coverage detected