CHANGELOG 的实现
项目需要写版本信息时有对除了版本号之外更详细的 changelog 的展示, 于是就需要在平时的 git commit 中进行规范, 才能自动生成CHANGELOG.md.
Husky
首先本地安装 husky yarn add husky -D, 相信做过 lint 的同学一定接触过 husky ,有着丰富的钩子. 其中 pre-commit就可以对代码进行 lint 检查, 避免 lint 的错误被上传.
{
"scripts": {
"lint": "vue-cli-service lint --fix"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint && git add ."
}
}
}
如果使用的是 vue 的脚手架, 其中内置了GitHook, 用的是yorkie这个库, fork 自 husky. 可按需使用.
总之, 自动化就是需要我们往流程里加一些控制命令, 以按照我们的需求实现. 那么 husky 就是很好的控制流程工具, 仅此而已, 具体要怎么做还需要调用其他依赖模块.类似摩登时代里面的流水线, 老板安排卓别林去流水线某个地方去拧螺丝, 但是螺丝怎么拧还得看卓老的, 下面就是螺丝工人们.
Commitizen
完成后全局安装 commitizen
yarn global add commitizen
会在使用 git cz开始提交时被触发, 可以按照模板书写适合生成 CHANGELOG 的 commit, 这样才可以通过下面的 commitlint 工具
你可以理解为就是一个格式化 commit 的东西.
安装完成后在项目根目录下使用
commitizen init cz-conventional-changelog --yarn --dev --exact
配置commitizen, 会在package.json 中添加commitizen路径
{
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
Commitlint
这是检查 commit-msg 是否符合标准, 那么什么是标准呢? js 有 eslint, 那么 commit 就有 commitlint, 需要安装@commitlint/cli commitlint 的 命令行控制台, 用来传递 commit-msg 给标准 --> @commitlint/config-conventional
yarn add @commitlint/cli @commitlint/config-conventional -D
类似 eslint.config.js一样需要对 commitlint做配置. 新建一个commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional']
};
然后在 husky 的 hooks 中添加对应命令. 记住, 这是螺丝工, husky 是流水线.
{
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
至此, 我们之后的所有 commit msg 都会符合 commitlint 的标准. 也就意味着可以自动生成有语义的 CHANGHELOG, 那么材料(commit msgs)有了, 来自动化加工出 CHANGELOG 吧.
standard-version
standard-version 可以使用脚本生成 CHNAGELOG, 并且更新版本号, 如果有需要还可以创建 tag. 详情就看文档按需去自定义了.
yarn add standard-version -D
安装完成之后, 创建一个发布脚本.
{
"script": {
"release": "standard-version"
}
}
在 git status clean 的时候使用
yarn release
就会生成一个 CHANGELOG.md, 并更新版本号.
快去试试吧.
以上内容都是 yarn 版本, 一下是npm 的版本:
package.json 的配置一样:
{
"name": "Haha",
"version": "0.1.0",
"private": true,
"scripts": {
"lint": "vue-cli-service lint --fix",
"release": "standard-version",
"c": "git add . && git cz"
},
"dependencies": {
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"cz-conventional-changelog": "3.0.2",
"husky": "^3.1.0",
"standard-version": "^7.0.1"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint && git add .",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
指令:
// 安装全局依赖
npm install --global commitizen
// 安装项目依赖
npm install --save-dev standard-version husky @commitlint/config-conventional @commitlint/cli
// 配置 commitizen
commitizen init cz-conventional-changelog --save-dev --save-exact
// 生成 CHANGELOG
npm run release
CHANGELOG 的实现的更多相关文章
- jenkins使用git SCM时changelog乱码(Jenkins部署在Linux上,任务在Windows Slave上构建)
问题原因 changelog的获取方式(git-client插件): 首先调用git whatchanged命令,读取输出字节流(UTF-8编码的Commit Message). 将字节流解码为字符串 ...
- 【PHP】PHP5.4.0版本号ChangeLog具体解释(上)
前言 随着大量的框架使用composer和namespace,渐渐的线上环境也从之前的5.3变成了5.4或者5.5甚至5.6,随着7月份PHP7的公布,会有很多其它的公司採用新版本号. 之前好久就想写 ...
- 根据Eclipse SVN changelog使用ANT自动打增量包
1.获取changeLog 用eclipseSVN的插件功能查看history. 将日志文件导出到本地文件svn_change.log,格式如下 r63 | xiaodaoshi | 2014-08- ...
- 利用shell脚本生成CHANGELOG.md(包含git提交规范)
前言 我们经常看到github上面有很多CHANGELOG.MD包含版本的更新信息,如果我们的git提交能遵循一定的规范,那么使用gitlog就能很方便的生成它 生成结果  shell脚本 http ...
- 自动生成CHANGELOG.md
$ npm install -g conventional-changelog-cli $ cd my-project $ conventional-changelog -p angular -i C ...
- Jenkins ChangeLog
Log changes in Jenkins - Stack Overflowhttps://stackoverflow.com/questions/13631145/log-changes-in-j ...
- Jenkins Git Changelog Plugin
https://wiki.jenkins.io/display/JENKINS/Git+Changelog+Plugin
- git使用总结(包含git commit message 和 changelog 工具的介绍)
[git的配置] 1.配置用户名和邮箱: 分为全局配置和局部配置 --system 系统配置 --global 全局配置 --local 局部配置 Git读取时:优先从local>glo ...
- 关于Mantis变更日志(Changelog)和路线图(Roadmap)的说明
变更日志(Changelog):是已经修改好了问题的日志,需要给项目添加版本号,并且在添加/解决问题时都指定了相应的版本号,才会显示. 路线图(Roadmap):是计划在某个版本修改某些问题的日志,需 ...
- git commit 、CHANGELOG 和版本发布的标准自动化
一直以来,因为团队项目迭代节奏很快,每次发布的更新日志和版本更新都是通过人肉来完成的.有时候实在忙的团团转,对于手动的写这些更新信息就显得力不从心了.对于团队新来的小伙伴,有时候遇到些紧急情况,就更显 ...
随机推荐
- Java 代码快速注释 和 取消注释
注释掉代码: 把要注释的代码选中: 加/* */ 形式的注释 -> Ctrl+Shift+/ 加 //形式的形式的注释 -> ctrl+/ 取消代码注释: 把要取消注释的代码选中: ...
- Centos7系统下以RPM方式如何安装mysql-5.7
检查系统是否装有mariadb rpm -qa | grep mariadb 卸载mariadb 强制卸载mariadb rpm -e --nodeps mariadb-libs-5.5.35-3.e ...
- Github搭建个人博客的总结
1. 参考 这个 博客 : https://blog.csdn.net/xudailong_blog/article/details/78762262 2. 把上面按照的就安装,并把git 仓库克隆 ...
- 推荐一个好用的免费开源的笔记本软件CherryTree
我是一个好奇心很强的人,对未知的事物总有一种想要追根究底的冲动.多年以来,我学了很多东西,也学的很杂,积累了很多领域的知识.但不得不承认,人的记忆力很有限,学的越多忘的就越多.很久以前我就在想,怎么样 ...
- 删除Vue中无权限的【node_modules】文件
npm install rimraf -g rimraf node_modules
- nginx处理请求的11个阶段
Nginx 处理请求的过程一共划分为 11 个阶段,按照执行顺序依次是 post-read.server-rewrite.find-config.rewrite.post-rewrite.preacc ...
- hdoj1711(kmp算法)
题目链接:https://www.cnblogs.com/kuangbin/archive/2012/08/14/2638803.html 题意:给定两个数组a.b,在数组a中查找b,求第一次出现的下 ...
- 深入理解JS的事件绑定、事件流模型
一.JS事件 (一)JS事件分类 1.鼠标事件: click/dbclick/mouseover/mouseout 2.HTML事件: onload/onunload/onsubmit/onresi ...
- [转帖]Intel 上一代 可扩展CPU的简单报价
8.1万元人间毒物!Intel 28核铂金版Xeon 8180零售上市 http://news.mydrivers.com/1/541/541670.htm 猜你想看:英特尔 CPU处理器 Xeon ...
- hyper-v虚拟机centos7网络配置
原文地址:https://jingyan.baidu.com/article/91f5db1b0279bd1c7e05e377.html hyper-v安装了centos7之后并不能上网,这里简单介绍 ...