Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: 🎸 add "format" field to customize subject in commit msg #81
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeFitz committed Feb 27, 2021
1 parent c38da98 commit 5e998cf
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 103 deletions.
3 changes: 2 additions & 1 deletion .git-cz.json
@@ -1,3 +1,4 @@
{
"disableEmoji": false
"disableEmoji": false,
"format": "{emoji} {scope}: {subject}"
}
13 changes: 9 additions & 4 deletions .prettierrc
@@ -1,5 +1,10 @@
{
"singleQuote": true,
"arrowParens": "always",
"bracketSpacing": false
}
"arrowParens": "always",
"bracketSpacing": false,
"endOfLine": "auto",
"printWidth": 85,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none"
}
153 changes: 70 additions & 83 deletions 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
Expand All @@ -19,7 +17,7 @@ npx git-cz -e
```shell
npm install -g git-cz
git-cz
# or
# or
git-cz -e
```

Expand All @@ -38,7 +36,7 @@ npm install --save-dev git-cz
"commitizen": {
"path": "git-cz"
}
},
}
}
```

Expand All @@ -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.
Expand All @@ -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'
}
}
};
Expand All @@ -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"
```

Expand All @@ -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
<type>[(<scope>)]: <emoji> <subject>
[BLANK LINE]
[body]
Expand All @@ -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:
Expand All @@ -215,13 +205,12 @@ Must be one of the following:
- `ci` &mdash; CI related changes
- `perf` &mdash; 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

Expand All @@ -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
```
24 changes: 11 additions & 13 deletions lib/formatCommitMessage.js
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down
23 changes: 21 additions & 2 deletions lib/parseArgs.js
Expand Up @@ -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:
Expand All @@ -32,6 +33,7 @@ const parseArgs = () => {
'dry-run': dryRun,
hook,
'disable-emoji': disableEmoji,
format,
'non-interactive': nonInteractive,
body,
breaking,
Expand All @@ -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) {
Expand All @@ -67,6 +85,7 @@ const parseArgs = () => {
const cliOptions = {
disableEmoji,
dryRun,
format,
help,
hook,
nonInteractive,
Expand Down
1 change: 1 addition & 0 deletions test/formatCommitMessage.test.js
Expand Up @@ -4,6 +4,7 @@ const formatCommitMessage = require('../lib/formatCommitMessage');

const defaultConfig = {
disableEmoji: false,
format: '{type} {scope}: {subject}',
breakingChangePrefix: '🧨 ',
closedIssuePrefix: '✅ ',
closedIssueMessage: 'Closes: ',
Expand Down

0 comments on commit 5e998cf

Please sign in to comment.