@@ -18,34 +18,29 @@ function getBaseVersion() {
1818 // Read root package.json
1919 const rootPackageJsonPath = path . join ( rootDir , 'package.json' ) ;
2020 const rootPackage = JSON . parse ( fs . readFileSync ( rootPackageJsonPath , 'utf8' ) ) ;
21- let baseVersion = rootPackage . version ;
21+ return rootPackage . version ;
22+ }
2223
24+ function getDefaultSuffix ( ) {
2325 // Get latest commit hash
2426 const commitHash = execSync ( 'git rev-parse --short HEAD' , {
2527 encoding : 'utf8' ,
2628 } ) . trim ( ) ;
2729
2830 // Append dev suffix with commit hash
29- const devSuffix = `-dev-${ commitHash } .0` ;
30- return `${ baseVersion } ${ devSuffix } ` ;
31+ return `dev-${ commitHash } .0` ;
3132}
3233
3334const argv = yargs ( hideBin ( process . argv ) )
34- . option ( 'pkg-version ' , {
35+ . option ( 'suffix ' , {
3536 type : 'string' ,
36- description : 'Set the package version' ,
37+ description : 'Set the package version suffix ' ,
3738 } )
3839 . parse ( ) ;
3940
40- const newVersion = argv [ 'pkg-version' ] ?? getBaseVersion ( ) ;
41- if ( argv [ 'pkg-version' ] ) {
42- console . log ( `Using provided package version (--pkg-version): ${ newVersion } ` ) ;
43- } else {
44- console . log (
45- `Using base version with dev suffix and commit hash: ${ newVersion } ` ,
46- ) ;
47- }
48-
41+ const baseVersion = getBaseVersion ( ) ;
42+ const suffix = argv [ 'suffix' ] ?? getDefaultSuffix ( ) ;
43+ const newVersion = `${ baseVersion } ${ suffix . length ? '-' : '' } ${ suffix } ` ;
4944console . log ( `Setting package version to: ${ newVersion } ` ) ;
5045
5146const packageJsonPath = path . join ( packageDir , 'package.json' ) ;
0 commit comments