liujia 2 сар өмнө
parent
commit
16d7436cdf
1 өөрчлөгдсөн 13 нэмэгдсэн , 9 устгасан
  1. 13 9
      scripts/release.js

+ 13 - 9
scripts/release.js

@@ -29,12 +29,12 @@ async function main() {
     },
   ])
 
-  // 更新版本(会生成 tag)
+  // 更新版本
   run(`npm version ${versionType} -m "new version published: v%s"`)
 
   const version = getVersion()
 
-  // 选择日志生成模式(默认 incremental)
+  // 选择 changelog 生成模式(默认 incremental)
   const { changelogMode } = await inquirer.prompt([
     {
       type: 'list',
@@ -48,7 +48,6 @@ async function main() {
     },
   ])
 
-  // 生成 changelog
   console.log('📝 正在生成 changelog...')
   if (changelogMode === 'full') {
     run('npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0')
@@ -56,19 +55,24 @@ async function main() {
     run('npx conventional-changelog -p angular -i CHANGELOG.md -s')
   }
 
-  // 提交 package.json 和 changelog
-  try {
+  // 安全 add(存在才加)
+  if (fs.existsSync('package-lock.json')) {
     run('git add package.json package-lock.json')
-  } catch {
-    run('git add package.json') // 兼容没有 package-lock.json 的情况
+  } else {
+    run('git add package.json')
   }
   run('git add CHANGELOG.md')
-  run('git commit -m "chore: update changelog for v' + version + '"')
+
+  // 仅在有变更时提交
+  try {
+    run(`git diff --cached --quiet || git commit -m "chore: update changelog for v${version}"`)
+  } catch (err) {
+    console.log('⚠️ 没有需要提交的文件,跳过 commit', err)
+  }
 
   // 推送代码 & tag
   run('git push --follow-tags')
 
-  // 成功提示
   console.log('\x1b[36m=========================\x1b[0m')
   console.log('\x1b[32m🎉 发布成功!\x1b[0m')
   console.log(`\x1b[33m📦 版本号:v${version}\x1b[0m`)