Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mfrancois3k/5acef64b2656e09124ab4ea649e3a0d3 to your computer and use it in GitHub Desktop.
Save mfrancois3k/5acef64b2656e09124ab4ea649e3a0d3 to your computer and use it in GitHub Desktop.
Husky How to generate automatic helpful fancy changelog

How to generate automatic helpful fancy changelog

This howto will setup your project with automatic changelog generation, based on your commit messages.

Setup git hooks with husky

  1. Install husky
    yarn add -D husky
  2. Enable git hooks
    npx husky install
  3. Add this to your package.json
    "scripts": {
        "prepare": "husky install"
    }

Commitlint

To enforce your commits to follow the Conventional Commits Specification we will use @commitlint/config-conventional and force it via a git hook.

  1. Install commitlint
    yarn add -D @commitlint/{cli,config-conventional}
  2. Add commit-msg git hook via husky
    npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'
  3. Create a .commitlintrc.json file which extends the rules from config-conventional
    {
        "extends": ["@commitlint/config-conventional"]
    }

Generate Changelog

Finally, standard-version will read your commits to generate a changelog

  1. Install
    yarn add -D standard-version
  2. Add some scripts to your package.json
    "scripts": {
        "release": "standard-version $1",
        "release:minor": "standard-version --release-as minor",
        "release:patch": "standard-version --release-as patch",
        "release:major": "standard-version --release-as major"
    }
    ℹ️ More informations about available commands on standard-version's doc
  3. Add and adapt the standard-version configuration into your package.json
    "standard-version": {
        "types": [
            {
                "type": "feat",
                "section": "Features"
            },
            {
                "type": "fix",
                "section": "Bug Fixes"
            },
            {
                "type": "chore",
                "section": "Chore changes:"
            },
            {
                "type": "docs",
                "section": "Documentation changes:"
            },
            {
                "type": "style",
                "hidden": true
            },
            {
                "type": "refactor",
                "section": "Refactors:"
            },
            {
                "type": "perf",
                "hidden": true
            },
            {
                "type": "test",
                "section": "Tests"
            }
        ]
    }

Emoji 🚀

Add a fancy touch to your commits with devmoji, it will automatically add emojis to your commits.

  1. Install devmoji
    yarn add -D devmoji
  2. Add git hook for devmoji
    npx husky add .husky/prepare-commit-msg "npx devmoji -e --lint"
    npx husky install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment