purpose

Git commit message normalization is intended to automatically generate Changelog. The purpose of automatically generating Changelog is to let you and others know what changes have been made (which features have been added or removed, and which bugs have been fixed) with each release update.

Dependency package Installation

npm install --save-dev git-cz husky commitlint @commitlint/config-conventional standard-version
Copy the code

Generate/change relevant configuration files

Run the following command to generate the husky command folder: husky

git init 
npx husky install
Copy the code

Create a new commit- MSG file in the.husky folder

#! /bin/sh . "$(dirname "$0")/_/husky.sh" npx --no-install commitlint --edit "$1"Copy the code

The changelog.config.js configuration file is added as follows:

module.exports = {
  disableEmoji: false.format: '{type}{scope}: {emoji}{subject}'.list: [
    'test'.'feat'.'fix'.'chore'.'docs'.'refactor'.'style'.'ci'.'perf',].maxMessageLength: 64.minMessageLength: 3.questions: [
    'type'.'scope'.'subject'.'body'.'breaking'.'issues'.'lerna',].scopes: [].types: {
    chore: {
      description: 'Build process or assistive tool changes'.emoji: '🤖'.value: 'chore',},ci: {
      description: 'CI related Changes'.emoji: '🎡'.value: 'ci',},docs: {
      description: 'Only modified document'.emoji: '✏ ️'.value: 'docs',},feat: {
      description: 'A new feature'.emoji: '🎸'.value: 'feat',},fix: {
      description: 'Troubleshooting'.emoji: '🐛'.value: 'fix',},perf: {
      description: 'Code changes to Improve performance'.emoji: '⚡ ️'.value: 'perf',},refactor: {
      description: 'Code changes that neither fix bugs nor add new features'.emoji: '💡'.value: 'refactor',},release: {
      description: 'Create publish Commit'.emoji: '🏹'.value: 'release',},style: {
      description: 'Just code format/style changes'.emoji: '💄'.value: 'style',},test: {
      description: 'Add Missing Tests'.emoji: '💍'.value: 'test',,}}}Copy the code

Modify the package. The json

{..."scripts": {
        "git-commit": "git-cz"
    },
    "config": {
      "commitizen": {
        "path": "git-cz"}}... }Copy the code

Git-commit This command replaces the original Git commit and allows users to fill in standardized messages according to the template

At this point, you can do a Git commit to test whether the commit message has been validated

The. Versionrc.js configuration file (used to automatically generate changlog) is added. The content of the file is as follows:

module.exports = {
    "types": [{"type": "feat"."section": "✨ the Features | new feature" },
      { "type": "fix"."section": "🐛 Bug Fixes | Bug Fixes." " },
      { "type": "init"."section": "🎉 Init | initialized." " },
      { "type": "docs"."section": "✏ ️ Documentation | document" },
      { "type": "style"."section": "💄 Styles | style" },
      { "type": "refactor"."section": "♻ ️ Code Refactoring | Code Refactoring" },
      { "type": "perf"."section": "⚡ Performance Improvements | Performance optimization" },
      { "type": "test"."section": "✅ Tests | testing" },
      { "type": "revert"."section": "⏪ Revert | back"."hidden": true },
      { "type": "build"."section": "📦 ‍ Build System | pack to Build" },
      { "type": "chore"."section": "🚀 Chore | build/engineering/tool to" },
      { "type": "ci"."section": "👷 Continuous Integration | CI configuration"}}]Copy the code

Modify the package. The json

{..."scripts": {
        "release": "standard-version"."release-major": "standard-version --release-as major"."release-minor": "standard-version --release-as minor"."release-patch": "standard-version --release-as patch",}... }Copy the code

Command description:

  • release: in accordance with thestandard-versionDefault rule Upgrade version number
  • release-major: Updates the major version
  • release-patch: Upgrade the patch version

Version of the form

The version number major. Minor. Patch

If you want to skip changelog generation

All configurable skips are: Bump, Changelog, Commit, tag

Modify the package. The json

{..."standard-version": { "skip": { "changelog": true}}... }Copy the code

Final Changelog effect

The resources

Use standard – version

Commit Specifications + CommitLint +CHANGELOG Automatically generate one – train services