Skip to content

Commit 78b1ea1

Browse files
bcabanesvsavkin
authored andcommitted
chore(commitizen): add cz-conventional-changelog
This adds the ability to automate the format of the commit by prompting the information needed in sequence. It is then easier to follow the standard format of the repository. A commit check has been added to the CI too.
1 parent fce682c commit 78b1ea1

File tree

6 files changed

+414
-23
lines changed

6 files changed

+414
-23
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ install:
99
- sh -e /etc/init.d/xvfb start
1010
- yarn install
1111
script:
12-
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then yarn checkformat --head=$TRAVIS_PULL_REQUEST_SHA --base=$(git merge-base HEAD $TRAVIS_BRANCH); fi'
1312
- yarn test
1413
- yarn e2e
14+
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then yarn checkformat --head=$TRAVIS_PULL_REQUEST_SHA --base=$(git merge-base HEAD $TRAVIS_BRANCH); fi'
15+
- yarn checkcommit
1516
addons:
1617
chrome: stable
1718
cache:

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ feat(schematics): add an option to generate lazy-loadable modules
8080
`ng generate lib mylib --lazy` provisions the mylib project in tslint.json
8181
```
8282

83+
#### Commitizen
84+
85+
To simplify and automate the process of commiting with this format,
86+
**Nx is a [Commitizen](https://github.com/commitizen/cz-cli) friendly repository**, just do `git add` and execute `yarn commit`.
87+
8388
## Migrations
8489

8590
Nx allows users to automatically upgrade to the newest version of the package. If you are introducing a change that would require the users to upgrade their workspace, add a migration to `packages/schematics/migrations`.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![NPM Version](https://badge.fury.io/js/%40nrwl%2Fnx.svg)](https://www.npmjs.com/@nrwl/nx)
99
[![NPM Downloads](https://img.shields.io/npm/dt/@nrwl/schematics.svg?style=flat-square)](https://www.npmjs.com/@nrwl/nx)
1010
[![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
11+
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
1112

1213
</p>
1314

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"private": true,
77
"scripts": {
88
"build": "./scripts/build.sh",
9+
"commit": "git-cz",
10+
"checkcommit": "./scripts/commit-lint.js",
911
"e2e": "./scripts/e2e.sh",
1012
"format": "prettier \"{packages,e2e}/**/*.ts\" --write",
1113
"linknpm": "./scripts/link.sh",
@@ -42,8 +44,10 @@
4244
"@types/yargs": "^11.0.0",
4345
"angular": "1.6.6",
4446
"app-root-path": "^2.0.1",
47+
"commitizen": "^2.10.1",
4548
"conventional-changelog-cli": "^1.3.21",
4649
"cosmiconfig": "^4.0.0",
50+
"cz-conventional-changelog": "^2.1.0",
4751
"fs-extra": "5.0.0",
4852
"graphviz": "^0.0.8",
4953
"husky": "^0.14.3",
@@ -80,5 +84,10 @@
8084
"tmp",
8185
"collection/.*/files"
8286
]
87+
},
88+
"config": {
89+
"commitizen": {
90+
"path": "./node_modules/cz-conventional-changelog"
91+
}
8392
}
8493
}

scripts/commit-lint.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
3+
console.log('🐟🐟🐟 Validating git commit message 🐟🐟🐟');
4+
const gitMessage = require('child_process')
5+
.execSync('git log -1 --no-merges')
6+
.toString()
7+
.trim();
8+
const matchTest = /([a-z]){0,8}\([a-z.0-9]+\):\s(([a-z0-9:\-\s])+)/g.test(
9+
gitMessage
10+
);
11+
const exitCode = +!matchTest;
12+
13+
if (exitCode === 0) {
14+
console.log('Commit ACCEPTED 👌');
15+
} else {
16+
console.log(
17+
'[Error]: Ho no! 😦 Your commit message: \n' +
18+
gitMessage +
19+
'\ndoes not follow the commit message convention specified in the CONTRIBUTING.MD file.'
20+
);
21+
console.log('\ntype(scope): subject \n BLANK LINE \n body');
22+
console.log(
23+
'\nExample: \n ' +
24+
'feat(schematics): add an option to generate lazy-loadable modules\n' +
25+
'\n`ng generate lib mylib --lazy` provisions the mylib project in tslint.json'
26+
);
27+
}
28+
process.exit(exitCode);

0 commit comments

Comments
 (0)