@@ -47,7 +47,43 @@ function getCurrentVersion() {
4747async function bumpVersion ( ) {
4848 try {
4949 state . originalVersion = getCurrentVersion ( ) ;
50- execSync ( 'npx bumpp' , { stdio : 'inherit' } ) ;
50+ const currentVersion = state . originalVersion . split ( '.' ) . map ( Number ) ;
51+
52+ // 询问要更新的版本类型
53+ const { versionType } = await inquirer . prompt ( [
54+ {
55+ type : 'list' ,
56+ name : 'versionType' ,
57+ message : '选择要更新的版本类型:' ,
58+ choices : [
59+ { name : '主版本号 (major)' , value : 'major' } ,
60+ { name : '次版本号 (minor)' , value : 'minor' } ,
61+ { name : '修订号 (patch)' , value : 'patch' }
62+ ]
63+ }
64+ ] ) ;
65+
66+ // 根据选择更新版本号
67+ let newVersion ;
68+ switch ( versionType ) {
69+ case 'major' :
70+ newVersion = `${ currentVersion [ 0 ] + 1 } .0.0` ;
71+ break ;
72+ case 'minor' :
73+ newVersion = `${ currentVersion [ 0 ] } .${ currentVersion [ 1 ] + 1 } .0` ;
74+ break ;
75+ case 'patch' :
76+ newVersion = `${ currentVersion [ 0 ] } .${ currentVersion [ 1 ] } .${ currentVersion [ 2 ] + 1 } ` ;
77+ break ;
78+ }
79+
80+ // 更新 package.json
81+ const pkgPath = join ( process . cwd ( ) , 'package.json' ) ;
82+ const pkg = JSON . parse ( readFileSync ( pkgPath , 'utf-8' ) ) ;
83+ pkg . version = newVersion ;
84+ writeFileSync ( pkgPath , JSON . stringify ( pkg , null , 2 ) + '\n' ) ;
85+
86+ console . log ( chalk . green ( `版本已更新: ${ state . originalVersion } -> ${ newVersion } ` ) ) ;
5187 } catch ( error ) {
5288 console . error ( chalk . red ( '版本更新失败' ) ) ;
5389 throw error ;
@@ -155,8 +191,8 @@ async function main() {
155191 console . log ( chalk . blue ( '开始发布流程...' ) ) ;
156192
157193 // 检查分支
158- // checkBranch();
159- // console.log(chalk.green('✓ 分支检查通过'));
194+ checkBranch ( ) ;
195+ console . log ( chalk . green ( '✓ 分支检查通过' ) ) ;
160196
161197 // 检查未提交的更改
162198 checkUncommittedChanges ( ) ;
0 commit comments