diff --git a/README.md b/README.md index 8d5ca2b..01cc244 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,62 @@ We’d love your feedback, { + if (url.startsWith('http') || url.startsWith('docs/')) { + return match + } + return `](docs/${url})` + }) + + if (['Enumerations', 'Interfaces', 'Type Aliases'].includes(section.name)) { + if (!utilityTypesAdded) { + apiContent += '\n### Utility Types\n\n' + utilityTypesAdded = true + } + const lines = sectionContent.split('\n') + let listItems = lines.filter(line => line.startsWith('- [')) + if (section.name === 'Enumerations' && listItems.length > 0) { + listItems = listItems.map(item => item + ' (enumeration)') + } + if (listItems.length > 0) { + apiContent += listItems.join('\n') + '\n' + } + } else { + sectionContent = sectionContent.replace( + `## ${section.name}`, + `### ${section.newName}` + ) + apiContent += '\n' + sectionContent + '\n' + } + } + + return apiContent.trim() +} + +function updateReadmeWithDocs() { + try { + const originalReadme = fs.readFileSync(README_PATH, 'utf-8') + + const generatedDocs = fs.readFileSync(DOCS_PATH, 'utf-8') + + const apiReferenceContent = extractCategorizedSections(generatedDocs) + + const originalApiReferenceStart = originalReadme.indexOf('## API Reference') + const nextSectionStart = originalReadme.indexOf( + '## ', + originalApiReferenceStart + 1 + ) + + if (originalApiReferenceStart === -1) { + console.error('Could not find "## API Reference" section in README.md') + process.exit(1) + } + + const beforeApiReference = originalReadme.substring( + 0, + originalApiReferenceStart + ) + + const afterApiReference = + nextSectionStart !== -1 ? originalReadme.substring(nextSectionStart) : '' + + const newReadme = + beforeApiReference + + apiReferenceContent + + (afterApiReference ? '\n\n' + afterApiReference : '') + + fs.writeFileSync(README_PATH, newReadme) + + console.log('✅ README.md updated with categorized API documentation') + } catch (error) { + console.error('❌ Error updating README:', error) + process.exit(1) + } +} + +updateReadmeWithDocs()