const fs = require('fs'); const path = require('path'); module.exports = function() { const raw = fs.readFileSync(path.join(__dirname, '../../CHANGELOG.md'), 'utf8'); const lines = raw.split('\n'); const versions = []; let current = null; let currentSection = null; for (const line of lines) { const versionMatch = line.match(/^## \[([^\]]+)\] - (\d{4}-\d{2}-\d{2})/); if (versionMatch) { if (current) versions.push(current); if (versions.length >= 3) break; current = { version: versionMatch[1], date: versionMatch[2], sections: [], intro: '' }; currentSection = null; continue; } const sectionMatch = line.match(/^### (.+)/); if (sectionMatch && current) { currentSection = { type: sectionMatch[1], items: [] }; current.sections.push(currentSection); continue; } const itemMatch = line.match(/^- (.+)/); if (itemMatch && current) { if (currentSection) { currentSection.items.push(itemMatch[1]); } continue; } // Free-form text before first section (e.g. v1.0.0 intro paragraph) if (line.trim() && current && !currentSection && !line.startsWith('#')) { current.intro = current.intro ? current.intro + ' ' + line.trim() : line.trim(); } } if (current && versions.length < 3) versions.push(current); return versions; };