diff --git a/.gitignore b/.gitignore index c530302..f21be44 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ build/Release node_modules .DS_Store coverage +.cz-config.js diff --git a/README.md b/README.md index d291cdb..8e688e2 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This is a customizable Commitizen plugin. You can specify the commit types, scop } } ``` - + - 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` @@ -36,6 +36,23 @@ 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. +## GOTCHAS + +* backticks +If you wish to have backticks in your content, for example "feat: \`string\`", the commit preview will be "feat: \\\\`string\\\\`". +Don't worry because on your `git log` will be "feat: \`string\`" as desired. + +* multiline contents on the body of the message +Body is the only place where you can use a `pipe` to break lines. +E.g.: you type this: `my items are:| - item01| - item 02`, which will become: + + +`my items are:` + `- item01` + `- item 02` + + + ## 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 f69f3e2..7cf663d 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ var path = require('path'); function readConfigFile() { // this function is replaced in test. 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 ' @@ -46,6 +47,18 @@ function buildCommit(answers) { return subject.trim(); } + function escapeSpecialChars(result) { + var specialChars = ['\`']; + + specialChars.map(function (item){ + // For some strange reason, we have to pass additional '\' slash to commitizen. Total slashes are 4. + // If user types "feat: `string`", the commit preview should show "feat: `\\string\\`". + // Don't worry. The git log will be "feat: `string`" + result = result.replace(new RegExp(item, 'g'), '\\\\`'); + }); + return result; + } + // Hard limit this line var head = (answers.type + addScope(answers.scope) + addSubject(answers.subject)).slice(0, maxLineWidth); @@ -67,7 +80,7 @@ function buildCommit(answers) { result += '\n\n' + footer; } - return result; + return escapeSpecialChars(result); } var isNotWip = function(answers) { diff --git a/spec/czCustomizableSpec.js b/spec/czCustomizableSpec.js index 2b8b44a..e28d98b 100644 --- a/spec/czCustomizableSpec.js +++ b/spec/czCustomizableSpec.js @@ -32,6 +32,19 @@ describe('cz-customizable', function() { commit = jasmine.createSpy(); }); + it('should escape special characters sush as backticks', function() { + module.prompter(cz, commit); + var commitAnswers = cz.prompt.mostRecentCall.args[1]; + + var answers = { + confirmCommit: 'yes', + type: 'feat', + subject: 'with backticks `here`' + }; + + commitAnswers(answers); + expect(commit).toHaveBeenCalledWith('feat: with backticks \\\\`here\\\\`'); + }); it('should call cz.prompt with questions', function() { module.prompter(cz, commit);