Skip to content

Commit 89a072c

Browse files
committed
refactor(cli): Completely rewrite commitizen
In this release, commitizen was completely rewritten to clean up the code base, add tests, and fix several long outstanding bugs. Additionally, there is additional functionality that has been added to attempt to polish the user experience and address certain important edge cases. Closes #25, closes #16, closes #13, closes #12, closes #7, closes commitizen/cz-conventional-changelog#8, closes commitizen/cz-conventional-changelog#9
1 parent 0be1657 commit 89a072c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1446
-216
lines changed

.cz.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
1-
# Logs
2-
logs
3-
*.log
4-
5-
# Runtime data
6-
pids
7-
*.pid
8-
*.seed
9-
10-
# Directory for instrumented libs generated by jscoverage/JSCover
11-
lib-cov
12-
13-
# Coverage directory used by tools like istanbul
14-
coverage
15-
16-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17-
.grunt
18-
19-
# node-waf configuration
20-
.lock-wscript
21-
22-
# Compiled binary addons (http://nodejs.org/api/addons.html)
23-
build/Release
24-
25-
# Dependency directory
26-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27-
node_modules
1+
node_modules/
2+
.tmp/
3+
artifacts/
4+
npm-debug.log

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,21 @@ As a project maintainer, making your repo Commitizen friendly allows you to sele
2424

2525
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/CONTRIBUTING.md#-git-commit-guidelines) also known as [conventional-changelog](https://github.com/ajoslin/conventional-changelog).
2626

27-
First, install the Commitizen conventional-changelog adapter into your project.
27+
First, install the Commitizen cli tools:
2828

2929
```
30-
npm install cz-conventional-changelog
30+
npm install commitizen -g
3131
```
3232

33-
Then just add **.cz.json** to the root of your repository with the following contents:
33+
Next, initialize your project to use the cz-conventional-changelog adapter by typing:
3434

35-
```json
36-
{
37-
"path": "node_modules/cz-conventional-changelog/"
38-
}
35+
```
36+
commitizen init cz-conventional-changelog --save --save-exact
3937
```
4038

41-
This just tells Commitizen which adapter we actually want our contributors to use when they try to commit to this repo.
39+
Note that if you want to force install over the top of an old adapter, you can apply the `--force` argument. For more information on this, just run `commitizen help`.
4240

43-
Alternatively, you can skip adding an additional dot file to your root directory by making **.cz.json** a part of **package.json**... just add the `czConfig` field:
41+
Then just add the `czConfig` field to the root of your **package.json** with the following contents:
4442

4543
```json
4644
...
@@ -49,6 +47,8 @@ Alternatively, you can skip adding an additional dot file to your root directory
4947
}
5048
```
5149

50+
This just tells Commitizen which adapter we actually want our contributors to use when they try to commit to this repo.
51+
5252
#### Congratulations your repo is Commitizen-friendly. Time to flaunt it!
5353

5454
Add the Commitizen-friendly badge to your README using the following markdown:
@@ -73,4 +73,10 @@ Both! Commitizen is not meant to be a replacement for git commit hooks. Rather,
7373
We accomplish this by letting you define which adapter you'd like to use in your project. Adapters just allow multiple projects to share the same commit message conventions. A good example of an adapter is the cz-conventional-commit adapter.
7474

7575
### Authors and Contributors
76-
Jim Cummins (@JimTheDev)
76+
@JimTheDev (Jim Cummins, author)
77+
@kentcdodds
78+
@accraze
79+
@kytwb
80+
@Den-dp
81+
82+
Special thanks to @stevelacy, whose [gulp-git](https://www.npmjs.com/package/gulp-git) project makes commitizen possible.

bin/commitizen

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
3+
require("babel/register");
4+
require('../src/cli/commitizen.js').bootstrap();
File renamed without changes.

bin/git-cz

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/usr/bin/env node
22

3-
var app = require('../src/app.js');
4-
app.bootstrap();
5-
6-
// PRIORITY HIGH
7-
// TODO: Tests
8-
// TODO: Examples
9-
10-
// PRIORITY MEDIUM
11-
// TODO: 3. Allow users to use their original messages using
12-
// some kind of template {{m1}} {{m2}} so that they
13-
// aren't lost.
3+
require("babel/register");
4+
var path = require('path');
5+
require('../src/cli/git-cz.js').bootstrap({
6+
cliPath: path.join(__dirname, '../')
7+
});

bin/git-cz-debug

Lines changed: 0 additions & 6 deletions
This file was deleted.

bin/git-cz.cmd

100755100644
File mode changed.

common/util.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
export {
5+
executeShellCommand,
6+
getParsedJsonFromFile,
7+
getParsedPackageJsonFromPath,
8+
isArray,
9+
isFunction,
10+
isString
11+
}
12+
13+
/**
14+
* Executes the command passed to it at the path requested
15+
* using the instance of shelljs passed in
16+
*/
17+
function executeShellCommand(sh, path, installCommand) {
18+
sh.cd(path);
19+
sh.exec(installCommand);
20+
}
21+
22+
/**
23+
* Gets the parsed contents of a json file
24+
*/
25+
function getParsedJsonFromFile(filePath, fileName, encoding = 'utf8') {
26+
try {
27+
var packageJsonContents = fs.readFileSync(path.join(filePath, fileName), encoding);
28+
return JSON.parse(packageJsonContents);
29+
} catch (e) {
30+
console.error(e);
31+
}
32+
}
33+
34+
/**
35+
* A helper method for getting the contents of package.json at a given path
36+
*/
37+
function getParsedPackageJsonFromPath(path) {
38+
return getParsedJsonFromFile(path, 'package.json');
39+
}
40+
41+
/**
42+
* Test if the passed argument is an array
43+
*/
44+
function isArray(arr) {
45+
return arr.constructor === Array;
46+
}
47+
48+
/**
49+
* Test if the passed argument is a function
50+
*/
51+
function isFunction(functionToCheck) {
52+
var getType = {};
53+
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
54+
}
55+
56+
/**
57+
* Test if the passed argument is a string
58+
*/
59+
function isString(str) {
60+
return Object.prototype.toString.call(str) == '[object String]';
61+
}
62+

0 commit comments

Comments
 (0)