Generate a changelog from git metadata.
npx @tessl/cli install tessl/npm-conventional-changelog-cli@5.0.0Conventional Changelog CLI is a command-line tool that generates changelogs from git metadata. It parses commit messages following conventional commit standards and produces formatted changelog files, supporting various presets and configuration options for different project workflows.
npm install -g conventional-changelog-cliThe tool is primarily used as a global CLI command:
conventional-changelog [options]For programmatic usage, import the underlying conventional-changelog library:
import conventionalChangelog from "conventional-changelog";CommonJS:
const conventionalChangelog = require("conventional-changelog");# Generate changelog using angular preset, writing to CHANGELOG.md
conventional-changelog -p angular -i CHANGELOG.md -s
# Generate entire changelog history (overwrite existing)
conventional-changelog -p angular -i CHANGELOG.md -s -r 0
# Output to stdout
conventional-changelog -p angular
# Use custom config and context
conventional-changelog -p angular -n config.js -c context.jsonConventional Changelog CLI is built on several key components:
conventional-changelog-cli) that parses arguments and orchestrates changelog generationconventional-changelog package) that coordinates the entire processThe CLI tool acts as a convenient wrapper around the core conventional-changelog package, making it accessible from command line while supporting both file-based and programmatic configuration.
For programmatic usage, the underlying conventional-changelog function is available:
/**
* Generate changelog stream programmatically
* @param options - Configuration options including preset, releaseCount, etc.
* @param context - Template context with version info, links, etc.
* @param gitRawCommitsOpts - Git commit extraction options
* @param parserOpts - Commit parsing options
* @param writerOpts - Changelog writing options
* @returns Readable stream of generated changelog
*/
function conventionalChangelog(
options?: ChangelogOptions,
context?: TemplateContext,
gitRawCommitsOpts?: GitRawCommitsOptions,
parserOpts?: ParserOptions,
writerOpts?: WriterOptions
): ReadableStream;
interface ChangelogOptions {
preset?: string;
releaseCount?: number;
skipUnstable?: boolean;
outputUnreleased?: boolean;
pkg?: { path?: string };
append?: boolean;
lernaPackage?: string;
tagPrefix?: string;
warn?: (message: string) => void;
debug?: (message: string) => void;
}Programmatic Usage Example:
import conventionalChangelog from "conventional-changelog";
import { createWriteStream } from "fs";
const changelogStream = conventionalChangelog({
preset: "angular",
releaseCount: 1
});
changelogStream.pipe(createWriteStream("CHANGELOG.md"));Controls where the tool reads existing changelogs and writes output.
# Read changelog from specified file
-i, --infile <file>
# Write changelog to specified file (stdout if unspecified)
-o, --outfile <file>
# Use same file for input and output
-s, --same-fileUsage Examples:
# Read from existing changelog, append new entries
conventional-changelog -i CHANGELOG.md -o CHANGELOG.md
# Same file operation (shorthand)
conventional-changelog -i CHANGELOG.md -s
# Output to different file
conventional-changelog -i OLD_CHANGELOG.md -o NEW_CHANGELOG.mdConfigures the commit message parsing and output formatting style.
# Specify preset for commit parsing and formatting
-p, --preset <preset>
# Available presets: angular, atom, codemirror, conventionalcommits,
# ember, eslint, express, jquery, jshintUsage Examples:
# Use Angular commit convention
conventional-changelog -p angular
# Use conventional commits standard
conventional-changelog -p conventionalcommits
# Use jQuery project style
conventional-changelog -p jquerySpecifies package information and custom configuration files.
# Path to package.json file (defaults to closest from cwd)
-k, --pkg <path>
# Path to configuration file
-n, --config <file>
# Path to template context JSON file
-c, --context <file>Configuration File Format:
// config.js example
module.exports = {
options: {
preset: 'angular',
releaseCount: 1
},
gitRawCommitsOpts: {
from: 'v1.0.0'
},
parserOpts: {
// parser options for commit parsing
},
writerOpts: {
// writer options for changelog formatting
mainTemplate: '{{commitGroups.[0].commits.[0].type}}{{testContext}}template'
}
};Context File Format:
{
"version": "1.0.0",
"previousTag": "v0.9.0",
"currentTag": "v1.0.0",
"linkCompare": true,
"repository": "https://github.com/user/repo"
}Controls how many releases to generate and whether to append or prepend.
# Number of releases to generate (0 = regenerate all)
-r, --release-count <count>
# Append newer releases to older ones
-a, --append
# Skip unstable version tags (alpha, beta, rc)
--skip-unstable
# Include unreleased changes in output
-u, --output-unreleasedUsage Examples:
# Generate only the latest release
conventional-changelog -p angular -r 1
# Regenerate entire changelog
conventional-changelog -p angular -r 0
# Append mode (newer releases at end)
conventional-changelog -p angular -a
# Skip pre-release versions
conventional-changelog -p angular --skip-unstableControls which commits and directories are included in the changelog.
# Generate changelog for specific lerna package
-l, --lerna-package <package>
# Tag prefix to consider when reading tags
-t, --tag-prefix <prefix>
# Generate changelog scoped to specific directory
--commit-path <path>Usage Examples:
# Generate for specific lerna package
conventional-changelog -l my-package@1.0.0
# Use custom tag prefix
conventional-changelog -t v
# Scope to specific directory
conventional-changelog --commit-path packages/my-appControls verbosity and debugging output.
# Enable verbose output for debugging
-v, --verboseUsage Examples:
# Enable detailed logging
conventional-changelog -p angular -v
# Debug configuration loading
conventional-changelog -n config.js -v{
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"changelog:all": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
}
}# Recommended release workflow
# 1. Make changes and commit
# 2. Run version bump
npm version patch
# 3. Update changelog (if using version script)
# This runs automatically via npm version hook
# 4. Commit and tag
git commit -m "chore(release): 1.0.1"
git tag v1.0.1
# 5. Push
git push && git push --tags# Generate changelog for specific package
conventional-changelog -l @myorg/package-a@1.0.0 -p angular
# Generate changelog for all packages (run from each package directory)
cd packages/package-a
conventional-changelog -p angular -i CHANGELOG.md -sThe CLI tool exits with specific codes:
Common error scenarios:
# Error: infile required with same-file flag
conventional-changelog -s
# Fix: Provide infile
conventional-changelog -i CHANGELOG.md -s
# Error: Invalid config file
conventional-changelog -n invalid-config.js
# Fix: Ensure config file exists and exports valid configuration
# Error: Git repository issues
# Fix: Ensure you're in a git repository with commitsConfiguration files can specify custom templates for changelog formatting:
module.exports = {
writerOpts: {
mainTemplate: `# Changelog
{{#each releases}}
## {{title}}
{{#each commits}}
- {{subject}}
{{/each}}
{{/each}}
`,
commitPartial: '- {{header}}\n'
}
};module.exports = {
gitRawCommitsOpts: {
from: 'v1.0.0', // Start from specific tag
to: 'HEAD', // End at specific ref
path: './src', // Limit to path
format: '%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci'
}
};module.exports = {
parserOpts: {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'],
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: ['header', 'hash']
}
};Each preset defines specific parsing rules, commit types, and output formatting for different project styles and commit conventions.