22
33/**
44 * Update versions across all packages in the monorepo
5- * Usage: node scripts/update-versions.js [major|minor|patch] [version]
5+ * Usage: node scripts/update-versions.js [major|minor|patch|set ] [version]
66 *
77 * Examples:
8- * node scripts/update-versions.js patch # Bump patch version (1.0.0 -> 1.0.1)
9- * node scripts/update-versions.js minor # Bump minor version (1.0.0 -> 1.1.0)
10- * node scripts/update-versions.js major # Bump major version (1.0.0 -> 2.0.0)
11- * node scripts/update-versions.js set 1.2.3 # Set specific version
8+ * node scripts/update-versions.js patch # Bump each package patch version independently
9+ * node scripts/update-versions.js minor # Bump each package minor version independently
10+ * node scripts/update-versions.js major # Bump each package major version independently
11+ * node scripts/update-versions.js set 1.2.3 # Set all packages to same specific version
1212 */
1313
1414import fs from 'fs' ;
@@ -22,7 +22,7 @@ const PACKAGES_DIR = path.resolve(__dirname, '../packages');
2222const ROOT_DIR = path . resolve ( __dirname , '..' ) ;
2323
2424// Package directories
25- const PACKAGES = [ 'core' , 'http' , 'mcp' , 'text' , 'cli' , 'direct-call' ] ;
25+ const PACKAGES = [ 'core' , 'http' , 'mcp' , 'text' , 'file' , ' cli', 'direct-call' , 'dotenv-loader '] ;
2626
2727/**
2828 * Parse semantic version string
@@ -70,7 +70,7 @@ function bumpVersion(currentVersion, bumpType) {
7070/**
7171 * Update package.json version
7272 */
73- function updatePackageVersion ( packagePath , newVersion ) {
73+ function updatePackageVersion ( packagePath , newVersion , bumpType = null ) {
7474 const packageJsonPath = path . join ( packagePath , 'package.json' ) ;
7575
7676 if ( ! fs . existsSync ( packageJsonPath ) ) {
@@ -81,11 +81,14 @@ function updatePackageVersion(packagePath, newVersion) {
8181 const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ;
8282 const oldVersion = packageJson . version ;
8383
84- packageJson . version = newVersion ;
84+ // If bumpType is provided, calculate new version from current version
85+ const finalVersion = bumpType ? bumpVersion ( oldVersion , bumpType ) : newVersion ;
86+
87+ packageJson . version = finalVersion ;
8588
8689 fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) + '\n' ) ;
8790
88- return { name : packageJson . name , oldVersion, newVersion } ;
91+ return { name : packageJson . name , oldVersion, newVersion : finalVersion } ;
8992}
9093
9194/**
@@ -139,22 +142,16 @@ function main() {
139142 if ( args . length === 0 ) {
140143 console . error ( '❌ Usage: node scripts/update-versions.js [major|minor|patch|set] [version?]' ) ;
141144 console . error ( '\nExamples:' ) ;
142- console . error ( ' node scripts/update-versions.js patch' ) ;
143- console . error ( ' node scripts/update-versions.js minor' ) ;
144- console . error ( ' node scripts/update-versions.js major' ) ;
145- console . error ( ' node scripts/update-versions.js set 1.2.3' ) ;
145+ console . error ( ' node scripts/update-versions.js patch # Bump each package by one patch ' ) ;
146+ console . error ( ' node scripts/update-versions.js minor # Bump each package by one minor ' ) ;
147+ console . error ( ' node scripts/update-versions.js major # Bump each package by one major ' ) ;
148+ console . error ( ' node scripts/update-versions.js set 1.2.3 # Set all packages to same version ' ) ;
146149 process . exit ( 1 ) ;
147150 }
148151
149152 const command = args [ 0 ] ;
150153 let newVersion ;
151-
152- // Get current version from core package
153- const corePackagePath = path . join ( PACKAGES_DIR , 'core' , 'package.json' ) ;
154- const corePackage = JSON . parse ( fs . readFileSync ( corePackagePath , 'utf8' ) ) ;
155- const currentVersion = corePackage . version ;
156-
157- console . log ( `📦 Current version: ${ currentVersion } \n` ) ;
154+ let bumpType = null ;
158155
159156 if ( command === 'set' ) {
160157 if ( args . length < 2 ) {
@@ -171,24 +168,26 @@ function main() {
171168 console . error ( `❌ ${ error . message } ` ) ;
172169 process . exit ( 1 ) ;
173170 }
171+
172+ console . log ( `🎯 Setting all packages to version: ${ newVersion } \n` ) ;
174173 } else if ( [ 'major' , 'minor' , 'patch' ] . includes ( command ) ) {
175- newVersion = bumpVersion ( currentVersion , command ) ;
174+ bumpType = command ;
175+ console . log ( `🎯 Bumping each package by one ${ command } version\n` ) ;
176176 } else {
177177 console . error ( `❌ Unknown command: ${ command } ` ) ;
178178 console . error ( ' Valid commands: major, minor, patch, set' ) ;
179179 process . exit ( 1 ) ;
180180 }
181181
182- console . log ( `🎯 New version: ${ newVersion } \n` ) ;
183-
184182 // Update all package versions
185183 const updates = [ ] ;
186184
187185 console . log ( '📝 Updating package versions...\n' ) ;
188186
189187 for ( const pkg of PACKAGES ) {
190188 const packagePath = path . join ( PACKAGES_DIR , pkg ) ;
191- const result = updatePackageVersion ( packagePath , newVersion ) ;
189+ // Pass bumpType for incremental bumps, or newVersion for set command
190+ const result = updatePackageVersion ( packagePath , newVersion , bumpType ) ;
192191
193192 if ( result ) {
194193 updates . push ( result ) ;
@@ -207,12 +206,11 @@ function main() {
207206
208207 console . log ( '\n✨ Version update complete!' ) ;
209208 console . log ( `\n📋 Summary:` ) ;
210- console . log ( ` Old version: ${ currentVersion } ` ) ;
211- console . log ( ` New version: ${ newVersion } ` ) ;
212209 console . log ( ` Updated ${ updates . length } packages` ) ;
210+ updates . forEach ( u => console . log ( ` - ${ u . name } : ${ u . oldVersion } -> ${ u . newVersion } ` ) ) ;
213211 console . log ( '\n💡 Next steps:' ) ;
214212 console . log ( ' 1. Review the changes: git diff' ) ;
215- console . log ( ' 2. Commit the changes: git commit -am "chore: bump version to ${newVersion} "' ) ;
213+ console . log ( ' 2. Commit the changes: git commit -am "chore: bump package versions "' ) ;
216214 console . log ( ' 3. Build the packages: bun run build' ) ;
217215 console . log ( ' 4. Publish: bun run publish:all' ) ;
218216}
0 commit comments