优化前端工作流:三、使用standard-version管理ChangeLog和Version

standard-version是一个帮助项目自动生成ChangeLog、升版本、打tag的工具。它基于semverConventional Commits规范。

当执行server-version命令后,它会自动完成以下操作:

  1. 取得当前版本(比如package.json里面的version字段),升版本:1.0.0 => 1.1.0 或者 1.0.0 => 2.0.0等(如何升级可以由参数控制)
  2. 基于commits生成ChangeLog文件
  3. 提交一个commit,包含ChangeLog和版本变更的文件
  4. 打tag

以上功能都是可配置跳过的,对应:bump、changelog、commit、tag。比如在配置文件中按照如下配置,就可以跳过打tag操作:

{
  skip: {
    tag: true
  }
}

和大部分工具的配置方式相同,为standard-version添加配置有两种方式:

  1. Placing a standard-version stanza in your package.json (assuming your project is JavaScript).
  2. Creating a .versionrc, .versionrc.json or .versionrc.js.

目前使用的配置文件如下,其它配置参考官方文档:https://www.npmjs.com/package/standard-version

module.exports = {
  skip: {
    tag: true,
  },
  //types为Conventional Commits标准中定义,目前支持
  //https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional
  types: [
    { type: "feat", section: "新特性" },
    { type: "fix", section: "Bug修复" },
    { type: "docs", section: "文档" },
    { type: "chore", section: "配置项", hidden: true },
    { type: "style", section: "格式", hidden: true },
    { type: "refactor", section: "重构", hidden: true },
    { type: "perf", section: "性能", hidden: true },
    { type: "test", section: "测试", hidden: true },
    { type: "build", section: "构建", hidden: true },
    { type: "ci", section: "CI", hidden: true },
    { type: "revert", section: "回滚", hidden: true },
  ],
  //hash链接
  commitUrlFormat: "http://gitlab.cmss.com/BI/{{repository}}/commit/{{hash}}",
  //issue链接
  issueUrlFormat: "http://jira.cmss.com/browse/{{id}}",
  //server-version自动commit的模板
  releaseCommitMessageFormat:
    "build: v{{currentTag}}版本发布 \n\nCode Source From: Self Code \nDescription: \nJira: # \n市场项目编号(名称):",
  //需要server-version更新版本号的文件
  bumpFiles: [
    {
      filename: "MY_VERSION_TRACKER.txt",
      // The `plain-text` updater assumes the file contents represents the version.
      type: "plain-text",
    },
    {
      filename: "package.json",
      // The `json` updater assumes the version is available under a `version` key in the provided JSON document.
      type: "json",
    },
  ],
};

package.json

  "scripts": {
    "release": "standard-version"
  },

发布命令:

yarn release --release-as major
yarn release --release-as minor
yarn release
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。