( files: HttpImportFile[], )
| 514 | } |
| 515 | |
| 516 | export function parseOpenCollectionFiles( |
| 517 | files: HttpImportFile[], |
| 518 | ): HttpImportResult { |
| 519 | const warnings: HttpImportWarning[] = [] |
| 520 | const yamlFiles = files.filter(isYamlFile) |
| 521 | const parsedFiles = yamlFiles |
| 522 | .map(file => ({ file, raw: readYaml(file, warnings) })) |
| 523 | .filter( |
| 524 | (entry): entry is { file: HttpImportFile, raw: unknown } => |
| 525 | entry.raw !== null, |
| 526 | ) |
| 527 | |
| 528 | const rootEntries = parsedFiles.filter(entry => |
| 529 | isOpenCollectionRoot(entry.file, entry.raw), |
| 530 | ) |
| 531 | const bundledEntries = parsedFiles.filter( |
| 532 | (entry): entry is { file: HttpImportFile, raw: UnknownRecord } => |
| 533 | isBundledCollection(entry.raw), |
| 534 | ) |
| 535 | if (rootEntries.length === 0 && bundledEntries.length === 0) { |
| 536 | return { collections: [], environments: [], warnings: [] } |
| 537 | } |
| 538 | |
| 539 | const collections: HttpImportCollection[] = [] |
| 540 | const environments: HttpImportEnvironment[] = [] |
| 541 | |
| 542 | for (const entry of bundledEntries) { |
| 543 | const result = parseBundledCollection(entry.file, entry.raw, warnings) |
| 544 | if (result.collection) { |
| 545 | collections.push(result.collection) |
| 546 | } |
| 547 | if (result.environment) { |
| 548 | environments.push(result.environment) |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | for (const rootEntry of rootEntries) { |
| 553 | if (isBundledCollection(rootEntry.raw)) |
| 554 | continue |
| 555 | |
| 556 | const rootInfo = getInfo(rootEntry.raw) |
| 557 | const rootDir = dirname(normalizePath(rootEntry.file.name)) |
| 558 | const rootFiles = parsedFiles.filter(entry => |
| 559 | isInsideRoot(entry.file.name, rootDir), |
| 560 | ) |
| 561 | const collection: HttpImportCollection = { |
| 562 | folders: [], |
| 563 | name: normalizeImportName( |
| 564 | rootInfo.name, |
| 565 | rootDir ? basename(rootDir) : 'Bruno Collection', |
| 566 | ), |
| 567 | requests: [], |
| 568 | } |
| 569 | const folderNames = new Map<string, string>() |
| 570 | |
| 571 | for (const entry of rootFiles) { |
| 572 | const relativePath = stripRootDir(entry.file.name, rootDir) |
| 573 | if (!isFolderFile({ ...entry.file, name: relativePath }, entry.raw)) |
no test coverage detected