husky-commitlint-commitizen

Conventional Commit 강제하기

Stars
13

Conventional Commit ( )

Conventional Commit

Conventional Commit?

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Conventional Commits . . . features, fixes, breaking changes SemVer(Semantic Version ) .

The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.

Semantic Versioning

MAJOR.MINOR.PATCH     .
1.   API   MAJOR ,
2.        MINOR  
3.        PATCH .
       MAJOR.MINOR.PATCH     .

Semantic Versioning ?

   .                . (  )

In the world of software management there exists a dreaded place called dependency hell. The bigger your system grows and the more packages you integrate into your software, the more likely you are to find yourself, one day, in this pit of despair.

husky + commitlint + commitizen Conventional Commit

husky

git-hook

webpack/webpack angular/angular angular/angular-cli angular/components vercel/hyper blitz-js/blitz facebook/docusaurus typescript-eslint/typescript-eslint 11ty/eleventy stylelint/stylelint rollup/rollup tauri-apps/tauri NativeScript/NativeScript formatjs/formatjs react-bootstrap/react-bootstrap react-dnd/react-dnd react-grid-layout/react-grid-layout snabbdom/snabbdom logaretm/vee-validate zenorocha/clipboard.js NodeBB/NodeBB ant-design/ant-design And more

commitlint

husky commit message

commitizen

commit message

1. husky + commitlint Conventional Commit

a.

npm i -D husky @commitlint/cli @commitlint/config-conventional

b. package.json Life Cycle scripts postinstall npm i

husky       
"script": {
  "postinstall": "husky install"
}

c. root commitlint.config.ts

import type { UserConfig } from '@commitlint/types'

const Configuration: UserConfig = {
  extends: ['@commitlint/config-conventional'],
}

module.exports = Configuration

d. .husky/commit-msg

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit "$1"

2. commitizen

a. package.json scripts commit ( )

"scripts": {
  "commit": "npx cz-customizable"
}

b. root .cz-config.js typeEnum

const typeEnums = {
  feat: '   ',
  fix: '  /  ',
  docs: '    ',
  markup: ' ',
  revert: '  ',
  style: ' ',
  remove: '   ',
  perf: '  ',
  ci: 'CI      ',
  event: ' ',
  config: '  / ',
}

const maxSpaceLength = Object.keys(typeEnums).reduce(
  (acc, { length }) => (length > acc ? length : acc),
  0,
)

const commitizenConfig = {
  types: Object.entries(typeEnums).map(([type, description]) => ({
    value: type,
    name: `${type}:     ${' '.repeat(maxSpaceLength - type.length)}` + description,
  })),
}

module.exports = commitizenConfig

c. .cz-config.js

3. commitlint - commitizen

a. commitlint commitizen typeEnum

import type { UserConfig } from '@commitlint/types'
import commitizenConfig from './.cz-config.js'

const Configuration: UserConfig = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [2, 'always', commitizenConfig.types.map(({ value }) => value)],
    'type-case': [2, 'always', 'lower-case'],
    'scope-empty': [2, 'never'],
  },
}

module.exports = Configuration

GitHub Actions + semantic-release + CI

  • github-actions semantic-release 
    
  • semantic-release semantic-versioning major/minor/patch commit (conventional-commit ) .
  • CI - CD  .
    

Semantic Release

Badges
Extracted from project README
Conventional Commit