Skip to content

Commit

Permalink
feat(config): use find-config package to locate config
Browse files Browse the repository at this point in the history
There is no need in creating symlink with postinstall script so it was removed.
Getting started instruction provides command to get config template.

closes #10
  • Loading branch information
Guria committed Jan 11, 2016
1 parent baf473d commit c3dfe81
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 59 deletions.
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a customizable Commitizen plugin. You can specify the commit types, scop


## Steps:
- install commitizen case you don't have it: `npm install -g commitizen`
- install commitizen in case you don't have it: `npm install -g commitizen`
- install the cz-customizable: `npm install cz-customizable --save-dev`
- configure `commitizen` to use `cz-customizable` as plugin. Add those lines to your `package.json`:
```
Expand All @@ -18,9 +18,7 @@ This is a customizable Commitizen plugin. You can specify the commit types, scop
}
```

- the `postinstall` script will automatically create a `.cz-config` in the root of your project *if it doesn't exsit*. It also creates a symlink inside `node_modules/cz-customizable` to point to your config file.

- you should commit your `.cz-config.js` file to your git.
- you should commit your `.cz-config.js` file to your git. Run `cp ./node_modules/cz-customizable/cz-config-EXAMPLE.js ./.cz-config.js` in a project root directory to get a template.

* if you don't provide a config file, this adapter will use the contents of the default file `node_modules/cz-customizable/cz-config-EXAMPLE.js`

Expand All @@ -38,20 +36,6 @@ Hopefully this will help you to have consistent commit messages and have a fully
It prompts for [conventional changelog](https://github.com/ajoslin/conventional-changelog/blob/master/conventions/angular.md) standard.


## Troubleshooting:
### you can't see the file `.cz-config` in the root of your porject.
- you can manually copy from `node_modules/cz-customizable/cz-config-EXAMPLE.js` to your project root (where your package.json is) and rename to `.cz-config.js`

### you edited the contents of `.cz-config.js` but `git cz` still doesn't show your values
- probably the post install script didn't create the symlink properly.
- Manual symlink creation:
- copy the file `cz-config-EXAMPLE.js` to the root of your project.
- rename the file to `.cz-config.js` and modify the options and scopes as you like.
- Now create a symlink to your config file:
- Linux ```ln -nsf ../../.cz-config.js node_modules/cz-customizable/.cz-config.js```
- Windows (something like this): ```mklink /D node_modules\cz-customizable\.cz-config.js ..\..\.cz-config.js```


## CONTRIBUTING

Please refer to the [Contributor Guidelines](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md) and [Conduct of Code](https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md) from [AngularJs](https://github.com/angular/angular.js) project.
Expand Down
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

// Inspired by: https://github.com/commitizen/cz-conventional-changelog and https://github.com/commitizen/cz-cli

var CZ_CONFIG_NAME = '.cz-config.js';
var CZ_CONFIG_EXAMPLE_LOCATION = './cz-config-EXAMPLE.js';
var wrap = require('word-wrap');
var SYMLINK_CONFIG_NAME = 'cz-config';
var findConfig = require('find-config');
var log = require('winston');
var editor = require('editor');
var temp = require('temp').track();
var fs = require('fs');
var path = require('path');

/* istanbul ignore next */
function readConfigFile() {
// this function is replaced in test.
var config;
try {
// Try to find a customized version for the project
// This file is a symlink to the real one usually placed in the root of your project.
config = require('./' + SYMLINK_CONFIG_NAME);
} catch (err) {
log.warn('You don\'t have a file "' + SYMLINK_CONFIG_NAME + '" in your project root directory. We will use the default configuration file inside this directory: ' + __dirname);
log.warn('You should go to your "node_modules/cz-customizable" and run "npm run postinstall" to fix it up. Please report on Github if this doenst work.');

config = require('./cz-config-EXAMPLE');
var config = findConfig.require(CZ_CONFIG_NAME, {home: false});
if (!config) {
log.warn('Unable to find a config file "' + CZ_CONFIG_NAME + '". Default configuration would be used.');
log.warn('Copy and use it as template by running in a project root directory:\n "cp '
+ path.resolve(CZ_CONFIG_EXAMPLE_LOCATION) + ' ' + path.join('.', CZ_CONFIG_NAME) + '"');

config = require(CZ_CONFIG_EXAMPLE_LOCATION);
}
return config;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"test:check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
"test:watch": "node_modules/jasmine-node/bin/jasmine-node --color --autotest spec/ --watch .",
"report-coverage": "cat ./coverage/lcov.info | codecov",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"postinstall": "node ./postinstall.js"
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"homepage": "https://github.com/leonardoanalista/cz-customizable",
"repository": {
Expand All @@ -25,6 +24,7 @@
"license": "MIT",
"dependencies": {
"editor": "^1.0.0",
"find-config": "^0.3.0",
"temp": "^0.8.3",
"winston": "2.1.0",
"word-wrap": "1.1.0"
Expand Down
28 changes: 0 additions & 28 deletions postinstall.js

This file was deleted.

0 comments on commit c3dfe81

Please sign in to comment.