Skip to content

Commit e6b75cb

Browse files
authoredSep 25, 2020
feat!: use cz-conventional-changelog as default adapter (#778)
1 parent a97e808 commit e6b75cb

File tree

5 files changed

+103
-97
lines changed

5 files changed

+103
-97
lines changed
 

‎README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ When you're working in a Commitizen friendly repository, you'll be prompted to f
4343

4444
[![Add and commit with Commitizen](https://github.com/commitizen/cz-cli/raw/master/meta/screenshots/add-commit.png)](https://github.com/commitizen/cz-cli/raw/master/meta/screenshots/add-commit.png)
4545

46-
### If your repo is NOT Commitizen friendly:
46+
### If your repo is NOT Commitizen-friendly
4747

48-
If you're **not** working in a Commitizen friendly repository, then `git cz` will work just the same as `git commit` but `npx cz` will use the [streamich/git-cz](https://github.com/streamich/git-cz) adapter. To fix this, you need to first [make your repo Commitizen-friendly](#making-your-repo-commitizen-friendly)
48+
If you're **not** working in a Commitizen friendly repository, then `git cz` will work just the same as `git commit` but `npx cz` will use the [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog) adapter. To fix this, you need to first [make your repo Commitizen-friendly](#making-your-repo-commitizen-friendly).
4949

5050
## Making your repo Commitizen-friendly
5151

52-
For this example, we'll be setting up our repo to use [AngularJS's commit message convention](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) also known as [conventional-changelog](https://github.com/ajoslin/conventional-changelog).
52+
For this example, we'll be setting up our repo to use [Conventional Commits convention](https://www.conventionalcommits.org/) through the [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) [commitizen adapter](https://github.com/commitizen/cz-conventional-changelog).
5353

5454
First, install the Commitizen cli tools:
5555

@@ -86,7 +86,7 @@ The above command does three things for you.
8686
}
8787
```
8888

89-
Alternatively, commitizen configs may be added to a .czrc file:
89+
Alternatively, commitizen configs may be added to a `.czrc` or `.cz.json` file:
9090

9191
```json
9292
{

‎package-lock.json

+90-77
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"dependencies": {
7676
"cachedir": "2.2.0",
77-
"cz-conventional-changelog": "3.2.0",
77+
"cz-conventional-changelog": "3.3.0",
7878
"dedent": "0.7.0",
7979
"detect-indent": "6.0.0",
8080
"find-node-modules": "2.0.0",

‎src/cli/git-cz.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { configLoader } from '../commitizen';
2-
import { git as useGitStrategy, gitCz as useGitCzStrategy } from './strategies';
2+
import { gitCz as useGitCzStrategy } from './strategies';
33

44
export {
55
bootstrap
@@ -9,19 +9,12 @@ export {
99
* This is the main cli entry point.
1010
* environment may be used for debugging.
1111
*/
12-
function bootstrap (environment = {}, argv = process.argv) {
12+
function bootstrap(environment = {}, argv = process.argv) {
1313

1414
// Get cli args
1515
let rawGitArgs = argv.slice(2, argv.length);
1616

17-
let adapterConfig = environment.config || configLoader.load();
17+
let adapterConfig = environment.config || configLoader.load() || { path: 'cz-conventional-changelog' };
1818

19-
// Choose a strategy based on the existance the adapter config
20-
if (typeof adapterConfig !== 'undefined') {
21-
// This tells commitizen we're in business
22-
useGitCzStrategy(rawGitArgs, environment, adapterConfig);
23-
} else {
24-
// This tells commitizen that it is not needed, just use git
25-
useGitStrategy(rawGitArgs, environment);
26-
}
19+
useGitCzStrategy(rawGitArgs, environment, adapterConfig);
2720
}

‎test/tests/cli.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ describe('git-cz', () => {
88

99
beforeEach(() => {
1010
fakeStrategies = {
11-
git: sinon.spy(),
1211
gitCz: sinon.spy()
1312
}
1413

@@ -49,17 +48,18 @@ describe('git-cz', () => {
4948
});
5049

5150
describe('and the config is not returned from configLoader.load', () => {
52-
it('tells commitizen to use the git strategy', () => {
51+
it('tells commitizen to use the default adapter', () => {
5352
bootstrap({});
54-
expect(fakeStrategies.git.called).to.equal(true);
53+
54+
expect(fakeStrategies.gitCz.args[0][2].path).to.equal('cz-conventional-changelog');
5555
});
5656
});
5757
});
5858

5959
describe('when argv is overridden', () => {
6060
it('uses the overridden argv', () => {
6161
bootstrap({}, ['node', 'git-cz', 'index.js']);
62-
expect(fakeStrategies.git.args[0][0][0]).to.equal('index.js');
62+
expect(fakeStrategies.gitCz.args[0][0][0]).to.equal('index.js');
6363
});
6464
})
6565
});

0 commit comments

Comments
 (0)
Please sign in to comment.