Skip to content

Commit 3e722cb

Browse files
committed
chore: 更新版本管理脚本,支持选择版本类型并自动更新 package.json
1 parent e9af2d5 commit 3e722cb

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@winner-fed/cloud-utils",
33
"description": "A collection of utils by winner fed",
4-
"version": "2.0.1",
4+
"version": "2.0.0",
55
"type": "module",
66
"author": {
77
"name": "winner-fed",

scripts/release.mjs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,43 @@ function getCurrentVersion() {
4747
async 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

Comments
 (0)