release.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env node
  2. import { execSync } from 'child_process'
  3. import inquirer from 'inquirer'
  4. import fs from 'fs'
  5. function run(cmd) {
  6. execSync(cmd, { stdio: 'inherit' })
  7. }
  8. function getVersion() {
  9. return JSON.parse(fs.readFileSync('package.json', 'utf8')).version
  10. }
  11. async function main() {
  12. console.log('🚀 开始发布流程...')
  13. // 1. 选择版本类型
  14. const { versionType } = await inquirer.prompt([
  15. {
  16. type: 'list',
  17. name: 'versionType',
  18. message: '请选择版本类型:',
  19. choices: [
  20. { name: '补丁版本 (patch)', value: 'patch' },
  21. { name: '小版本 (minor)', value: 'minor' },
  22. { name: '大版本 (major)', value: 'major' },
  23. ],
  24. },
  25. ])
  26. // 2. 更新版本号(会生成新 tag)
  27. run(`npm version ${versionType} -m "new version published: v%s"`)
  28. // 读取新版本号
  29. const version = getVersion()
  30. // 3. 全量生成 changelog
  31. console.log('📝 正在全量生成 changelog...')
  32. run('npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0')
  33. // 4. 自动提交 changelog
  34. run('git add CHANGELOG.md')
  35. run('git commit --amend --no-edit') // 合并到刚才的提交
  36. // 5. 推送代码 & tag
  37. run('git push --force-with-lease')
  38. run('git push --tags')
  39. // 6. 彩色提示
  40. console.log('\x1b[36m=========================\x1b[0m')
  41. console.log('\x1b[32m🎉 发布成功!\x1b[0m')
  42. console.log(`\x1b[33m📦 版本号:v${version}\x1b[0m`)
  43. console.log('\x1b[35m⚙️ 部署:\x1b[0m')
  44. console.log('\x1b[34m * 打包并部署到测试环境(单机版):npm run deploy:test\x1b[0m')
  45. console.log('\x1b[35m⚙️ 打包:\x1b[0m')
  46. console.log('\x1b[34m * 开发环境:npm run build:dev\x1b[0m')
  47. console.log('\x1b[34m * 测试环境:npm run build:test\x1b[0m')
  48. console.log('\x1b[34m * 生产环境:npm run build\x1b[0m')
  49. console.log('\x1b[35m⚙️ 同步代码:\x1b[0m')
  50. console.log('\x1b[34m * 同步dev分支代码到prod分支:bash scripts/merge_dev_to_pro.sh\x1b[0m')
  51. console.log('\x1b[36m=========================\x1b[0m')
  52. }
  53. main()