一款非常灵活的 Changelog 日志生成工具(应用于 npm 包或应用项目中)

Changelog 生成工具

@eat-fish/changelog 是一款专用于 npm 包版本升级与 版本变更日志生成的工具, 也可以使用在应用项目中

通过提取 commit 信息来生成 CHANGELOG.md 文件

在发布新版本前使用 @eat-fish/changelog 来生成下一个版本号与 CHANGELOG 变更日志

通过自定义 commit matcher 可以实现基于 commit 提取生成或者 基于 PR 提取生成两种方式的 CHANGELOG 日志

示例项目

基于 commit 方案

通过 自定义 配置文件 matcher 函数来提取 特定 commit 生成

js 复制代码
module.exports = {
  matcher: (rawCommitInfo) => {
    const { message } = rawCommitInfo;

    // 提取 feat、fix 类型 的 commit
    const [, type, scope, description] = message.match(/(feat|fix)(?:\(([^)]*?)\))?:\s?(.+)/) || [];

    if (!type || !description) return false;

    return {
      type,
      scope,
      description,
    };
  },
};

changelog-commit-example

CHANGELOG 示例查看

基于 PR 方案

通过 自定义 配置文件 matcher 函数来提取 特定 PR commit 生成

js 复制代码
module.exports = {
  matcher: (rawCommitInfo) => {
    const { message, description: rawDescription } = rawCommitInfo;

    // 先过滤 PR 类型 commit
    const messageMatchRes = message.match(/Merge pull request #\d+ from ([^\\]+)\/(.+)/) || [];

    if (!messageMatchRes) return false;

    const [, author] = messageMatchRes;

    // 再提取 commit 信息
    const [, type, scope, description] = rawDescription.match(/(feat|fix)(?:\(([^)]*?)\))?:\s?(.+)/) || [];

    if (!type || !description) return false;

    return {
      type,
      scope,
      description,
      author,
    };
  },
};

changelog-pr-example

CHANGELOG 示例查看

使用

安装

sh 复制代码
pnpm add @eat-fish/changelog@latest -D

手动创建第一个 tag

如果是首次引入 @eat-fish/changelog, 需要先手动创建第一个 tag

使用如下命令, 创建的 tag 名为 v+ 当前 package.json 中的版本号, 例如 v1.0.0

sh 复制代码
git tag -a v1.0.0 -m "Version 1.0.0"

开始

运行前确保 没有 package.json 文件以及 CHANGELOG.md 文件的变更

然后执行升级并生成 CHANGELOG 命令

sh 复制代码
# 可以选择你想升级的版本

# fix 版本变更: 1.0.0 -> 1.0.1
pnpm changelog release patch

# feature 版本变更: 1.0.0 -> 1.1.0
pnpm changelog release minor

# feature 版本变更: 1.0.0 -> 2.0.0
pnpm changelog release major

确认无误后提交升级变更

运行完成后将自动 commit

包含 package.json 版本号变更以及 CHANGELOG.md 日志变更

确认无误后可以提交上去, 如有问题则使用以下命令撤回

sh 复制代码
git reset --hard HEAD~1

后续如果是 npm 包可以正常走 npm publish 发布

如果是应用项目则结束了

相关推荐
崔庆才丨静觅15 分钟前
hCaptcha 验证码图像识别 API 对接教程
前端
passerby60611 小时前
完成前端时间处理的另一块版图
前端·github·web components
掘了1 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
崔庆才丨静觅1 小时前
实用免费的 Short URL 短链接 API 对接说明
前端
崔庆才丨静觅2 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端
猫头虎2 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
崔庆才丨静觅2 小时前
比官方便宜一半以上!Midjourney API 申请及使用
前端
Moment2 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
崔庆才丨静觅2 小时前
刷屏全网的“nano-banana”API接入指南!0.1元/张量产高清创意图,开发者必藏
前端
剪刀石头布啊2 小时前
jwt介绍
前端