release.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * @Description: release.js
  3. * @Author: zcf
  4. * @Date: 2021-12-29 19:34:07
  5. * @LastEditTime: 2022-04-20 16:01:55
  6. * @LastEditors: zcf
  7. */
  8. import { execSync } from 'child_process'
  9. import { readJSONSync } from 'fs-extra'
  10. import chalk from 'chalk'
  11. import boxen from 'boxen'
  12. import ora from 'ora'
  13. const standardVersion = require('standard-version')
  14. // 读取现在的版本
  15. const { version: oldVersion } = readJSONSync('package.json')
  16. // 执行bumpp指令,更新版本号
  17. execSync('npx bumpp', { stdio: 'inherit' })
  18. // 读取更新后的版本号
  19. const { version } = readJSONSync('package.json')
  20. // 版本号如果没有变化,则退出
  21. if (oldVersion === version) {
  22. process.exit()
  23. }
  24. // 链接git仓库的动画
  25. const spinner = ora('Link to Git ...').start()
  26. /* =============================================
  27. = 生成版本CHANGELOG文件 =
  28. =============================================*/
  29. standardVersion({
  30. releaseAs: version,
  31. silent: true,
  32. header: '# zcf-Admin ChangeLog\n\n',
  33. types: [
  34. { type: 'feat', section: '✨ Features | 新功能' },
  35. { type: 'fix', section: '🐛 Bug Fixes | Bug 修复' },
  36. { type: 'init', section: '🎉 Init | 初始化' },
  37. { type: 'docs', section: '✏️ Documentation | 文档' },
  38. { type: 'style', section: '💄 Styles | 风格' },
  39. { type: 'refactor', section: '♻️ Code Refactoring | 代码重构' },
  40. { type: 'perf', section: '⚡ Performance Improvements | 性能优化' },
  41. { type: 'test', section: '✅ Tests | 测试' },
  42. { type: 'revert', section: '⏪ Revert | 回退' },
  43. { type: 'build', section: '📦‍ Build System | 打包构建' },
  44. { type: 'chore', section: '🚀 Chore | 构建/工程依赖/工具' },
  45. { type: 'ci', section: '👷 Continuous Integration | CI 配置' }
  46. ]
  47. })
  48. .then(() => {
  49. // ─── SUCCESSFUL ──────────────────────────────────────────────────
  50. execSync('git push --follow-tags', { stdio: 'inherit' })
  51. spinner.succeed('Git push successful!')
  52. // eslint-disable-next-line
  53. console.log(
  54. boxen(`${chalk('\n\n🎉 ')}${chalk.green.bold('project release success!\n')}`, {
  55. padding: 1,
  56. margin: 1,
  57. borderStyle: 'round',
  58. borderColor: 'green'
  59. })
  60. )
  61. })
  62. .catch((err) => {
  63. // ─── FAILED ──────────────────────────────────────────────────────
  64. spinner.fail('Git push failed!')
  65. console.error(
  66. `${boxen(`${chalk('\n\n❌ ')}${chalk.red.bold(`${err.message}!\n`)}`, {
  67. padding: 1,
  68. margin: 1,
  69. borderStyle: 'round',
  70. borderColor: 'red'
  71. })}`
  72. )
  73. })