diff --git a/build/lint-commit-msg.js b/build/lint-commit-msg.js new file mode 100644 index 000000000..70d2b2961 --- /dev/null +++ b/build/lint-commit-msg.js @@ -0,0 +1,34 @@ +const fs = require('fs'); +const signale = require('signale'); + +const gitParams = process.env.HUSKY_GIT_PARAMS; +const commitMsg = fs.readFileSync(gitParams, 'utf-8').trim(); + +const commitRE = /^(revert: )?\[(fix|feat|docs|perf|test|types|build|chore|refactor|breaking change)\].{1,50}/; + +if (!commitRE.test(commitMsg)) { + signale.error(`Error: invalid commit message format. + +Proper commit message format is required for automated changelog generation. + +Examples: + +[fix] Button: incorrect style +[feat] Button: add color prop +[dosc] Button: fix typo + +Allowed Types: + +- fix +- feat +- docs +- perf +- test +- types +- build +- chore +- refactor +- breaking change +`); + process.exit(1); +} diff --git a/package.json b/package.json index 560d1f8dc..f0367bc46 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ }, "husky": { "hooks": { - "pre-commit": "lint-staged" + "pre-commit": "lint-staged", + "commit-msg": "node build/lint-commit-msg.js" } }, "lint-staged": {