( files: FileMap, rootFolder = '/', hideRoot: boolean, hiddenFiles: Array<string | RegExp>, )
| 253 | } |
| 254 | |
| 255 | function buildFileList( |
| 256 | files: FileMap, |
| 257 | rootFolder = '/', |
| 258 | hideRoot: boolean, |
| 259 | hiddenFiles: Array<string | RegExp>, |
| 260 | ): Node[] { |
| 261 | const folderPaths = new Set<string>(); |
| 262 | const fileList: Node[] = []; |
| 263 | |
| 264 | let defaultDepth = 0; |
| 265 | |
| 266 | if (rootFolder === '/' && !hideRoot) { |
| 267 | defaultDepth = 1; |
| 268 | fileList.push({ kind: 'folder', name: '/', depth: 0, id: 0, fullPath: '/' }); |
| 269 | } |
| 270 | |
| 271 | for (const [filePath, dirent] of Object.entries(files)) { |
| 272 | const segments = filePath.split('/').filter((segment) => segment); |
| 273 | const fileName = segments.at(-1); |
| 274 | |
| 275 | if (!fileName || isHiddenFile(filePath, fileName, hiddenFiles)) { |
| 276 | continue; |
| 277 | } |
| 278 | |
| 279 | let currentPath = ''; |
| 280 | |
| 281 | let i = 0; |
| 282 | let depth = 0; |
| 283 | |
| 284 | while (i < segments.length) { |
| 285 | const name = segments[i]; |
| 286 | const fullPath = (currentPath += `/${name}`); |
| 287 | |
| 288 | if (!fullPath.startsWith(rootFolder) || (hideRoot && fullPath === rootFolder)) { |
| 289 | i++; |
| 290 | continue; |
| 291 | } |
| 292 | |
| 293 | if (i === segments.length - 1 && dirent?.type === 'file') { |
| 294 | fileList.push({ |
| 295 | kind: 'file', |
| 296 | id: fileList.length, |
| 297 | name, |
| 298 | fullPath, |
| 299 | depth: depth + defaultDepth, |
| 300 | }); |
| 301 | } else if (!folderPaths.has(fullPath)) { |
| 302 | folderPaths.add(fullPath); |
| 303 | |
| 304 | fileList.push({ |
| 305 | kind: 'folder', |
| 306 | id: fileList.length, |
| 307 | name, |
| 308 | fullPath, |
| 309 | depth: depth + defaultDepth, |
| 310 | }); |
| 311 | } |
| 312 |
no test coverage detected