forked from git.gladyson/openmonetis
feat(ajustes): adicionar aba changelog com histórico de versões
Parser lê o CHANGELOG.md e exibe as versões com badges por tipo de mudança (Adicionado, Alterado, Corrigido) na página de ajustes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
60
lib/changelog/parse-changelog.ts
Normal file
60
lib/changelog/parse-changelog.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
export type ChangelogSection = {
|
||||
type: string;
|
||||
items: string[];
|
||||
};
|
||||
|
||||
export type ChangelogVersion = {
|
||||
version: string;
|
||||
date: string;
|
||||
sections: ChangelogSection[];
|
||||
};
|
||||
|
||||
export function parseChangelog(): ChangelogVersion[] {
|
||||
const filePath = path.join(process.cwd(), "CHANGELOG.md");
|
||||
const content = fs.readFileSync(filePath, "utf-8");
|
||||
const lines = content.split("\n");
|
||||
|
||||
const versions: ChangelogVersion[] = [];
|
||||
let currentVersion: ChangelogVersion | null = null;
|
||||
let currentSection: ChangelogSection | null = null;
|
||||
|
||||
for (const line of lines) {
|
||||
const versionMatch = line.match(/^## \[(.+?)\] - (.+)$/);
|
||||
if (versionMatch) {
|
||||
if (currentSection && currentVersion) {
|
||||
currentVersion.sections.push(currentSection);
|
||||
}
|
||||
currentVersion = {
|
||||
version: versionMatch[1],
|
||||
date: versionMatch[2],
|
||||
sections: [],
|
||||
};
|
||||
versions.push(currentVersion);
|
||||
currentSection = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
const sectionMatch = line.match(/^### (.+)$/);
|
||||
if (sectionMatch && currentVersion) {
|
||||
if (currentSection) {
|
||||
currentVersion.sections.push(currentSection);
|
||||
}
|
||||
currentSection = { type: sectionMatch[1], items: [] };
|
||||
continue;
|
||||
}
|
||||
|
||||
const itemMatch = line.match(/^- (.+)$/);
|
||||
if (itemMatch && currentSection) {
|
||||
currentSection.items.push(itemMatch[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentSection && currentVersion) {
|
||||
currentVersion.sections.push(currentSection);
|
||||
}
|
||||
|
||||
return versions;
|
||||
}
|
||||
Reference in New Issue
Block a user