CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-conventional-changelog

Generate a changelog from git metadata using conventional commit conventions.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

cli.mddocs/

Command Line Interface

The conventional-changelog CLI provides a comprehensive command-line interface for generating changelogs with extensive options for various workflows, from simple one-off generations to complex CI/CD integrations.

class ConventionalChangelog {
  constructor(cwdOrGitClient?: string | ConventionalGitClient);
  loadPreset<T>(preset: PresetParams<T>, loader?: PresetModuleLoader): this;
  config(config: Preset | Promise<Preset>): this;
  readPackage(transform?: PackageTransform): this;
  readPackage(path?: string, transform?: PackageTransform): this;
  package(pkg: Record<string, unknown>): this;
  readRepository(): this;
  repository(infoOrGitUrl: string | Partial<HostedGitInfo>): this;
  options(options: Options): this;
  context(context: Context): this;
  tags(params: GetSemverTagsParams): this;
  commits(params: GetCommitsParams, parserOptions?: ParserStreamOptions): this;
  writer(params: WriterOptions): this;
  write(includeDetails?: false): AsyncGenerator<string, void>;
  write(includeDetails: true): AsyncGenerator<Details<Commit>, void>;
  writeStream(includeDetails?: boolean): NodeJS.ReadableStream;
}

Capabilities

CLI Installation and Basic Usage

# Install globally
npm install -g conventional-changelog

# Or use locally
npm install conventional-changelog

# Basic usage with Angular preset
conventional-changelog -p angular

# Generate all previous changelogs (first time setup)
conventional-changelog -p angular -r 0

CLI Command Structure

interface Flags {
  /** Read the CHANGELOG from this file (default: CHANGELOG.md) */
  infile?: string;
  /** Write the CHANGELOG to this file (default: infile) */
  outfile?: string;
  /** Output the result to stdout */
  stdout?: boolean;
  /** Name of the preset you want to use */
  preset?: string;
  /** A filepath of where your package.json is located */
  pkg?: string;
  /** Should the newer release be appended to the older release (default: false) */
  append?: boolean;
  /** How many releases to be generated from the latest (default: 1) */
  releaseCount?: number;
  /** If given, unstable tags will be skipped, e.g., x.x.x-alpha.1, x.x.x-rc.2 */
  skipUnstable?: boolean;
  /** Output unreleased changelog */
  outputUnreleased?: boolean;
  /** Verbose output. Use this for debugging (default: false) */
  verbose?: boolean;
  /** A filepath of your config script */
  config?: string;
  /** A filepath of a json that is used to define template variables */
  context?: string;
  /** Generate the CHANGELOG for the first time */
  firstRelease?: boolean;
  /** Generate a changelog for a specific lerna package */
  lernaPackage?: string;
  /** Tag prefix to consider when reading the tags */
  tagPrefix?: string;
}

/**
 * Main CLI program runner
 * @param generator - ConventionalChangelog instance
 * @param flags - Parsed CLI flags
 */
function runProgram(generator: ConventionalChangelog, flags: Flags): Promise<void>;

Complete CLI Options

Input/Output Options

  • -i, --infile <file> - Input changelog file (default: CHANGELOG.md)
  • -o, --outfile <file> - Output changelog file (default: same as infile)
  • --stdout - Output changelog to stdout instead of file

Examples:

# Read from and write to CHANGELOG.md (default)
conventional-changelog -p angular

# Custom input and output files
conventional-changelog -p angular -i OLD_CHANGELOG.md -o NEW_CHANGELOG.md

# Output to stdout
conventional-changelog -p angular --stdout

Preset and Configuration Options

  • -p, --preset <name> - Preset name (angular, atom, codemirror, ember, eslint, express, jquery, jscs, jshint)
  • -n, --config <file> - Configuration script file path
  • -c, --context <file> - JSON file with template variables
  • -k, --pkg <file> - Package.json file path

Examples:

# Use Angular preset (most common)
conventional-changelog -p angular

