The generateMarkdown function is the primary entrypoint for converting a list of commits into a formatted Markdown changelog. It organizes commits into sections based on their type (e.g., features, fixes) and handles breaking changes separately.
Key behaviors:
- Breaking Changes: Commits marked as
isBreaking are placed in a dedicated section using the title provided in options.titles.breakingChanges. - Type Grouping: Commits are grouped by their
type according to the mapping defined in options.types. - Scope Grouping: If
options.group is enabled, commits are grouped by their scope. The logic automatically detects if scope grouping is necessary based on whether any scope contains multiple commits. - GitHub Integration: If
options.repo and options.baseUrl are provided, it generates a "View changes on GitHub" link at the bottom of the changelog. - Gitmoji Support: The output is processed through
convert-gitmoji to ensure emojis are correctly rendered in the Markdown output.
To use this, you must provide an array of Commit objects and a ResolvedChangelogOptions configuration object.
import { generateMarkdown } from './src/style/markdown'
const commits = [...] // Array of Commit objects
const options = {
baseUrl: 'github.com/antfu',
repo: 'antfu/changelogithub',
from: 'v14.0.0',
to: 'v15.0.0',
capitalize: true,
emoji: true,
group: 'multiple', // or true, or false
scopeMap: { 'core': 'Core Engine' },
types: {
feat: { title: 'Features' },
fix: { title: 'Bug Fixes' }
},
titles: {
breakingChanges: 'Breaking Changes'
}
}
const markdown = generateMarkdown(commits, options)