優(yōu)化前端工作流:三、使用standard-version管理ChangeLog和Version

standard-version是一個(gè)幫助項(xiàng)目自動(dòng)生成ChangeLog、升版本、打tag的工具。它基于semverConventional Commits規(guī)范。

當(dāng)執(zhí)行server-version命令后,它會(huì)自動(dòng)完成以下操作:

  1. 取得當(dāng)前版本(比如package.json里面的version字段),升版本:1.0.0 => 1.1.0 或者 1.0.0 => 2.0.0等(如何升級(jí)可以由參數(shù)控制)
  2. 基于commits生成ChangeLog文件
  3. 提交一個(gè)commit,包含ChangeLog和版本變更的文件
  4. 打tag

以上功能都是可配置跳過(guò)的,對(duì)應(yīng):bump、changelog、commit、tag。比如在配置文件中按照如下配置,就可以跳過(guò)打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標(biāo)準(zhǔn)中定義,目前支持
  //https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional
  types: [
    { type: "feat", section: "新特性" },
    { type: "fix", section: "Bug修復(fù)" },
    { type: "docs", section: "文檔" },
    { type: "chore", section: "配置項(xiàng)", hidden: true },
    { type: "style", section: "格式", hidden: true },
    { type: "refactor", section: "重構(gòu)", hidden: true },
    { type: "perf", section: "性能", hidden: true },
    { type: "test", section: "測(cè)試", hidden: true },
    { type: "build", section: "構(gòu)建", 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自動(dòng)commit的模板
  releaseCommitMessageFormat:
    "build: v{{currentTag}}版本發(fā)布 \n\nCode Source From: Self Code \nDescription: \nJira: # \n市場(chǎng)項(xiàng)目編號(hào)(名稱(chēng)):",
  //需要server-version更新版本號(hào)的文件
  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"
  },

發(fā)布命令:

yarn release --release-as major
yarn release --release-as minor
yarn release
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容