# Use custom config file
conventional-changelog -n ./changelog.config.js

# Custom package.json location
conventional-changelog -k ./packages/core/package.json

# Use context file for template variables
conventional-changelog -c ./changelog-context.json

Release and Version Options

  • -r, --release-count <number> - Number of releases to generate (default: 1, 0 = all)
  • -f, --first-release - Generate changelog for first time (equivalent to -r 0)
  • -a, --append - Append newer releases to older ones
  • -u, --output-unreleased - Include unreleased changes
  • --skip-unstable - Skip unstable tags (alpha, beta, rc)

Examples:

# Generate last 3 releases
conventional-changelog -p angular -r 3

# Generate all releases (first time setup)
conventional-changelog -p angular -r 0
# or
conventional-changelog -p angular -f

# Append new releases to bottom of file
conventional-changelog -p angular -a

# Include unreleased changes
conventional-changelog -p angular -u

Repository and Tagging Options

  • -l, --lerna-package <name> - Generate changelog for specific Lerna package
  • -t, --tag-prefix <prefix> - Tag prefix to consider
  • --commit-path <path> - Generate changelog scoped to specific directory

Examples:

# Lerna monorepo - specific package
conventional-changelog -p angular -l my-package

# Custom tag prefix
conventional-changelog -p angular -t "release-"

# Scope to specific directory
conventional-changelog -p angular --commit-path packages/core

Debug and Utility Options

  • -v, --verbose - Verbose output for debugging
  • --help - Show help information
  • --version - Show version information

Examples:

# Enable verbose logging
conventional-changelog -p angular -v

# Show help
conventional-changelog --help

CLI Workflow Examples

Standard Workflow

# 1. Make changes and commit using conventional format
git commit -m "feat: add new feature"
git commit -m "fix: resolve bug in parser"

# 2. Update version in package.json
npm version minor

# 3. Generate changelog
conventional-changelog -p angular -i CHANGELOG.md -o CHANGELOG.md

# 4. Commit changelog and tag
git add CHANGELOG.md
git commit -m "chore: update changelog"
git tag v1.2.0

# 5. Push changes
git push origin main --tags

First-time Setup

# Generate complete changelog history
conventional-changelog -p angular -i CHANGELOG.md -o CHANGELOG.md -r 0

CI/CD Integration

# In build script - generate and validate changelog
conventional-changelog -p angular --stdout > /tmp/changelog.md
if [ -s /tmp/changelog.md ]; then
  echo "Changelog generated successfully"
  cat /tmp/changelog.md >> CHANGELOG.md
else
  echo "No new changes to document"
fi

Monorepo Usage

# Generate changelog for specific package in Lerna monorepo
conventional-changelog -p angular -l @my-org/my-package -i packages/my-package/CHANGELOG.md

# Use package-specific config
conventional-changelog -p angular -k packages/my-package/package.json -n packages/my-package/changelog.config.js

Advanced Configuration Files

Config File Example (changelog.config.js)

module.exports = {
  writer: {
    transform: (commit, context) => {
      // Custom commit transformation
      if (commit.type === 'chore') return null;
      return commit;
    },
    groupBy: 'type',
    commitGroupsSort: 'title',
    commitsSort: ['scope', 'subject']
  },
  parser: {
    noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES']
  }
};

Context File Example (changelog-context.json)

{
  "version": "1.2.0",
  "previousTag": "v1.1.0",
  "currentTag": "v1.2.0",
  "packageData": {
    "name": "my-package"
  },
  "host": "https://github.com",
  "owner": "my-org", 
  "repository": "my-repo"
}

Error Handling and Troubleshooting

Common error scenarios and solutions:

# Verbose mode for debugging
conventional-changelog -p angular -v

# Validate git repository
git log --oneline -10  # Check recent commits
git tag -l             # Check available tags

# Test with stdout first
conventional-changelog -p angular --stdout

docs

cli.md

configuration.md

git-integration.md

index.md

programmatic-api.md

tile.json