(rootDir: string, opts: ReadBumpFilesOptions = {})
| 41 | |
| 42 | /** Read all bump files from .bumpy/ (and optionally channel subdirs), sorted by git creation order */ |
| 43 | export async function readBumpFiles(rootDir: string, opts: ReadBumpFilesOptions = {}): Promise<ReadBumpFilesResult> { |
| 44 | const dir = getBumpyDir(rootDir); |
| 45 | const bumpFiles: BumpFile[] = []; |
| 46 | const errors: string[] = []; |
| 47 | |
| 48 | const files = await listFiles(dir, '.md'); |
| 49 | for (const file of files) { |
| 50 | if (file === 'README.md') continue; |
| 51 | const result = await parseBumpFileFromPath(resolve(dir, file)); |
| 52 | if (result.bumpFile) bumpFiles.push(result.bumpFile); |
| 53 | errors.push(...result.errors); |
| 54 | } |
| 55 | |
| 56 | for (const channel of opts.channels ?? []) { |
| 57 | const channelDir = resolve(dir, channel); |
| 58 | const channelFiles = await listFiles(channelDir, '.md'); |
| 59 | for (const file of channelFiles) { |
| 60 | if (file === 'README.md') continue; |
| 61 | const result = await parseBumpFileFromPath(resolve(channelDir, file)); |
| 62 | if (result.bumpFile) { |
| 63 | const duplicate = bumpFiles.find((bf) => bf.id === result.bumpFile!.id); |
| 64 | if (duplicate) { |
| 65 | errors.push( |
| 66 | `Bump file "${result.bumpFile.id}" exists both ${duplicate.channel ? `in .bumpy/${duplicate.channel}/` : 'at .bumpy/ root'} and in .bumpy/${channel}/ — ` + |
| 67 | 'remove one copy (the change likely already shipped on one of them).', |
| 68 | ); |
| 69 | continue; |
| 70 | } |
| 71 | bumpFiles.push({ ...result.bumpFile, channel }); |
| 72 | } |
| 73 | errors.push(...result.errors); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Sort by the commit date when each bump file was first added to git. |
| 78 | // Falls back to filename order for uncommitted bump files. |
| 79 | const creationOrder = getBumpFileCreationOrder(rootDir); |
| 80 | if (creationOrder.size > 0) { |
| 81 | bumpFiles.sort((a, b) => { |
| 82 | const aOrder = creationOrder.get(a.id) ?? Infinity; |
| 83 | const bOrder = creationOrder.get(b.id) ?? Infinity; |
| 84 | return aOrder - bOrder || a.id.localeCompare(b.id); |
| 85 | }); |
| 86 | } |
| 87 | |
| 88 | return { bumpFiles, errors }; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Use `git log` to get the commit timestamp when each bump file was first added. |
no test coverage detected
searching dependent graphs…