release.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env node
  2. import { execSync } from 'child_process'
  3. import inquirer from 'inquirer'
  4. function run(cmd) {
  5. execSync(cmd, { stdio: 'inherit' })
  6. }
  7. async function main() {
  8. console.log('🚀 开始发布流程...')
  9. // 1. 选择版本类型
  10. const { versionType } = await inquirer.prompt([
  11. {
  12. type: 'list',
  13. name: 'versionType',
  14. message: '请选择版本类型:',
  15. choices: [
  16. { name: '补丁版本 (patch)', value: 'patch' },
  17. { name: '小版本 (minor)', value: 'minor' },
  18. { name: '大版本 (major)', value: 'major' },
  19. ],
  20. },
  21. ])
  22. // 2. 先更新版本号(生成新 tag)
  23. run(`npm version ${versionType} -m "new version published: v%s"`)
  24. // 3. 全量生成 changelog(覆盖原文件)
  25. console.log('📝 正在全量生成 changelog...')
  26. run('npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0')
  27. // 4. 自动提交 changelog
  28. run('git add CHANGELOG.md')
  29. run('git commit --amend --no-edit') // 直接加到刚才的版本提交里
  30. // 5. 推送代码 & tag(tag 不变,提交更新了)
  31. run('git push --force-with-lease')
  32. run('git push --tags')
  33. console.log('✅ 发布完成!')
  34. }
  35. main()