diff --git a/README.md b/README.md index 511254c..d291cdb 100644 --- a/README.md +++ b/README.md @@ -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`: ``` @@ -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` @@ -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. diff --git a/index.js b/index.js index 67aad43..f69f3e2 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/package.json b/package.json index 3638570..ecf07d2 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" diff --git a/postinstall.js b/postinstall.js deleted file mode 100644 index bfb68eb..0000000 --- a/postinstall.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var path = require('path'); -var fs = require('fs'); - -var SYM_LINK_LOCATION = './cz-config'; -var CZ_CONFIG_NAME = '.cz-config.js'; -var CZ_CONFIG_EXAMPLE_LOCATION = './cz-config-EXAMPLE.js'; - - - -fs.stat(path.resolve('./../../' + CZ_CONFIG_NAME), function(err, stats) { - if (err) { - console.info('>>> config file doesn\'t exist. I will create one for you.'); - fs.writeFileSync(path.resolve('./../../' + CZ_CONFIG_NAME), fs.readFileSync(path.resolve(CZ_CONFIG_EXAMPLE_LOCATION))); - } else { - console.info('>>> file ' + CZ_CONFIG_NAME + ' already exist in your project root. We will NOT override it.'); - } - -}); - -//first delete any existing symbolic link. -fs.unlink(SYM_LINK_LOCATION, function(err) { - - // create or re-create symlink to file located 2 dirs up. - console.info('>>> cz-customizable is about to create this symlink "' + __dirname + '/.cz-config" to point to your project root directory, 2 levels up.'); - fs.symlinkSync(path.resolve('./../../' + CZ_CONFIG_NAME), path.resolve(SYM_LINK_LOCATION), 'file'); -});