@@ -67,29 +67,20 @@ const CreatVersionDialog = ({
67
67
if ( ! currentVersion ) {
68
68
return null ;
69
69
}
70
- const VERSION_MAP = {
71
- major : 0 ,
72
- minor : 1 ,
73
- patch : 2 ,
74
- } ;
75
- const splitVersion = currentVersion . split ( "." ) ;
76
- const selectedIndex = VERSION_MAP [ versionType ] ;
77
- if ( selectedIndex === 2 ) {
78
- // patch is a little funny
79
- const currentPatch = splitVersion [ selectedIndex ] ;
80
- let newPatch = Number ( currentPatch ) + 1 ;
81
- let newPatchString = String ( newPatch ) ;
82
- const digits = String ( newPatchString ) . length ; //now we know how many digits we have
83
- for ( let i = 0 ; i < 3 - digits ; i ++ ) {
84
- newPatchString = "0" + newPatchString ;
85
- }
86
- splitVersion [ selectedIndex ] = newPatchString ;
87
- return splitVersion . join ( "." ) ;
88
- } else {
89
- const targetValue = splitVersion [ selectedIndex ] ;
90
- splitVersion [ selectedIndex ] = Number ( targetValue + 1 ) ;
91
- return splitVersion . join ( "." ) ;
70
+ const splitVersionString = currentVersion . split ( "." ) ;
71
+ if ( versionType === "major" ) {
72
+ splitVersionString [ 0 ] = String ( parseInt ( splitVersionString [ 0 ] ) + 1 ) ;
73
+ splitVersionString [ 1 ] = "0" ;
74
+ splitVersionString [ 2 ] = "000" ;
75
+ } else if ( versionType === "minor" ) {
76
+ splitVersionString [ 1 ] = String ( parseInt ( splitVersionString [ 1 ] ) + 1 ) ;
77
+ splitVersionString [ 2 ] = "000" ;
78
+ } else if ( versionType === "patch" ) {
79
+ splitVersionString [ 2 ] = String (
80
+ parseInt ( splitVersionString [ 2 ] ) + 1
81
+ ) . padStart ( 3 , "0" ) ;
92
82
}
83
+ return splitVersionString . join ( "." ) ;
93
84
} ;
94
85
95
86
useEffect ( ( ) => {
0 commit comments