auto-changelog的简单使用

auto-changelog的简单使用

自动化生成Git提交记录,CHANGELOG.md文件

github:https://github.com/cookpete/auto-changelog

安装

npm install -g auto-changelog

配置脚本

package.json文件下

"scripts": {"changelog": "auto-changelog -p --commit-url http://xxxx/xxxx/amwiki/-/commit/{id} --sort-commits date-desc --commit-limit true --ignore-commit-pattern chore --hide-empty-releases true"
}

运行脚本

npm run changelog

参考配置列表

Usage: auto-changelog [options]Options:-o, --output [file]                 # output file, default: CHANGELOG.md-c, --config [file]                 # config file location, default: .auto-changelog-t, --template [template]           # specify template to use [compact, keepachangelog, json], default: compact-r, --remote [remote]               # specify git remote to use for links, default: origin-p, --package                       # use version from package.json as latest release-v, --latest-version [version]      # use specified version as latest release-u, --unreleased                    # include section for unreleased changes-l, --commit-limit [count]          # number of commits to display per release, default: 3-b, --backfill-limit [count]        # number of commits to backfill empty releases with, default: 3--commit-url [url]              # override url for commits, use {id} for commit id--issue-url [url]               # override url for issues, use {id} for issue id--merge-url [url]               # override url for merges, use {id} for merge id--compare-url [url]             # override url for compares, use {from} and {to} for tags--issue-pattern [regex]         # override regex pattern for issues in commit messages--breaking-pattern [regex]      # regex pattern for breaking change commits--merge-pattern [regex]         # add custom regex pattern for merge commits--commit-pattern [regex]        # pattern to include when parsing commits--ignore-commit-pattern [regex] # pattern to ignore when parsing commits--tag-pattern [regex]           # override regex pattern for version tags--tag-prefix [prefix]           # prefix used in version tags, default: v--starting-version [tag]        # specify earliest version to include in changelog--starting-date [yyyy-mm-dd]    # specify earliest date to include in changelog--ending-version [tag]          # specify latest version to include in changelog--sort-commits [property]       # sort commits by property [relevance, date, date-desc, subject, subject-desc], default: relevance--release-summary               # display tagged commit message body as release summary--unreleased-only               # only output unreleased changes--hide-empty-releases           # hide empty releases--hide-credit                   # hide auto-changelog credit--handlebars-setup [file]       # handlebars setup file--append-git-log [string]       # string to append to git log command--append-git-tag [string]       # string to append to git tag command--prepend                       # prepend changelog to output file--stdout                        # output changelog to stdout--plugins [...name]             # use plugins to augment commit/merge/release information-V, --version                       # output the version number-h, --help                          # output usage information# Write log to CHANGELOG.md in current directory
auto-changelog# Write log to HISTORY.md using keepachangelog template
auto-changelog --output HISTORY.md --template keepachangelog# Disable the commit limit, rendering all commits for every release
auto-changelog --commit-limit false

配置示例

当前配置

"changelog": "auto-changelog -p --commit-url http://192.168.217.8/xxxx/xxxx/-/commit/{id} --sort-commits date-desc --commit-limit true --ignore-commit-pattern chore --hide-empty-releases true"

命令配置解释:

-p:根据package发布版本进行分类

–commit-url http://192.168.217.8/xxxx/xxxx/-/commit/{id}:提交commit地址,动态拼接commitid

–sort-commits date-desc:根据commit时间降序

–commit-limit true:限制每次release展示的commit数量

–ignore-commit-pattern chore:忽略指定commit提交,此处忽略commit信息以chore开头的commit

–hide-empty-releases true:隐藏空的release

注意:配置与配置之间有空格

生成md文件示例

上面配置示例实际生成的md文件如下

默认生成示例

自定义模板

