根据当前项目 package.json 版本与 Git 提交记录生成中文版本日志。用于用户提出"生成版本日志""生成 changelog""发布新版本并生成更新记录"等请求时,自动读取当前版本号、定位上一版本、汇总版本区间 commit,并更新 docs/public/changelogs/cn.json(新增版本、生成中文 summary、按类型归类变更)。
按以下流程更新 docs/public/changelogs/cn.json。
package.json 中的 version 作为 currentVersion。docs/public/changelogs/cn.json,确认是否已存在 currentVersion。previousVersion:
currentVersion 已存在于 changelog:取它的下一条记录版本号。currentVersion 不存在于 changelog:取第一条记录版本号。previousVersion,报错并停止。优先按以下规则确定区间:
v{currentVersion}:使用 v{previousVersion}..v{currentVersion}。v{currentVersion}:使用 v{previousVersion}..HEAD。v{previousVersion} 不存在:回退为从首个提交到 HEAD,并在结果中明确标注"缺少上一版本 tag,采用全量范围"。使用命令:
git log --no-merges --pretty=format:'%h%x09%s' <RANGE>
必要时读取正文:
git show -s --format='%B' <commit>
将 commit 按以下类型归类到 changes[].type:
featfixrefactorperfstyledocstestbuildcichorerevertother(无法识别前缀时)归类规则:
feat:, fix(scope):)。other。为本版本生成 1 句中文 summary:
目标文件:docs/public/changelogs/cn.json
更新规则:
version: currentVersiondate: 当前日期(YYYY-MM-DD)summary: 新生成摘要changes: 分类后的数组(每个元素为 { "type": string, "items": string[] })npx prettier --write docs/public/changelogs/cn.json
JSON.stringify(..., null, 2) 的最小格式保证,并在输出中明确提示"未执行 Prettier 格式化"。写入后执行以下检查:
version 无重复。changes 中每个 items 至少 1 条。feat / fix)。若自检失败,修复后再输出结果。
补充检查:
docs/public/changelogs/cn.json 已经过 Prettier(若可用)。自检通过并输出结果后,必须询问用户:
"changelog 已生成完毕。是否继续执行 sync-changelog 技能,将本版本日志同步为多语言版本并提交?"
../sync-changelog/SKILL.md。需要查看项目格式细节时,读取:
references/changelog-format.mdscripts/extract_commits_for_changelog.shscripts/format_changelog.sh