diff --git a/.git-cz.json b/.git-cz.json index 92137901..99630e77 100644 --- a/.git-cz.json +++ b/.git-cz.json @@ -1,3 +1,4 @@ { - "disableEmoji": false + "disableEmoji": false, + "format": "{emoji} {scope}: {subject}" } diff --git a/.prettierrc b/.prettierrc index 915b20c9..e1cb6f1c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,10 @@ { - "singleQuote": true, - "arrowParens": "always", - "bracketSpacing": false -} \ No newline at end of file + "arrowParens": "always", + "bracketSpacing": false, + "endOfLine": "auto", + "printWidth": 85, + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none" +} diff --git a/README.md b/README.md index 452d3443..a9f631da 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) - # git-cz ![image](https://user-images.githubusercontent.com/9773803/49760520-fa6c6f00-fcc4-11e8-84c4-80727f071487.png) - ### Without installation ```shell @@ -19,7 +17,7 @@ npx git-cz -e ```shell npm install -g git-cz git-cz -# or +# or git-cz -e ``` @@ -38,7 +36,7 @@ npm install --save-dev git-cz "commitizen": { "path": "git-cz" } - }, + } } ``` @@ -61,7 +59,6 @@ run: git cz ``` - ## Custom config You can provide a custom configuration in a `changelog.config.js` file in your repo, or in any parent folder. @@ -70,80 +67,63 @@ Below is default config: ```js module.exports = { - "disableEmoji": false, - "list": [ - "test", - "feat", - "fix", - "chore", - "docs", - "refactor", - "style", - "ci", - "perf" - ], - "maxMessageLength": 64, - "minMessageLength": 3, - "questions": [ - "type", - "scope", - "subject", - "body", - "breaking", - "issues", - "lerna" - ], - "scopes": [], - "types": { - "chore": { - "description": "Build process or auxiliary tool changes", - "emoji": "๐Ÿค–", - "value": "chore" + disableEmoji: false, + format: '{type} {scope}: {subject}', + list: ['test', 'feat', 'fix', 'chore', 'docs', 'refactor', 'style', 'ci', 'perf'], + maxMessageLength: 64, + minMessageLength: 3, + questions: ['type', 'scope', 'subject', 'body', 'breaking', 'issues', 'lerna'], + scopes: [], + types: { + chore: { + description: 'Build process or auxiliary tool changes', + emoji: '๐Ÿค–', + value: 'chore' }, - "ci": { - "description": "CI related changes", - "emoji": "๐ŸŽก", - "value": "ci" + ci: { + description: 'CI related changes', + emoji: '๐ŸŽก', + value: 'ci' }, - "docs": { - "description": "Documentation only changes", - "emoji": "โœ๏ธ", - "value": "docs" + docs: { + description: 'Documentation only changes', + emoji: 'โœ๏ธ', + value: 'docs' }, - "feat": { - "description": "A new feature", - "emoji": "๐ŸŽธ", - "value": "feat" + feat: { + description: 'A new feature', + emoji: '๐ŸŽธ', + value: 'feat' }, - "fix": { - "description": "A bug fix", - "emoji": "๐Ÿ›", - "value": "fix" + fix: { + description: 'A bug fix', + emoji: '๐Ÿ›', + value: 'fix' }, - "perf": { - "description": "A code change that improves performance", - "emoji": "โšก๏ธ", - "value": "perf" + perf: { + description: 'A code change that improves performance', + emoji: 'โšก๏ธ', + value: 'perf' }, - "refactor": { - "description": "A code change that neither fixes a bug or adds a feature", - "emoji": "๐Ÿ’ก", - "value": "refactor" + refactor: { + description: 'A code change that neither fixes a bug or adds a feature', + emoji: '๐Ÿ’ก', + value: 'refactor' }, - "release": { - "description": "Create a release commit", - "emoji": "๐Ÿน", - "value": "release" + release: { + description: 'Create a release commit', + emoji: '๐Ÿน', + value: 'release' }, - "style": { - "description": "Markup, white-space, formatting, missing semi-colons...", - "emoji": "๐Ÿ’„", - "value": "style" + style: { + description: 'Markup, white-space, formatting, missing semi-colons...', + emoji: '๐Ÿ’„', + value: 'style' }, - "test": { - "description": "Adding missing tests", - "emoji": "๐Ÿ’", - "value": "test" + test: { + description: 'Adding missing tests', + emoji: '๐Ÿ’', + value: 'test' } } }; @@ -155,7 +135,7 @@ Using `--non-interactive` flag you can run `git-cz` non-interactive mode. For example: -``` +```bash git-cz --non-interactive --type=feat --subject="add onClick prop to component" ``` @@ -169,21 +149,22 @@ CLI parameters: - `--issues` - `--lerna` -## Disable Emoji +## Disable Emoji + Using `--disable-emoji` flag will disable emoji. For example: -``` +```bash git-cz --disable-emoji ``` ## Commit message format -* A commit message consists of a **header**, **body** and **footer**. -* The header has a **type** and a **subject**: +- A commit message consists of a **header**, **body** and **footer**. +- The header has a **type** and a **subject**: -``` +```bash [()]: [BLANK LINE] [body] @@ -201,6 +182,15 @@ Any other line should be limited to 72 character **[automatic wrapping]** This allows the message to be easier to read on GitHub as well as in various git tools. +### Format + +By default the subject format is: `{type} {scope}: {subject}` + +Configuring the `format` field in `.git-cz.json` you can customize your own: + +- `{emoji} {type} {scope} {subject}` +- `{type} {scope}: {emoji} {subject}` + ### Type Must be one of the following: @@ -215,13 +205,12 @@ Must be one of the following: - `ci` — CI related changes - `perf` — A code change that improves performance - ### Subject The subject contains succinct description of the change: -* Use the imperative, present tense: "change" not "changed" nor "changes" -* No dot (.) at the end. +- Use the imperative, present tense: "change" not "changed" nor "changes" +- No dot (.) at the end. ### Body @@ -240,18 +229,16 @@ Select the packages the commit affected. The footer is the place to reference any tasks related to this commit. - - ## Why this Fork? -``` +```bash npm i -g git-cz added 1 package in 0.612s ``` Installs in 0.6s vs 31.1s. -``` +```bash npm i -g mol-conventional-changelog added 345 packages in 31.076s ``` diff --git a/lib/formatCommitMessage.js b/lib/formatCommitMessage.js index 3db430a8..8cd276b4 100644 --- a/lib/formatCommitMessage.js +++ b/lib/formatCommitMessage.js @@ -21,21 +21,13 @@ const formatCommitMessage = (state) => { trim: true, width: MAX_LINE_WIDTH }; - let head = ''; - let scope = ''; - if (answers.scope && answers.scope !== 'none') { - scope = `(${answers.scope})`; - } - - if (config.disableEmoji) { - head = answers.type + scope + ': ' + answers.subject; - } else { - const emoji = config.types[answers.type].emoji; - const emojiPrefix = emoji ? emoji + ' ' : ''; + const emoji = config.types[answers.type].emoji; + const scope = answers.scope ? '(' + answers.scope.trim() + ')' : ''; + const subject = answers.subject.trim(); + const type = answers.type; - head = answers.type + scope + ': ' + emojiPrefix + answers.subject; - } + const format = config.format || '{emoji} {scope}: {subject}'; const affectsLine = makeAffectsLine(answers); @@ -44,6 +36,12 @@ const formatCommitMessage = (state) => { const breaking = wrap(answers.breaking, wrapOptions); const issues = wrap(answers.issues, wrapOptions); + const head = format + .replace(/\{emoji\}/g, emoji) + .replace(/\{scope\}/g, scope) + .replace(/\{subject\}/g, subject) + .replace(/\{type\}/g, type); + let msg = head; if (body) { diff --git a/lib/parseArgs.js b/lib/parseArgs.js index e703aedd..503171c1 100644 --- a/lib/parseArgs.js +++ b/lib/parseArgs.js @@ -13,6 +13,7 @@ const helpScreen = ` -h, --help show usage information -v, --version print version info and exit --disable-emoji don't add emoji to commit title + --format custom formatting options for subject --non-interactive run git-cz in non-interactive mode non-interactive mode options: @@ -32,6 +33,7 @@ const parseArgs = () => { 'dry-run': dryRun, hook, 'disable-emoji': disableEmoji, + format, 'non-interactive': nonInteractive, body, breaking, @@ -50,8 +52,24 @@ const parseArgs = () => { h: 'help', v: 'version' }, - boolean: ['version', 'help', 'disable-emoji', 'non-interactive', 'hook', 'dry-run'], - string: ['type', 'subject', 'scope', 'body', 'breaking', 'issues', 'learna'] + boolean: [ + 'version', + 'help', + 'disable-emoji', + 'non-interactive', + 'hook', + 'dry-run' + ], + string: [ + 'format', + 'type', + 'subject', + 'scope', + 'body', + 'breaking', + 'issues', + 'learna' + ] }); if (help || h) { @@ -67,6 +85,7 @@ const parseArgs = () => { const cliOptions = { disableEmoji, dryRun, + format, help, hook, nonInteractive, diff --git a/test/formatCommitMessage.test.js b/test/formatCommitMessage.test.js index c4c6bca9..24562efe 100644 --- a/test/formatCommitMessage.test.js +++ b/test/formatCommitMessage.test.js @@ -4,6 +4,7 @@ const formatCommitMessage = require('../lib/formatCommitMessage'); const defaultConfig = { disableEmoji: false, + format: '{type} {scope}: {subject}', breakingChangePrefix: '๐Ÿงจ ', closedIssuePrefix: 'โœ… ', closedIssueMessage: 'Closes: ',