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

test(测试): 测试

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