* Updates CHANGELOG.md with new content
(packageDirName: string, newContent: string)
| 202 | * Updates CHANGELOG.md with new content |
| 203 | */ |
| 204 | function updateChangelog(packageDirName: string, newContent: string) { |
| 205 | let changelogPath = |
| 206 | packageDirName === "/" |
| 207 | ? path.join(getRootDir(), "CHANGELOG.md") |
| 208 | : getPackageFile(packageDirName, "CHANGELOG.md"); |
| 209 | |
| 210 | if (preview) { |
| 211 | console.log( |
| 212 | ` • Would update ${path.relative(process.cwd(), changelogPath)}:\n`, |
| 213 | ); |
| 214 | console.log( |
| 215 | newContent |
| 216 | .split("\n") |
| 217 | .map((line) => ` ${line}`) |
| 218 | .join("\n"), |
| 219 | ); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | let existingChangelog = readFile(changelogPath); |
| 224 | |
| 225 | let lines = existingChangelog.split("\n"); |
| 226 | |
| 227 | // Find the first ## version entry |
| 228 | let firstVersionIndex = lines.findIndex((line) => line.startsWith("## ")); |
| 229 | |
| 230 | let updatedChangelog: string; |
| 231 | if (firstVersionIndex !== -1) { |
| 232 | // Insert before the first version entry |
| 233 | lines.splice(firstVersionIndex, 0, newContent); |
| 234 | updatedChangelog = lines.join("\n"); |
| 235 | } else { |
| 236 | // No version entries yet - append to the end |
| 237 | updatedChangelog = existingChangelog.trimEnd() + "\n\n" + newContent + "\n"; |
| 238 | } |
| 239 | |
| 240 | writeFile(changelogPath, updatedChangelog); |
| 241 | console.log(` ✓ Updated CHANGELOG.md`); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Deletes all change files (except README.md) |
no test coverage detected
searching dependent graphs…