Introduction to Conventional Changelog CLI for Automated Versioning and Release Notes

Conventional Changelog CLI: Revolutionize Your Versioning and Release Notes

The conventional-changelog-cli is a powerful tool that automates the process of generating changelogs and maintaining semantic versioning in your projects. By following conventional commit messages, you can effortlessly keep your project documentation up-to-date and consistent.

Getting Started

To begin with conventional-changelog-cli, you need to install it globally using npm:

npm install -g conventional-changelog-cli

Basic Commands

Here are some basic commands you can use with conventional-changelog-cli:

  • conventional-changelog -p angular -i CHANGELOG.md -s – Generate a changelog using the Angular preset and save it to CHANGELOG.md.
  • conventional-changelog -i CHANGELOG.md -s – Update the existing CHANGELOG.md file.
  • conventional-changelog -r 0 – Regenerate the entire changelog from scratch.

Creating Custom Presets

You can create custom presets to tailor the output of the changelog to your needs:


  module.exports = {
    writerOpts: {
      transform: (commit, context) => {
        let discard = true;
        const issues = [];

        commit.notes.forEach((note) => {
          note.title = 'BREAKING CHANGES';
          discard = false;
        });

        if (commit.type === 'feat') {
          commit.type = 'Features';
        } else if (commit.type === 'fix') {
          commit.type = 'Bug Fixes';
        } else if (commit.type === 'perf') {
          commit.type = 'Performance Improvements';
        } else if (commit.type === 'revert') {
          commit.type = 'Reverts';
        } else {
          return;
        }

        if (commit.scope === '*') {
          commit.scope = '';
        }

        if (typeof commit.hash === 'string') {
          commit.hash = commit.hash.substring(0, 7);
        }

        if (typeof commit.subject === 'string') {
          commit.subject = commit.subject.substring(0, 80);
        }

        return commit;
      },
    },
  };

Advanced API Usage

Here are some examples to showcase advanced usage of the API:

Commitlint Configuration

Integrate commitlint with conventional-changelog-cli to enforce commit message conventions:


  // commitlint.config.js
  module.exports = {
    extends: ['@commitlint/config-conventional'],
  };

Connect commitlint with your version control system (e.g., Git) to lint commit messages:


  // package.json
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }

Conventional Changelog with Shell Scripts

Automate your release process by using shell scripts:


  #!/bin/bash
  git checkout main
  git pull origin main
  npm version patch
  conventional-changelog -p angular -i CHANGELOG.md -s
  git add CHANGELOG.md
  git commit -m "docs(CHANGELOG): update changelog"
  git push origin main --follow-tags

Example Application

Here is an example of an application integrating the conventional-changelog-cli:


  // index.js
  const fs = require('fs');
  const changelog = require('conventional-changelog');

  changelog({
    preset: 'angular',
  })
  .pipe(fs.createWriteStream('CHANGELOG.md'))
  .on('close', () => {
    console.log('Changelog generated successfully!');
  });

In this example, we use the conventional-changelog library to generate a changelog based on Angular conventions and save it to a CHANGELOG.md file.

With conventional-changelog-cli, automating your versioning and release notes has never been easier. Explore the powerful features and streamline your project’s documentation today!

Hash: 1e25d3d5347bdcf914e1504017a30af7ab49eba19c8c264ad5f3fcccd85c7d90

Leave a Reply

Your email address will not be published. Required fields are marked *