Skip to content

Commit 923e147

Browse files
committed
Feat: add option to disable emojies
1 parent 5e29cd4 commit 923e147

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,25 @@ $ sgc
4141
You can even create a global config. Just go to your users home and create a `.sgcrc`. The global config will be triggered if no project configurations are present.
4242

4343
**Options:**
44+
- [emojies](#emojies)
4445
- [types](#types)
4546
- [rules](#rules)
4647

48+
### emojies
49+
50+
**Type:** `boolean`
51+
52+
**Default:** `false`
53+
54+
A boolean to enable emojies at the beginning of a commit message
55+
56+
Example:
57+
```json
58+
{
59+
"emojies": false
60+
}
61+
```
62+
4763
### types
4864

4965
> Types will define your git commits.

lib/promptConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const choices = (configuration) => {
55
const choicesList = [];
66

77
configuration.types.forEach((type) => {
8-
const emoji = `${type.emoji} ` || '';
8+
const emoji = configuration.emojies && type.emoji ? `${type.emoji} ` : '';
99
const configType = type.type;
1010
const description = type.description || '';
1111

test/fixtures/questions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import chalk from 'chalk';
2+
3+
const withEmoji = [
4+
{
5+
name: `${chalk.bold('Add:')} Files added`,
6+
value: ':emo: Add:',
7+
},
8+
];
9+
10+
const withoutEmoji = [
11+
{
12+
name: `${chalk.bold('Add:')} Files added`,
13+
value: 'Add:',
14+
},
15+
];
16+
17+
export {
18+
withEmoji,
19+
withoutEmoji,
20+
};

test/prompConfig.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import os from 'os';
22
import test from 'ava';
33
import path from 'path';
4-
import chalk from 'chalk';
54
import fs from 'fs-extra';
65
import json from 'json-extra';
76

87
import getConfig from '../lib/getConfig';
98
import { choices, questions } from '../lib/promptConfig';
9+
import { withEmoji, withoutEmoji } from './fixtures/questions';
1010

1111
const cwd = process.cwd();
12-
const homedir = os.homedir();
1312
const date = new Date();
13+
const homedir = os.homedir();
14+
const fixtures = path.join(cwd, 'test', 'fixtures');
1415
const datetime = date.toISOString().slice(0, 10);
1516
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 4);
1617

1718
let globalExist = false;
1819

19-
2020
// rename global .sgcrc
2121
test.before(() => {
2222
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
@@ -35,23 +35,21 @@ test('get configuration file equals .sgcrc_default', (t) => {
3535
t.deepEqual(getConfig(), json.readToObjSync(path.join(cwd, '.sgcrc_default')));
3636
});
3737

38-
test('choices are the same as choices generated from .sgcrc_default', (t) => {
39-
const sgc = getConfig();
38+
test('choices are rendered without emojis', (t) => {
39+
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
4040
const choicesList = choices(sgc);
41-
const choicesArray = [];
4241

43-
sgc.types.forEach((type) => {
44-
const emoji = `${type.emoji} ` || '';
45-
const configType = type.type;
46-
const description = type.description || '';
42+
t.deepEqual(choicesList, withoutEmoji);
43+
});
4744

48-
choicesArray.push({
49-
value: emoji + configType,
50-
name: `${chalk.bold(configType)} ${description}`,
51-
});
52-
});
45+
test('choices are rendered with emojis', (t) => {
46+
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
47+
48+
sgc.emojies = true;
49+
50+
const choicesList = choices(sgc);
5351

54-
t.deepEqual(choicesList, choicesArray);
52+
t.deepEqual(choicesList, withEmoji);
5553
});
5654

5755
test('check the values of the question object', (t) => {

0 commit comments

Comments
 (0)