@@ -168,12 +168,56 @@ if ($PSCmdlet.ShouldProcess("package.json/package-lock.json", "npm version $Vers
168168
169169# --- Changelog ---
170170if (Test-Path " CHANGELOG.md" ) {
171- Write-Step " Prepending CHANGELOG.md entry"
171+ Write-Step " Generating CHANGELOG.md entry from git history "
172172 $date = Get-Date - Format " yyyy-MM-dd"
173+
174+ # Try to find the previous tag
175+ $prevTag = (& git describe -- tags -- abbrev= 0 2> $null )
176+ $logRange = if ($prevTag ) { " $prevTag ..HEAD" } else { " HEAD" }
177+
178+ # Get commits since last tag
179+ $logs = (& git log $logRange -- pretty= format:" %s" -- no- merges)
180+
181+ $added = @ ()
182+ $changed = @ ()
183+ $fixed = @ ()
184+
185+ foreach ($line in $logs ) {
186+ if ($line -match ' ^(feat|add)(\(.*\))?:\s*(.*)$' ) {
187+ $added += " - $ ( $Matches [3 ]) "
188+ }
189+ elseif ($line -match ' ^(fix|bug)(\(.*\))?:\s*(.*)$' ) {
190+ $fixed += " - $ ( $Matches [3 ]) "
191+ }
192+ elseif ($line -match ' ^(chore|refactor|docs|style|perf|test|change)(\(.*\))?:\s*(.*)$' ) {
193+ $changed += " - $ ( $Matches [3 ]) "
194+ }
195+ else {
196+ # Default to changed if no prefix matches
197+ $changed += " - $line "
198+ }
199+ }
200+
201+ $entry = " <!-- markdownlint-disable MD024 -->`n`n # Changelog`n`n ## [$Version ] - $date `n`n "
202+
203+ if ($added.Count -gt 0 ) {
204+ $entry += " ### Added`n`n " + ($added -join " `n " ) + " `n`n "
205+ }
206+ if ($changed.Count -gt 0 ) {
207+ $entry += " ### Changed`n`n " + ($changed -join " `n " ) + " `n`n "
208+ }
209+ if ($fixed.Count -gt 0 ) {
210+ $entry += " ### Fixed`n`n " + ($fixed -join " `n " ) + " `n`n "
211+ }
212+
213+ if ($added.Count -eq 0 -and $changed.Count -eq 0 -and $fixed.Count -eq 0 ) {
214+ $entry += " ### Added`n`n - Release $Version `n`n "
215+ }
216+
173217 $existing = Get-Content " CHANGELOG.md" - Raw
174218 $existing = $existing -replace ' (?ms)^<!-- markdownlint-disable MD024 -->\s*' , ' '
175219 $existing = $existing -replace ' (?ms)^# Changelog\s*' , ' '
176- $entry = " <!-- markdownlint-disable MD024 --> `n`n # Changelog `n`n ## [ $Version ] - $date `n`n ### Added `n - Release $Version `n`n "
220+
177221 $escapedVer = [regex ]::Escape($Version )
178222 if ($existing -notmatch " ## \[$escapedVer \]" ) {
179223 Set-Content " CHANGELOG.md" ($entry + $existing ) - Encoding UTF8
0 commit comments