提交 71e865f2 authored 作者: lidongxu's avatar lidongxu

test(测试): 测试

n
上级 09a359fe
......@@ -2,41 +2,60 @@ import fs from 'fs'
function parseChangelog(changelogText) {
const result = {};
const versionRegex = /^### \[([\d.]+)\]\([^)]+\)/;
const sectionRegex = /^### (.*?) \| (.*)$/;
const descRegex = /^\* \*\*(.*?):?\*\* (.*?) \(/;
const versionRegex = /^## \[([\d.]+)\]\([^)]+\)/; // 匹配二级标题版本
const sectionRegex = /^### (.*?) \| (.*)$/; // 匹配三级标题部分
const breakingChangesRegex = /^### ⚠ BREAKING CHANGES$/; // 匹配BREAKING CHANGES
const descRegex = /^\* \*\*(.*?):?\*\* (.*?) \(/; // 匹配描述行
let currentVersion = null;
let currentSection = null;
let isBreakingChanges = false;
const lines = changelogText.split('\n');
for (const line of lines) {
// 检查是否是版本行
// 检查是否是版本行 (二级标题)
const versionMatch = line.match(versionRegex);
if (versionMatch) {
currentVersion = versionMatch[1];
result[currentVersion] = [];
result[currentVersion] = {
breakingChanges: [],
changes: []
};
isBreakingChanges = false;
continue;
}
// 如果不是版本行但有当前版本,则检查是否是章节行
// 如果是当前版本下的内容
if (currentVersion) {
// 检查是否是BREAKING CHANGES部分
const breakingMatch = line.match(breakingChangesRegex);
if (breakingMatch) {
isBreakingChanges = true;
continue;
}
// 检查是否是普通的三级标题部分
const sectionMatch = line.match(sectionRegex);
if (sectionMatch) {
isBreakingChanges = false;
currentSection = {
info: sectionMatch[2],
type: sectionMatch[2], // 取 | 后面的部分作为类型
desc: []
};
result[currentVersion].push(currentSection);
result[currentVersion].changes.push(currentSection);
continue;
}
// 检查是否是描述行
// 收集描述内容
const descMatch = line.match(descRegex);
if (descMatch && currentSection) {
if (descMatch) {
const description = descMatch[2].trim();
currentSection.desc.push(description);
if (isBreakingChanges) {
result[currentVersion].breakingChanges.push(description);
} else if (currentSection) {
currentSection.desc.push(description);
}
}
}
}
......@@ -47,4 +66,5 @@ function parseChangelog(changelogText) {
const changelog = './CHANGELOG.md'
const changeData = fs.readFileSync(changelog, 'utf-8')
const result = parseChangelog(changeData)
// 把对象写回到 version.js
console.log(result)
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论