Skip to content

Commit 974ebda

Browse files
committed
Merge branch 'master' into greenkeeper-nyc-10.0.0
* master: docs(install): Add documentation for installing and running locally (#300) fix(tests): fix tests when a global config is present (#405) test(adapter): add test for scoped npm modules fix(adapter): add support for scoped adapters docs: Add cz-emoji to tools list (#404) feat(commit): use OS-specific cache dir for commitizen.json instead of home-or-tmp (#400) fix(npmignore): ignore more unnecessary files (#393) docs: add vscode-commitizen to tools list (#397) Ci issues with commits (#402) chore(ci): add node versions and say git version in ci docs: replace sudo mention with link to how to fix EACCES error
2 parents 0aafa6e + ca32961 commit 974ebda

File tree

15 files changed

+285
-172
lines changed

15 files changed

+285
-172
lines changed

.npmignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/meta
22
/src
33
/test
4-
test/tools/trigger-appveyor-tests.sh
4+
test/tools/trigger-appveyor-tests.sh
5+
/coverage
6+
/.travis.yml
7+
/appveyor.yml
8+
jsconfig.json
9+
travis_after_all.py

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ branches:
99
notifications:
1010
email: false
1111
node_js:
12+
- '7'
13+
- '6'
14+
- '5'
1215
- '4'
1316
- '0.12'
1417
before_install:
1518
- git config --global user.name "TravisCI"
19+
- git config --global user.email "commitizen@gmail.com"
1620
- npm i -g npm@^2.0.0
1721
before_script:
1822
- npm prune
23+
- git version
1924
- curl -Lo travis_after_all.py https://git.io/vLSON
2025
script:
2126
- npm run test

CONTRIBUTING.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ to release new versions automatically.
1717

1818
* Commits of type `fix` will trigger bugfix releases, think `0.0.1`
1919
* Commits of type `feat` will trigger feature releases, think `0.1.0`
20-
* Commits with `BREAKING CHANGE` in body or footer will trigger breakgin releases, think `1.0.0`
20+
* Commits with `BREAKING CHANGE` in body or footer will trigger breaking releases, think `1.0.0`
2121

22-
All other commit types wil trigger no new release.
22+
All other commit types will trigger no new release.
23+
24+
## Gotchas
25+
26+
### Atom removes lines with just spaces, breaking tests
27+
28+
When using Atom, if you edit some of our tests, atom will remove the whitespace on some lines. Unfortunately we wanted this whitespace to
29+
able to test multiline commits and their difference across operating
30+
systems. Atom has decided to keep the stripping of whitespace as a
31+
default. Although we understand this decision, it has the unfortunate
32+
side effect of editing parts of the file that you might not have
33+
intended. We think this should be left up to more configurable tools
34+
like eslint.
35+
36+
For now, in order to work around this, you can take the steps outlined
37+
[here](https://github.com/atom/whitespace/issues/10#issuecomment-85183781) to temporarily disable automatic whitespace removal in Atom.

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ When you commit with Commitizen, you'll be prompted to fill out any required com
55
[![codecov.io](https://img.shields.io/codecov/c/github/commitizen/cz-cli.svg?style=flat-square)](https://codecov.io/github/commitizen/cz-cli?branch=master) [![npm monthly downloads](https://img.shields.io/npm/dm/commitizen.svg?style=flat-square)](https://www.npmjs.com/package/commitizen) [![current version](https://img.shields.io/npm/v/commitizen.svg?style=flat-square)](https://www.npmjs.com/package/commitizen) [![bitHound Score](https://www.bithound.io/github/commitizen/cz-cli/badges/score.svg)](https://www.bithound.io/github/commitizen/cz-cli) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
66

77
#### Installing the command line tool
8-
Installation is as simple as running the following command (add sudo if on OSX/Linux):
8+
Installation is as simple as running the following command (if you see `EACCES` error, reading [fixing npm permissions](https://docs.npmjs.com/getting-started/fixing-npm-permissions) may help):
99

1010
```
1111
npm install -g commitizen
@@ -31,7 +31,7 @@ npm install -g commitizen
3131
Install your preferred `commitizen` adapter globally, for example [`cz-conventional-changelog`](https://www.npmjs.com/package/cz-conventional-changelog)
3232

3333
```
34-
npm i -g cz-conventional-changelog
34+
npm install -g cz-conventional-changelog
3535
```
3636

3737
Create a `.czrc` file in your `home` directory, with `path` referring to the preferred, globally installed, `commitizen` adapter
@@ -92,6 +92,27 @@ This just tells Commitizen which adapter we actually want our contributors to us
9292

9393
Please note that in previous version of Commitizen we used czConfig. **czConfig has been deprecated** and you should migrate to the new format before Commitizen 3.0.0.
9494

95+
#### Optional: Install and run Commitizen locally
96+
97+
Installing and running Commitizen locally allows you to make sure that developers are running the exact same version of Commitizen on every machine.
98+
99+
Install Commitizen with `npm install --save-dev commitizen`.
100+
101+
Once you have Commitizen installed as a local dev dependency you can execute `./node_modules/.bin/commitizen` or `./node_modules/.bin/git-cz` in order to actually use the commands.
102+
103+
You can then initialize the conventional changelog adapter using: `./node_modules/.bin/commitizen init cz-conventional-changelog --save-dev --save-exact`
104+
105+
And you can then add some nice npm run scripts in your package.json pointing to the local version of commitizen:
106+
107+
```json
108+
...
109+
"scripts": {
110+
"commit": "git-cz"
111+
}
112+
```
113+
114+
This will be more convenient for your users because then if they want to do a commit, all they need to do is run `npm run commit` and they will get the prompts needed to start a commit!
115+
95116
#### Congratulations your repo is Commitizen-friendly. Time to flaunt it!
96117

97118
Add the Commitizen-friendly badge to your README using the following markdown:
@@ -181,6 +202,8 @@ We know that every project and build process has different requirements so we've
181202
- [cz-mapbox-changelog](https://www.npmjs.com/package/cz-mapbox-changelog)
182203
- [cz-customizable](https://github.com/leonardoanalista/cz-customizable)
183204
- [cz-conventional-changelog-lint](https://github.com/marionebl/cz-conventional-changelog-lint)
205+
- [vscode-commitizen](https://github.com/KnisterPeter/vscode-commitizen)
206+
- [cz-emoji](https://github.com/ngryman/cz-emoji)
184207

185208
To create an adapter, just fork one of these great adapters and modify it to suit your needs. We pass you an instance of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) but you can capture input using whatever means necessary. Just call the `commit` callback with a string and we'll be happy. Publish it to npm, and you'll be all set!
186209

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"build:watch": "babel --watch src --out-dir dist",
1111
"prepublish": "not-in-install && npm run build || true",
1212
"report-coverage": "nyc report --reporter=lcov | codecov",
13+
"write-coverage": "nyc report --reporter=lcov",
1314
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
1415
"start": "npm run test:watch",
1516
"test": "nyc --require babel-core/register _mocha -- test/tests/index.js",
@@ -60,20 +61,20 @@
6061
"nodemon": "1.11.0",
6162
"nyc": "10.0.0",
6263
"proxyquire": "1.7.10",
63-
"rimraf": "2.5.4",
6464
"semantic-release": "4.3.5",
6565
"semver": "5.3.0",
6666
"sinon": "1.17.6"
6767
},
6868
"dependencies": {
69+
"cachedir": "^1.1.0",
6970
"chalk": "1.1.3",
7071
"cz-conventional-changelog": "1.2.0",
7172
"dedent": "0.6.0",
7273
"detect-indent": "4.0.0",
7374
"find-node-modules": "1.0.3",
7475
"find-root": "1.0.0",
76+
"fs-extra": "^1.0.0",
7577
"glob": "7.1.1",
76-
"home-or-tmp": "2.0.0",
7778
"inquirer": "1.2.2",
7879
"lodash": "4.16.3",
7980
"minimist": "1.2.0",

src/commitizen/adapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function getPrompter(adapterPath) {
128128
function resolveAdapterPath(inboundAdapterPath) {
129129
// Check if inboundAdapterPath is a path or node module name
130130
let parsed = path.parse(inboundAdapterPath);
131-
let isPath = parsed.dir.length > 0;
131+
let isPath = parsed.dir.length > 0 && parsed.dir.charAt(0) !== "@";
132132

133133
// Resolve from the root of the git repo if inboundAdapterPath is a path
134134
let absoluteAdapterPath = isPath ?

src/commitizen/commit.js

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import path from 'path';
22

3-
import homeOrTmp from 'home-or-tmp';
43
import dedent from 'dedent';
4+
import cacheDir from 'cachedir';
5+
import {ensureDir} from 'fs-extra';
56
import {commit as gitCommit, log} from '../git';
67
import * as cache from './cache';
78

@@ -21,41 +22,48 @@ function dispatchGitCommit(sh, repoPath, template, options, overrideOptions, don
2122
* Asynchronously commits files using commitizen
2223
*/
2324
function commit(sh, inquirer, repoPath, prompter, options, done) {
24-
25-
var cachePath = path.join(homeOrTmp, 'commitizen.json');
26-
27-
if(options.retryLastCommit) {
28-
29-
console.log('Retrying last commit attempt.');
30-
31-
// We want to use the last commit instead of the current commit,
32-
// so lets override some options using the values from cache.
33-
let {
34-
options: retryOptions,
35-
overrideOptions: retryOverrideOptions,
36-
template: retryTemplate
37-
} = cache.getCacheValueSync(cachePath, repoPath);
38-
dispatchGitCommit(sh, repoPath, retryTemplate, retryOptions, retryOverrideOptions, done);
39-
40-
} else {
41-
// Get user input -- side effect that is hard to test
42-
prompter(inquirer, function(error, template, overrideOptions) {
43-
// Allow adapters to error out
44-
// (error: Error?, template: String, overrideOptions: Object)
45-
if (!(error instanceof Error)) {
46-
overrideOptions = template;
47-
template = error;
48-
error = null;
49-
}
25+
var cacheDirectory = cacheDir('commitizen');
26+
var cachePath = path.join(cacheDirectory, 'commitizen.json');
5027

51-
if (error) {
52-
return done(error);
53-
}
28+
ensureDir(cacheDirectory, function(error) {
29+
if (error) {
30+
console.error("Couldn't create commitizen cache directory: ", error);
31+
// TODO: properly handle error?
32+
} else {
33+
if(options.retryLastCommit) {
5434

55-
// We don't want to add retries to the cache, only actual commands
56-
cache.setCacheValueSync(cachePath, repoPath, { template, options, overrideOptions });
57-
dispatchGitCommit(sh, repoPath, template, options, overrideOptions, done);
58-
});
59-
}
35+
console.log('Retrying last commit attempt.');
36+
37+
// We want to use the last commit instead of the current commit,
38+
// so lets override some options using the values from cache.
39+
let {
40+
options: retryOptions,
41+
overrideOptions: retryOverrideOptions,
42+
template: retryTemplate
43+
} = cache.getCacheValueSync(cachePath, repoPath);
44+
dispatchGitCommit(sh, repoPath, retryTemplate, retryOptions, retryOverrideOptions, done);
45+
46+
} else {
47+
// Get user input -- side effect that is hard to test
48+
prompter(inquirer, function(error, template, overrideOptions) {
49+
// Allow adapters to error out
50+
// (error: Error?, template: String, overrideOptions: Object)
51+
if (!(error instanceof Error)) {
52+
overrideOptions = template;
53+
template = error;
54+
error = null;
55+
}
56+
57+
if (error) {
58+
return done(error);
59+
}
60+
61+
// We don't want to add retries to the cache, only actual commands
62+
cache.setCacheValueSync(cachePath, repoPath, { template, options, overrideOptions });
63+
dispatchGitCommit(sh, repoPath, template, options, overrideOptions, done);
64+
});
65+
}
66+
}
67+
});
6068

6169
}

src/common/util.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export {
77
getParsedPackageJsonFromPath,
88
isArray,
99
isFunction,
10-
isString
10+
isString,
11+
isInTest
1112
}
1213

1314
/**
@@ -80,3 +81,7 @@ function isString(str) {
8081
return Object.prototype.toString.call(str) == '[object String]';
8182
}
8283
}
84+
85+
function isInTest() {
86+
return typeof global.it === 'function';
87+
}

src/configLoader/loader.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import path from 'path';
22

33
import {findup, getContent} from '../configLoader';
4+
import {isInTest} from '../common/util.js';
45

56
export default loader;
67

78
/**
89
* Command line config helpers
9-
* Shamelessly ripped from with slight modifications:
10+
* Shamelessly ripped from with slight modifications:
1011
* https://github.com/jscs-dev/node-jscs/blob/master/lib/cli-config.js
1112
*/
1213

@@ -27,7 +28,7 @@ function loader(configs, config, cwd) {
2728

2829
content = getContent(
2930
findup(configs, { nocase: true, cwd: directory }, function(configPath) {
30-
if (path.basename(configPath) === 'package.json') {
31+
if (path.basename(configPath) === 'package.json') {
3132
// return !!this.getContent(configPath);
3233
}
3334

@@ -38,20 +39,22 @@ function loader(configs, config, cwd) {
3839
if (content) {
3940
return content;
4041
}
41-
42-
// Try to load standard configs from home dir
43-
var directoryArr = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME];
44-
for (var i = 0, dirLen = directoryArr.length; i < dirLen; i++) {
45-
if (!directoryArr[i]) {
46-
continue;
47-
}
48-
49-
for (var j = 0, len = configs.length; j < len; j++) {
50-
content = getContent(configs[j], directoryArr[i]);
51-
52-
if (content) {
53-
return content;
54-
}
55-
}
42+
/* istanbul ignore if */
43+
if(!isInTest()) {
44+
// Try to load standard configs from home dir
45+
var directoryArr = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME];
46+
for (var i = 0, dirLen = directoryArr.length; i < dirLen; i++) {
47+
if (!directoryArr[i]) {
48+
continue;
49+
}
50+
51+
for (var j = 0, len = configs.length; j < len; j++) {
52+
content = getContent(configs[j], directoryArr[i]);
53+
54+
if (content) {
55+
return content;
56+
}
57+
}
58+
}
5659
}
57-
}
60+
}

src/git/log.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {exec} from 'child_process';
1+
import { exec } from 'child_process';
22

33
export { log };
44

@@ -11,6 +11,7 @@ function log(repoPath, done) {
1111
cwd: repoPath
1212
}, function(error, stdout, stderr) {
1313
if (error) {
14+
throw error;
1415
done();
1516
}
1617
done(stdout);

0 commit comments

Comments
 (0)