如何为自己的项目生成changelog

背景

在github上看到人家的更新日志感觉很cool,怎么能给自己项目来一套呢

环境信息

shell 复制代码
tds@tdsdeMacBook-Pro demo-doc % node -v
v14.18.1
tds@tdsdeMacBook-Pro demo-doc % npm -v
6.14.15

硬件信息

  • 型号名称:MacBook Pro
  • 版本: 12.6.9
  • 芯片: Apple M1

编码实战

  • 因为我本地的node版本为14.18.1,可以使用standard-version
  • 生成日志需要提交记录符合 Angular 格式(或其他约定的格式)

规范化提交信息

使用其他规范化提交信息的工具也可以

安装规范化工具(详细安装流程和强制约束见参考资料),然后

shell 复制代码
npm install -g commitizen cz-conventional-changelog

为 commitizen 指定 Adapter.

全局模式下, 需要 ~/.czrc 配置文件, 为 commitizen 指定 Adapter.

shell 复制代码
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc

使用git cz提交代码

全局安装后报错
报错信息如下

shell 复制代码
PS C:\Users\sky\WebstormProjects\Demo\React\umi> echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
PS C:\Users\sky\WebstormProjects\Demo\React\umi> git cz
The config file at "C:\Users\sky\.czrc" contains invalid charset, expect utf8

解决方案

删除根目录下的.czrc,在vscode中新建.czrc文件,文件内容为{ "path": "cz-conventional-changelog" }

standard-version安装和设置

安装standard-version

shell 复制代码
npm i --save-dev standard-version

将脚本命令添加到我们的package.json

json 复制代码
{
  ...
  "scripts": {
      "release": "standard-version",
      "release:dry": "standard-version --dry-run"
  }
  ...
}

修改standard-version配置.versionrc.js(非必要)

js 复制代码
module.exports = {
  skip: {
    bump: false, // 跳过升级版本操作
    changelog: false, // 基于commits生成ChangeLog文档
    commit: false, // 提交一个commit,包含ChangeLog和版本变更的文件
    tag: false, // 跳过打tag操作
  },
  //types为Conventional Commits标准中定义,目前支持
  //https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional
  types: [
    { type: 'feat', section: '✨ Features | 新功能' },
    { type: 'fix', section: '🐛 Bug Fixes | Bug 修复' },
    { type: 'init', section: '🎉 Init | 初始化' },
    { type: 'docs', section: '✏️ Documentation | 文档' },
    { type: 'style', section: '💄 Styles | 风格' },
    { type: 'refactor', section: '♻️ Code Refactoring | 代码重构' },
    { type: 'perf', section: '⚡ Performance Improvements | 性能优化' },
    { type: 'test', section: '✅ Tests | 测试' },
    { type: 'revert', section: '⏪ Revert | 回退', hidden: true },
    { type: 'build', section: '📦‍ Build System | 打包构建' },
    { type: 'chore', section: '🚀 Chore | 构建/工程依赖/工具', hidden: true },
    { type: 'ci', section: '👷 Continuous Integration | CI 配置' },
  ],
};

生成日志

在按照规范规范提交代码后,运行如下命令:

shell 复制代码
npm run release

想要确认结果是否符合预期,可运行npm run release:dry进行测试

参考资料

相关推荐
摘星编程5 小时前
OpenHarmony环境下React Native:自定义useTruncate文本截断
javascript·react native·react.js
Duang007_5 小时前
【LeetCodeHot100 超详细Agent启发版本】字母异位词分组 (Group Anagrams)
开发语言·javascript·人工智能·python
2601_949868367 小时前
Flutter for OpenHarmony 电子合同签署App实战 - 主入口实现
开发语言·javascript·flutter
m0_748229997 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
xiaoxue..7 小时前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
摘星编程7 小时前
在OpenHarmony上用React Native:自定义useHighlight关键词高亮
javascript·react native·react.js
2601_949613028 小时前
flutter_for_openharmony家庭药箱管理app实战+用药知识详情实现
android·javascript·flutter
一起养小猫8 小时前
Flutter for OpenHarmony 实战 表单处理与验证完整指南
android·开发语言·前端·javascript·flutter·harmonyos
xcs1940510 小时前
前端 项目构建问题 \node_modules\loader-runner\lib\loadLoader.js
开发语言·前端·javascript
我爱加班、、10 小时前
new Map()+Array.from()整理elementPlus的级联器数据
linux·前端·javascript