支持用自定义模板生成md文件

  1. 新建一个模板文件如:changelog-template.hbs

  2. 模板文件入填入代码,使用handlebars模板引擎

    # 更新日志
    {{#each releases}}
    ## {{isoDate}}{{#each merges}}
    - A merge has a {{message}}, an {{id}} and a {{href}} to the PR.{{/each}}{{#each fixes}}
    - Each fix has a {{commit}} with a {{commit.subject}}, an {{id}} and a {{href}} to the fixed issue.{{/each}}{{#each commits}}
    - {{subject}}[{{shorthash}}]({{href}}){{!-- 这里需要有个换行 否则二级标题会被渲染进li中 --}}{{/each}}
    {{/each}}
    
  3. 修改package.json文件中的脚本,以提供的模板生成内容。

    1. 模板文件changelog-template.hbs放在项目根目录,与package.json同级即可
    2. -o ./library/home-首页.md 指定输出文件目录
    "scripts": {"changelog-template": "auto-changelog --template changelog-template.hbs -o ./library/home-首页.md -p --sort-commits date-desc --commit-limit false --ignore-commit-pattern chore --hide-empty-releases true"
    },
    
  4. 运行命令后,即可按照我们的模板生成内容

模板修改

  1. 模板中的这些变量啥意思?源码数据文件->
    数据源示例

  2. 更个性化一点的修改,渲染自己想要的数据。

    找到auto-changelog源码包中的template.js文件,路径为node_modules\auto-changelog\src\template.js

    compileTemplate函数中调用自己的函数:

    const compileTemplate = async (releases, options) => {const { template, handlebarsSetup } = optionsif (handlebarsSetup) {const path = /^\//.test(handlebarsSetup) ? handlebarsSetup : join(process.cwd(), handlebarsSetup)const setup = require(path)if (typeof setup === 'function') {setup(Handlebars)}}//渲染之前调用,修改源数据customDate(releases)const compile = Handlebars.compile(await getTemplate(template), COMPILE_OPTIONS)if (template === 'json') {return compile({ releases, options })}return cleanTemplate(compile({ releases, options }))
    };//自定义函数
    function customDate(releases) {// 存放已经出现过的时间  进行去重操作let Time=[];    releases.forEach(item1 => {item1.commits.forEach((item2,index2)=>{// 遍历当前release下的所有commitif(Time.indexOf(item2.niceDate)==-1){Time.push(item2.niceDate);//没有出现过 可以显示item2.showTime=true;let date=new Date(item2.date).toLocaleDateString();item2.isoDate=date.replace(/\//g,"-");}else{// 出现过item2.showTime=false;}})});
    }
    
  3. 修改模板文件

    # 更新日志
    {{#each releases}}
    {{!-- ## {{isoDate}} --}}{{#each merges}}
    - A merge has a {{message}}, an {{id}} and a {{href}} to the PR.{{/each}}{{#each fixes}}
    - Each fix has a {{commit}} with a {{commit.subject}}, an {{id}} and a {{href}} to the fixed issue.{{/each}}{{#each commits}}{{#if showTime}}### {{isoDate}}{{/if}}
    - {{subject}}[{{shorthash}}]({{href}})
    {{!-- 这里需要有个换行 否则二级标题会被渲染进li中 --}}{{/each}}
    {{/each}}
    
  4. 这里实现的效果是输出每天的提交记录:
    生成示例

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/24910.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

IntelliJ IDEA 如何优雅的添加文档注释(附详细图解)

IntelliJ IDEA 如何优雅的添加文档注释(附详细图解) 📌提要✍✍类注释✍✍方法注释 📌提要 在开发过程中,最常用的注释有两种:类注释和方法注释,分别是为类和方法添加作者、日期、版本号、描述等…

小程序的 weiui的使用以及引入

https://wechat-miniprogram.github.io/weui/docs/quickstart.html 网址 1.点进去,在app.json里面配置 在你需要的 页面的 json里面配置,按需引入 然后看文档,再在你的 wxml里面使用就好了

2023年8月初补题

看这个人的专栏 https://blog.csdn.net/qq_42555009/category_8770183.html 有一定思维难度,贪心,用multiset实现 翻译: 链接:https://ac.nowcoder.com/acm/contest/33187/H 来源:牛客网 在夜之城的中心有一座高大…

JavaScript Es6 _1 笔记

JavaScript Es6 _1 笔记 学习作用域、变量提升、闭包等语言特征,加深对 JavaScript 的理解,掌握变量赋值、函数声明的简洁语法,降低代码的冗余度。 理解作用域对程序执行的影响能够分析程序执行的作用域范围理解闭包本质,利用闭包…

协议,序列化,反序列化,Json

文章目录 协议序列化和反序列化网络计算器protocol.hppServer.hppServer.ccClient.hppClient.cclog.txt通过结果再次理解通信过程 Json效果 协议 协议究竟是什么呢?首先得知道主机之间的网络通信交互的是什么数据,像平时使用聊天APP聊天可以清楚&#x…

选择排序(指针法)

描述 用选择法对10个整数排序。 输入 输入包含10个整数,用空格分隔。 输出 输出排序后的结果,用空格分隔。 输入样例 1 3 1 4 1 5 9 2 6 5 3 输出样例 1 1 1 2 3 3 4 5 5 6 9 输入样例 2 2 4 6 8 10 12 14 16 18 20 输出样例 2 2 4 6 8 1…

迭代器模式(Iterator)

迭代器模式是一种行为设计模式,可以在不暴露底层实现(列表、栈或树等)的情况下,遍历一个聚合对象中所有的元素。 Iterator is a behavior design pattern that can traverse all elements of an aggregate object without exposing the internal imple…

【二分查找】74. 搜索二维矩阵

74. 搜索二维矩阵 解题思路 方法1 将二维数组转换为一维数组使用二分查找 class Solution {public boolean searchMatrix(int[][] matrix, int target) {// 使用二分查找// 将矩阵写入一个数组中 然后使用二分查找算法int[] a new int[matrix.length * matrix[0].length];i…

机器学习常用Python库安装

机器学习常用Python库安装 作者日期版本说明Dog Tao2022.06.16V1.0开始建立文档 文章目录 机器学习常用Python库安装Anaconda简介使用镜像源配置 Pip简介镜像源配置 CUDAPytorch安装旧版本 TensorFlowGPU支持说明 DGL简介安装DGLLife RDKitscikit-multilearn Anaconda 简介 …

Python 程序设计入门(004)—— 赋值运算符与常用函数

Python 程序设计入门(004)—— 赋值运算符与常用函数 目录 Python 程序设计入门(004)—— 赋值运算符与常用函数一、赋值运算符二、常用的数学函数1、round() 函数2、pow() 函数3、divmod() 函数 三、字符串与 str() 函数1、字符串…

UEditorPlus v3.3.0 图片上传压缩重构,UI优化,升级基础组件

UEditor是由百度开发的所见即所得的开源富文本编辑器,基于MIT开源协议,该富文本编辑器帮助不少网站开发者解决富文本编辑器的难点。 UEditorPlus 是有 ModStart 团队基于 UEditor 二次开发的富文本编辑器,主要做了样式的定制,更符…

C++经典排序算法详解

目录 一、选择排序 二、冒泡排序 三、插入排序 一、选择排序 选择排序 选择排序(Selection sort)是一种简单直观的排序算法。它的工作原理是:第一次从待排序的数据元素中选出最小(或最大)的一个元素,存…

解决vite+vue3项目npm装包失败

报错如下: Failed to remove some directories [ npm WARN cleanup [ npm WARN cleanup D:\\V3Work\\v3project\\node_modules\\vue, npm WARN cleanup [Error: EPERM: operation not permitted, rmdir D:\V3Work\v3project\node_modules\vue\reactivity\…

题解 | #B.Distance# 2023牛客暑期多校6

B.Distance 贪心(?) 题目大意 对于两个大小相同的多重集 A , B \mathbb{A},\mathbb{B} A,B ,可以选择其中任一元素 x x x 执行操作 x x 1 xx1 xx1 任意次数,最少的使得 A , B \mathbb{A},\mathbb{B} A,B 相同的操作次数记为 C ( A , B ) C(\m…

嵌入式开发学习(STC51-13-温度传感器)

内容 通过DS18B20温度传感器,在数码管显示检测到的温度值; DS18B20介绍 简介 DS18B20是由DALLAS半导体公司推出的一种的“一线总线(单总线)”接口的温度传感器; 与传统的热敏电阻等测温元件相比,它是一…

虚函数表(vtable)

虚函数表(通常简称为 vtable)是 C 用于实现多态行为的一种机制。当一个类定义了虚函数或者继承了虚函数,编译器会为该类生成一个虚函数表。下面详细介绍虚函数表及其工作原理: 1. 什么是虚函数表? 虚函数表是一个存放…

关于Express 5

目录 1、概述 2、Express 5的变化 2.1 弃用或删除内容的列表: app.param(name,fn)名称中的前导冒号(:) app.del() app.param(fn) 复数方法名 res.json&#xff0…

Codeforces Round 890 (Div. 2) D. More Wrong(交互题 贪心/启发式 补写法)

题目 t(t<100)组样例&#xff0c;长为n(n<2000)的序列 交互题&#xff0c;每次你可以询问一个区间[l,r]的逆序对数&#xff0c;代价是 要在的代价内问出最大元素的位置&#xff0c;输出其位置 思路来源 neal Codeforces Round 890 (Div. 2) supported by Constructo…

springboot工程测试临时数据修改技巧

目录 properties临时属性测试注入 args临时参数测试注入 bean配置类属性注入&#xff08;Import&#xff09; SpringBootTest是一个注解&#xff0c;用于测试Spring Boot应用程序。它可用于指示Spring Boot测试应用程序的启动点&#xff0c;并为测试提供一个可用的Spring应用…

Godot 4 源码分析 - Path2D与PathFollow2D

学习演示项目dodge_the_creeps&#xff0c;发现里面多了一个Path2D与PathFollow2D 研究GDScript代码发现&#xff0c;它主要用于随机生成Mob var mob_spawn_location get_node(^"MobPath/MobSpawnLocation")mob_spawn_location.progress randi()# Set the mobs dir…