1+ /* eslint-disable no-console */
12const { execSync } = require ( 'node:child_process' ) ;
23const fs = require ( 'node:fs' ) ;
34const path = require ( 'node:path' ) ;
@@ -12,14 +13,16 @@ function execCommand(command, options = {}) {
1213 console . error ( error . message ) ;
1314 process . exit ( 1 ) ;
1415 }
16+
17+ return null ;
1518}
1619
1720function getPackageInfo ( ) {
1821 const pkgJson = JSON . parse ( fs . readFileSync ( PKG_JSON_PATH , 'utf8' ) ) ;
1922 return {
2023 name : pkgJson . name ,
2124 version : pkgJson . version ,
22- pkgJson
25+ pkgJson,
2326 } ;
2427}
2528
@@ -38,7 +41,7 @@ function getBaseVersionFromGit() {
3841
3942function incrementVersion ( version , type = 'patch' ) {
4043 const [ major , minor , patch ] = version . split ( '.' ) . map ( Number ) ;
41-
44+
4245 switch ( type ) {
4346 case 'major' :
4447 return `${ major + 1 } .0.0` ;
@@ -52,30 +55,30 @@ function incrementVersion(version, type = 'patch') {
5255
5356function findNextAvailableVersion ( packageName , baseVersion ) {
5457 console . log ( `Finding next available version starting from: ${ baseVersion } ` ) ;
55-
58+
5659 try {
5760 const versionString = execCommand ( `npm show ${ packageName } versions --json` ) ;
5861 const versions = JSON . parse ( versionString ) ;
59-
62+
6063 let currentVersion = baseVersion ;
61-
64+
6265 // Keep incrementing patch version until we find one that doesn't exist
6366 while ( versions . includes ( currentVersion ) ) {
6467 console . log ( `Version ${ currentVersion } already exists as stable, incrementing...` ) ;
6568 currentVersion = incrementVersion ( currentVersion , 'patch' ) ;
6669 }
67-
70+
6871 console . log ( `Next available base version: ${ currentVersion } ` ) ;
6972 return currentVersion ;
70- } catch ( error ) {
73+ } catch {
7174 console . log ( 'Could not check NPM versions, using provided base version' ) ;
7275 return baseVersion ;
7376 }
7477}
7578
7679function getNextBetaVersion ( packageName , baseVersion ) {
7780 console . log ( `Calculating next beta version for base: ${ baseVersion } ` ) ;
78-
81+
7982 // Validate base version format
8083 if ( ! / ^ \d + \. \d + \. \d + $ / . test ( baseVersion ) ) {
8184 console . error ( `Invalid base version format: ${ baseVersion } ` ) ;
@@ -84,7 +87,7 @@ function getNextBetaVersion(packageName, baseVersion) {
8487
8588 // Find the next available base version if current one exists as stable
8689 const availableBaseVersion = findNextAvailableVersion ( packageName , baseVersion ) ;
87-
90+
8891 let npmBetaNumber = 0 ;
8992 let gitBetaNumber = 0 ;
9093
@@ -95,25 +98,25 @@ function getNextBetaVersion(packageName, baseVersion) {
9598
9699 const versionPrefix = `${ availableBaseVersion } -beta.` ;
97100 const npmBetas = versions
98- . filter ( v => v . startsWith ( versionPrefix ) )
99- . map ( v => {
101+ . filter ( ( v ) => v . startsWith ( versionPrefix ) )
102+ . map ( ( v ) => {
100103 const match = v . match ( / ^ .+ - b e t a \. ( \d + ) $ / ) ;
101104 return match ? parseInt ( match [ 1 ] , 10 ) : 0 ;
102105 } ) ;
103-
106+
104107 npmBetaNumber = npmBetas . length > 0 ? Math . max ( ...npmBetas ) : 0 ;
105108 console . log ( `Latest beta on NPM for ${ availableBaseVersion } : ${ npmBetaNumber } ` ) ;
106- } catch ( error ) {
109+ } catch {
107110 console . log ( 'No existing beta versions found on NPM' ) ;
108111 }
109112
110113 // Check Git tags for existing beta versions of the available base version
111114 try {
112115 const tagPattern = `v${ availableBaseVersion } -beta.*` ;
113116 const tags = execCommand ( `git tag -l "${ tagPattern } " --sort=-version:refname` ) ;
114-
117+
115118 if ( tags ) {
116- const tagList = tags . split ( '\n' ) . filter ( tag => tag . trim ( ) ) ;
119+ const tagList = tags . split ( '\n' ) . filter ( ( tag ) => tag . trim ( ) ) ;
117120 if ( tagList . length > 0 ) {
118121 const latestTag = tagList [ 0 ] ;
119122 const match = latestTag . match ( / v \d + \. \d + \. \d + - b e t a \. ( \d + ) $ / ) ;
@@ -123,40 +126,40 @@ function getNextBetaVersion(packageName, baseVersion) {
123126 }
124127 }
125128 }
126- } catch ( error ) {
129+ } catch {
127130 console . log ( 'No existing beta tags found in Git' ) ;
128131 }
129132
130133 // Use the higher number to avoid conflicts
131134 const nextBetaNumber = Math . max ( npmBetaNumber , gitBetaNumber ) + 1 ;
132135 const nextVersion = `${ availableBaseVersion } -beta.${ nextBetaNumber } ` ;
133-
136+
134137 console . log ( `Next beta version: ${ nextVersion } ` ) ;
135138 return nextVersion ;
136139}
137140
138141function updatePackageVersion ( newVersion ) {
139142 const { pkgJson } = getPackageInfo ( ) ;
140143 pkgJson . version = newVersion ;
141- fs . writeFileSync ( PKG_JSON_PATH , JSON . stringify ( pkgJson , null , 2 ) + '\n' ) ;
144+ fs . writeFileSync ( PKG_JSON_PATH , ` ${ JSON . stringify ( pkgJson , null , 2 ) } \n` ) ;
142145 console . log ( `Updated package.json to ${ newVersion } ` ) ;
143146}
144147
145148function main ( ) {
146149 console . log ( '🚀 Starting beta version calculation...' ) ;
147-
150+
148151 const { name : packageName } = getPackageInfo ( ) ;
149-
152+
150153 // Get the base version from Git (what was committed by release_metadata)
151154 const baseVersion = getBaseVersionFromGit ( ) ;
152155 console . log ( `Base version from Git: ${ baseVersion } ` ) ;
153-
156+
154157 // Calculate next beta version (will auto-increment if base version exists as stable)
155158 const nextBetaVersion = getNextBetaVersion ( packageName , baseVersion ) ;
156-
159+
157160 // Update package.json with the beta version
158161 updatePackageVersion ( nextBetaVersion ) ;
159-
162+
160163 console . log ( '✅ Beta version preparation completed!' ) ;
161164 console . log ( `Package will be published as: ${ nextBetaVersion } ` ) ;
162165}
0 commit comments