| 150 | } |
| 151 | |
| 152 | function buildOutputLines( |
| 153 | headerLine: string, |
| 154 | categories: Map<string, string[]>, |
| 155 | prereleaseLines: string[], |
| 156 | ): string[] { |
| 157 | const hasUnknownCategories = [...categories.keys()].filter( |
| 158 | (c) => !CATEGORY_ORDER.includes(c), |
| 159 | ) |
| 160 | if (hasUnknownCategories.length > 0) { |
| 161 | throw new Error( |
| 162 | `Unknown categories found: ${hasUnknownCategories.join(', ')}`, |
| 163 | ) |
| 164 | } |
| 165 | |
| 166 | const outputLines: string[] = [headerLine, ''] |
| 167 | for (const category of CATEGORY_ORDER) { |
| 168 | const items = categories.get(category) |
| 169 | if (items && items.length > 0) { |
| 170 | outputLines.push(category, '') |
| 171 | outputLines.push(...items) |
| 172 | outputLines.push('') |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | if (prereleaseLines.length > 0) { |
| 177 | outputLines.push('### Beta Changelogs', '', ...prereleaseLines) |
| 178 | } |
| 179 | |
| 180 | return outputLines |
| 181 | } |
| 182 | |
| 183 | const filePath = path.resolve( |
| 184 | // eslint-disable-next-line n/no-unsupported-features/node-builtins |