@@ -4,11 +4,21 @@ import fs from "fs"
44import { execSync } from "child_process"
55
66function main ( ) {
7+ // Check command line flags
8+ const updateChangelogOnly = process . argv . includes ( "--update-changelog-only" )
9+ const getChangelogContent = process . argv . includes ( "--get-changelog-content" )
10+
711 // Read package.json to get current version
812 const pkg = JSON . parse ( fs . readFileSync ( "package.json" , "utf8" ) )
913 const version = pkg . version
1014
11- console . log ( `Creating tag for version ${ version } ...` )
15+ if ( updateChangelogOnly ) {
16+ console . log ( `Updating changelog for version ${ version } ...` )
17+ } else if ( getChangelogContent ) {
18+ // Just get the changelog content for this version and exit
19+ } else {
20+ console . log ( `Updating changelog and creating tag for version ${ version } ...` )
21+ }
1222
1323 // Read changelog
1424 let changelog = fs . readFileSync ( "CHANGELOG.md" , "utf8" )
@@ -22,7 +32,7 @@ function main() {
2232 // Check if version already exists in changelog
2333 if ( changelog . includes ( newVersionHeader ) || changelog . includes ( versionHeader ) ) {
2434 console . log ( `Version ${ version } already exists in changelog. Skipping update.` )
25- } else if ( changelog . includes ( unreleasedHeader ) ) {
35+ } else if ( changelog . includes ( unreleasedHeader ) && ! getChangelogContent ) {
2636 console . log ( "Updating [Unreleased] section to current version..." )
2737 changelog = changelog . replace ( unreleasedHeader , newVersionHeader )
2838
@@ -36,7 +46,15 @@ function main() {
3646
3747 // Write updated changelog back to file
3848 fs . writeFileSync ( "CHANGELOG.md" , changelog , "utf8" )
39- console . log ( "✅ Updated CHANGELOG.md" )
49+
50+ // Stage the changelog file for commit
51+ execSync ( "git add CHANGELOG.md" , { stdio : "inherit" } )
52+ console . log ( "✅ Updated CHANGELOG.md and staged for commit" )
53+ }
54+
55+ // If only updating changelog, exit here
56+ if ( updateChangelogOnly ) {
57+ return
4058 }
4159
4260 // Find the section for this version
@@ -54,6 +72,12 @@ function main() {
5472 // Extract the content for this version
5573 const content = changelog . substring ( startIdx , nextVersionIdx === - 1 ? undefined : nextVersionIdx ) . trim ( )
5674
75+ // If only getting changelog content, just output it and exit
76+ if ( getChangelogContent ) {
77+ console . log ( content )
78+ return
79+ }
80+
5781 console . log ( "Changelog content:" )
5882 console . log ( content )
5983 console . log ( )
0 commit comments