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.hqwc.cn/news/58849.html

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

相关文章

RabbitMQ - 简单案例

目录 0.引用 1.Hello world 2.轮训分发消息 2.1 抽取工具类 2.2 启动两个工作线程接受消息 2.4 结果展示 3.消息应答 3.1 自动应答 3.2 手动消息应答的方法 3.3 消息自动重新入队 3.4 消息手动应答代码 4.RabbitMQ 持久化 4.1 队列如何实现持久化 4.2 消息实现持久化 5.不…

培训报名小程序报名确认开发

目录 1 创建页面2 创建URL参数3 信息展示4 消息订阅5 页面传参6 程序预览总结 我们上一篇介绍了报名功能的开发,在用户报名成功后需要展示报名的确认信息,如果信息无误提示用户支付,在支付之前需要让用户进行授权,允许小程序给用户…

Spring 知识点

Spring 1.1 Spring 简介 1.1.1 Spring 概念 Spring是一个轻量级Java开发框架,最早有Rod Johnson创建为了解决企业级应用开发的业务逻辑层和其他各层的耦合问题Spring最根本的使命是解决企业级应用开发的复杂性,即简化Java开发。使现有的技术更加容易使…

从8个新 NFT AMM,聊聊能如何为 NFT 提供流动性

DeFi 的出现,开启了数字金融民主化的革命。其中,通过 AMM 自由创建流动性池极大地增加了 ERC-20 Token 的流动性,并为一些长尾 Token 解锁了价值的发现,因而今天在链上可以看到各种丰富的交易、借贷和杠杆等活动。 而另一方面&am…

C语言一些有趣的冷门知识

文章目录 概要1.访问数组元素的方法运行结果 2.中括号的特殊用法运行结果 3.大括号的特殊用法运行结果 4.sizeof的用法运行结果 5.渐进运算符运行结果 小结 概要 本文章只是介绍一些有趣的C语言知识,纯属娱乐。这里所有的演示代码我是使用的编译器是Visual Studio …

linux基于信号量实现多线程生产者消费者模型

基于信号量实现多线程生产者消费者模型。 编程思路: 1.食物的初始化编号为100: beginnum 100; 2.仓库有5个空碗,最多保存5个食物:queue[5]; 3.初始化空碗的数量为5,食物的数量为0&#xff1a…

Go context.WithCancel()的使用

WithCancel可以将一个Context包装为cancelCtx,并提供一个取消函数,调用这个取消函数,可以Cancel对应的Context Go语言context包-cancelCtx 疑问 context.WithCancel()取消机制的理解 父母5s钟后出门,倒计时,父母在时要学习,父母一走就可以玩 …

python之prettytable库的使用

文章目录 一 什么是prettytable二 prettytable的简单使用1. 添加表头2. 添加行3. 添加列4. 设置对齐方式4. 设置输出表格样式5. 自定义边框样式6. 其它功能 三 prettytable在实际中的使用 一 什么是prettytable prettytable是Python的一个第三方工具库,用于创建漂亮…

爬虫来介绍ChromeF12 谷歌开发者工具 -Network

了解网页基础(HTML、CSS、JavaScript) 了解HTTP基本原理 了解JSON格式 了解Ajax请求 了解爬虫基本原理 (一)、Chrome开发者工具面板概述 Elements 查找网页源代码HTML中的任一元素,手动修改任一元素的属性和样式且能实时在浏览器里面得到反馈。 比如我们在Event Listener…

springboot vue 初步集成onlyoffice

文章目录 前言一、vue ts1. 安装依赖2. onlyoffice组件实现(待优化)3. 使用组件4. 我的配置文件 二、springboot 回调代码1. 本地存储 三、效果展示踩坑总结问题1问题2 前言 对接onlyoffice,实现文档的预览和在线编辑功能。 一、vue ts …

Android数据存储选项:SQLite、Room等

Android数据存储选项:SQLite、Room等 1. 引言 在移动应用的开发过程中,数据存储是至关重要的一环。无论是用户的个人信息、设置配置还是应用产生的临时数据,都需要在设备上进行存储以便随时访问。随着移动应用的日益发展,数据存…

Openlayers实战:判断共享单车是否在电子围栏内

共享单车方便了我们的日常生活,解决了后一公里的行程问题。为了解决共享单车乱放的问题,运营部门规划出一些围栏,配合到电子地图上即为电子围栏,只有放在围栏内才能停车结算,在我们的Openlayers实战示例中,即模拟这一场景。 效果图 源代码 /* * @Author: 大剑师兰特(x…