@@ -38,41 +38,59 @@ export function getNextReleaseVersion(currentVersion: string): string {
3838 return `${ major } .${ nextTensMinor } ` ;
3939}
4040
41+ /**
42+ * Read and parse version.json
43+ * @returns The parsed version.json object
44+ */
45+ function readVersionJson ( ) : { version : string ; [ key : string ] : unknown } {
46+ const versionFilePath = path . join ( path . resolve ( __dirname , '..' ) , 'version.json' ) ;
47+ const file = fs . readFileSync ( versionFilePath , 'utf8' ) ;
48+ return JSON . parse ( file ) ;
49+ }
50+
51+ /**
52+ * Write version.json with the given version
53+ * @param versionJson The version.json object to write
54+ */
55+ function writeVersionJson ( versionJson : { version : string ; [ key : string ] : unknown } ) : void {
56+ const versionFilePath = path . join ( path . resolve ( __dirname , '..' ) , 'version.json' ) ;
57+ const newJson = JSON . stringify ( versionJson , null , 4 ) ;
58+ console . log ( `New json: ${ newJson } ` ) ;
59+ fs . writeFileSync ( versionFilePath , newJson ) ;
60+ }
61+
4162gulp . task ( 'incrementVersion' , async ( ) : Promise < void > => {
4263 const argv = minimist ( process . argv . slice ( 2 ) ) ;
4364 const isReleaseCandidate = argv [ 'releaseCandidate' ] === true || argv [ 'releaseCandidate' ] === 'true' ;
4465
4566 // Get the current version from version.json
46- const versionFilePath = path . join ( path . resolve ( __dirname , '..' ) , 'version.json' ) ;
47- const file = fs . readFileSync ( versionFilePath , 'utf8' ) ;
48- const versionJson = JSON . parse ( file ) ;
67+ const versionJson = readVersionJson ( ) ;
4968
5069 // Calculate new version
5170 const version = versionJson . version as string ;
52- const split = version . split ( '.' ) ;
53- let newVersion : string ;
71+ let split : string [ ] ;
5472
5573 if ( isReleaseCandidate ) {
5674 // If this is a release candidate, increment to be higher than the next stable version
5775 // e.g., if current is 2.74, next stable is 2.80, so main should be 2.81
5876 const nextStableVersion = getNextReleaseVersion ( version ) ;
59- const stableSplit = nextStableVersion . split ( '.' ) ;
60- newVersion = `${ stableSplit [ 0 ] } .${ parseInt ( stableSplit [ 1 ] ) + 1 } ` ;
77+ split = nextStableVersion . split ( '.' ) ;
6178 console . log (
62- `Release candidate mode: Updating ${ version } to ${ newVersion } (next stable would be ${ nextStableVersion } )`
79+ `Release candidate mode: Updating ${ version } to ${ split [ 0 ] } .${
80+ parseInt ( split [ 1 ] ) + 1
81+ } (next stable would be ${ nextStableVersion } )`
6382 ) ;
6483 } else {
6584 // Normal increment: just increment the minor version
66- newVersion = ` ${ split [ 0 ] } . ${ parseInt ( split [ 1 ] ) + 1 } ` ;
67- console . log ( `Updating ${ version } to ${ newVersion } ` ) ;
85+ split = version . split ( '.' ) ;
86+ console . log ( `Updating ${ version } to ${ split [ 0 ] } . ${ parseInt ( split [ 1 ] ) + 1 } ` ) ;
6887 }
6988
89+ const newVersion = `${ split [ 0 ] } .${ parseInt ( split [ 1 ] ) + 1 } ` ;
90+
7091 // Write the new version back to version.json
7192 versionJson . version = newVersion ;
72- const newJson = JSON . stringify ( versionJson , null , 4 ) ;
73- console . log ( `New json: ${ newJson } ` ) ;
74-
75- fs . writeFileSync ( versionFilePath , newJson ) ;
93+ writeVersionJson ( versionJson ) ;
7694
7795 // Add a new changelog section for the new version.
7896 console . log ( 'Adding new version header to changelog' ) ;
@@ -226,11 +244,9 @@ async function generatePRList(startSHA: string, endSHA: string): Promise<string[
226244 * This task is used when snapping from prerelease to release.
227245 * It updates the version to round up to the next tens version (e.g., 2.74 -> 2.80).
228246 */
229- gulp . task ( 'updateVersionForRelease ' , async ( ) : Promise < void > => {
247+ gulp . task ( 'updateVersionForStableRelease ' , async ( ) : Promise < void > => {
230248 // Get the current version from version.json
231- const versionFilePath = path . join ( path . resolve ( __dirname , '..' ) , 'version.json' ) ;
232- const file = fs . readFileSync ( versionFilePath , 'utf8' ) ;
233- const versionJson = JSON . parse ( file ) ;
249+ const versionJson = readVersionJson ( ) ;
234250
235251 const currentVersion = versionJson . version as string ;
236252 const releaseVersion = getNextReleaseVersion ( currentVersion ) ;
@@ -239,8 +255,5 @@ gulp.task('updateVersionForRelease', async (): Promise<void> => {
239255
240256 // Write the new version back to version.json
241257 versionJson . version = releaseVersion ;
242- const newJson = JSON . stringify ( versionJson , null , 4 ) ;
243- console . log ( `New json: ${ newJson } ` ) ;
244-
245- fs . writeFileSync ( versionFilePath , newJson ) ;
258+ writeVersionJson ( versionJson ) ;
246259} ) ;
0 commit comments