|
@@ -220,6 +220,32 @@ function gitCommit(version) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Git 添加 tag
|
|
|
|
|
+function gitTag(version) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ execSync(`git tag v${version}`, {
|
|
|
|
|
+ encoding: 'utf-8',
|
|
|
|
|
+ stdio: 'inherit'
|
|
|
|
|
+ })
|
|
|
|
|
+ return true
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// Git 推送(包含 tags)
|
|
|
|
|
+function gitPush() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ execSync('git push --follow-tags', {
|
|
|
|
|
+ encoding: 'utf-8',
|
|
|
|
|
+ stdio: 'inherit'
|
|
|
|
|
+ })
|
|
|
|
|
+ return true
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 主循环
|
|
// 主循环
|
|
|
async function main() {
|
|
async function main() {
|
|
|
showHeader()
|
|
showHeader()
|
|
@@ -270,6 +296,9 @@ async function main() {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 检查版本号是否有变化
|
|
|
|
|
+ const versionChanged = currentVersion !== newVersion
|
|
|
|
|
+
|
|
|
console.log('')
|
|
console.log('')
|
|
|
console.log('正在更新版本号...')
|
|
console.log('正在更新版本号...')
|
|
|
console.log('')
|
|
console.log('')
|
|
@@ -288,21 +317,55 @@ async function main() {
|
|
|
console.log('============================================')
|
|
console.log('============================================')
|
|
|
console.log('')
|
|
console.log('')
|
|
|
|
|
|
|
|
- const gitChoice = await readYesNo('是否将修改提交到 Git?', true)
|
|
|
|
|
|
|
+ if (versionChanged) {
|
|
|
|
|
+ const gitChoice = await readYesNo('是否将修改提交到 Git?', true)
|
|
|
|
|
|
|
|
- if (gitChoice) {
|
|
|
|
|
- console.log('')
|
|
|
|
|
- console.log('正在提交到 Git...')
|
|
|
|
|
- if (gitCommit(newVersion)) {
|
|
|
|
|
|
|
+ if (gitChoice) {
|
|
|
console.log('')
|
|
console.log('')
|
|
|
- console.log(`[成功] 已提交到 Git,提交消息: v${newVersion}`)
|
|
|
|
|
|
|
+ console.log('正在提交到 Git...')
|
|
|
|
|
+ if (gitCommit(newVersion)) {
|
|
|
|
|
+ console.log('')
|
|
|
|
|
+ console.log(`[成功] 已提交到 Git,提交消息: v${newVersion}`)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('')
|
|
|
|
|
+ console.log('[警告] Git 提交失败,可能没有变更或发生错误')
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
console.log('')
|
|
console.log('')
|
|
|
- console.log('[警告] Git 提交失败,可能没有变更或发生错误')
|
|
|
|
|
|
|
+ console.log('已跳过 Git 提交')
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('[提示] 版本号未变化,跳过 Git 提交')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 无论版本是否变化,都询问是否添加 tag
|
|
|
|
|
+ const tagChoice = await readYesNo('是否添加 Git tag?', false)
|
|
|
|
|
+ if (tagChoice) {
|
|
|
|
|
+ console.log('')
|
|
|
|
|
+ console.log('正在添加 tag...')
|
|
|
|
|
+ if (gitTag(newVersion)) {
|
|
|
|
|
+ console.log(`[成功] 已添加 tag: v${newVersion}`)
|
|
|
|
|
+
|
|
|
|
|
+ // 询问是否推送
|
|
|
|
|
+ const pushChoice = await readYesNo('是否推送到远程仓库?', true)
|
|
|
|
|
+ if (pushChoice) {
|
|
|
|
|
+ console.log('')
|
|
|
|
|
+ console.log('正在推送...')
|
|
|
|
|
+ if (gitPush()) {
|
|
|
|
|
+ console.log('[成功] 已推送到远程仓库')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('[警告] 推送失败')
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('')
|
|
|
|
|
+ console.log('已跳过推送')
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('[警告] 添加 tag 失败,可能 tag 已存在')
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
console.log('')
|
|
console.log('')
|
|
|
- console.log('已跳过 Git 提交')
|
|
|
|
|
|
|
+ console.log('已跳过添加 tag')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
console.log('')
|
|
console.log('')
|