Skip to content

Commit

Permalink
chore: refactor commit hook (#3610)
Browse files Browse the repository at this point in the history
* chore: refactor commit hook

* chore(packaging): clean dependencie

* chore(packaging): clean dev dependencie
  • Loading branch information
hsuanxyz authored and vthinkxie committed Jun 20, 2019
1 parent 9522658 commit 1b17110
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 119 deletions.
60 changes: 60 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';
const message = process.env['HUSKY_GIT_PARAMS'];
const fs = require('fs');

const types = [
'build',
"chore",
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
"release",
'revert',
'style',
'test'
];

const scopes = [
"showcase",
"packaging",
"changelog",
"schematics",
"module:*"
];

function parseMessage(message) {
const PATTERN = /^(\w+)(?:\(([^)]+)\))?\: (.+)$/;
const match = PATTERN.exec(message);
if (!match) {
return null;
}
return {
type: match[1] || null,
scope: match[2] || null,
}
}

function getScopesRule() {
const messages = fs.readFileSync(message, {encoding: 'utf-8'});
const parsed = parseMessage(messages.split('\n')[0]);
if (!parsed) {
return [2, 'always', scopes]
}
const { scope, type } = parsed;
if (scope && !scopes.includes(scope) && type !== 'release' && !/module:.+/.test(scope)) {
return [2, 'always', scopes]
} else {
return [2, 'always', []]
}
}

module.exports = {
extends: ['@commitlint/config-angular'],
rules: {
'type-enum': [2, 'always', types],
'scope-enum': getScopesRule
}
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"@angular/pwa": "^0.800.1",
"@angular/router": "~8.0.0",
"@angular/service-worker": "~8.0.0",
"@commitlint/cli": "^8.0.0",
"@commitlint/config-angular": "^8.0.0",
"@nguniversal/module-map-ngfactory-loader": "^7.1.1",
"@schematics/angular": "~8.0.1",
"@stackblitz/sdk": "^1.1.1",
Expand Down Expand Up @@ -123,7 +125,7 @@
},
"husky": {
"hooks": {
"commit-msg": "node ./scripts/git/commit-msg.js -E HUSKY_GIT_PARAMS",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
}
Expand Down
24 changes: 0 additions & 24 deletions scripts/git/commit-message.json

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/git/commit-msg.js

This file was deleted.

73 changes: 0 additions & 73 deletions scripts/git/validate-commit-message.js

This file was deleted.

0 comments on commit 1b17110

Please sign in to comment.