Skip to content

Commit 56a4d8b

Browse files
committed
feat(cz-commitlint): add prompt field to commitlint config file, add tests for cz-commitlint
prompt field is working for prompt config, settled in commitlint config file, can be defined by shared configurations.
1 parent 12a596f commit 56a4d8b

31 files changed

+2555
-606
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ lib/
1111
package.json.lerna_backup
1212
/*.iml
1313
tsconfig.tsbuildinfo
14+
coverage

@commitlint/config-conventional/index.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,102 @@ module.exports = {
3333
],
3434
],
3535
},
36+
prompt: {
37+
questions: {
38+
type: {
39+
description: "Select the type of change that you're committing:",
40+
enum: {
41+
feat: {
42+
description: 'A new feature',
43+
title: 'Features',
44+
emoji: '✨',
45+
},
46+
fix: {
47+
description: 'A bug fix',
48+
title: 'Bug Fixes',
49+
emoji: '🐛',
50+
},
51+
docs: {
52+
description: 'Documentation only changes',
53+
title: 'Documentation',
54+
emoji: '📚',
55+
},
56+
style: {
57+
description:
58+
'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
59+
title: 'Styles',
60+
emoji: '💎',
61+
},
62+
refactor: {
63+
description:
64+
'A code change that neither fixes a bug nor adds a feature',
65+
title: 'Code Refactoring',
66+
emoji: '📦',
67+
},
68+
perf: {
69+
description: 'A code change that improves performance',
70+
title: 'Performance Improvements',
71+
emoji: '🚀',
72+
},
73+
test: {
74+
description: 'Adding missing tests or correcting existing tests',
75+
title: 'Tests',
76+
emoji: '🚨',
77+
},
78+
build: {
79+
description:
80+
'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
81+
title: 'Builds',
82+
emoji: '🛠',
83+
},
84+
ci: {
85+
description:
86+
'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
87+
title: 'Continuous Integrations',
88+
emoji: '⚙️',
89+
},
90+
chore: {
91+
description: "Other changes that don't modify src or test files",
92+
title: 'Chores',
93+
emoji: '♻️',
94+
},
95+
revert: {
96+
description: 'Reverts a previous commit',
97+
title: 'Reverts',
98+
emoji: '🗑',
99+
},
100+
},
101+
},
102+
scope: {
103+
description:
104+
'What is the scope of this change (e.g. component or file name)',
105+
},
106+
subject: {
107+
description: 'Write a short, imperative tense description of the change',
108+
},
109+
body: {
110+
description: 'Provide a longer description of the change',
111+
},
112+
isBreaking: {
113+
description: 'Are there any breaking changes?',
114+
},
115+
breakingBody: {
116+
description:
117+
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself',
118+
},
119+
breaking: {
120+
description: 'Describe the breaking changes',
121+
},
122+
isIssueAffected: {
123+
description: 'Does this change affect any open issues?',
124+
},
125+
issuesBody: {
126+
description:
127+
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself',
128+
},
129+
issues: {
130+
description: 'Add issue references (e.g. "fix #123", "re #123".)',
131+
},
132+
},
133+
}
36134
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {QualifiedRules, UserPromptConfig} from '@commitlint/types';
2+
import {Inquirer} from 'inquirer';
3+
import {
4+
combineCommitMessage as combineBody,
5+
getQuestions as getBodyQuestions,
6+
} from './SectionBody';
7+
import {
8+
combineCommitMessage as combineFooter,
9+
getQuestions as getFooterQuestions,
10+
} from './SectionFooter';
11+
import {
12+
combineCommitMessage as combineHeader,
13+
getQuestions as getHeaderQuestions,
14+
} from './SectionHeader';
15+
import {setPromptConfig} from './store/prompts';
16+
import {setRules} from './store/rules';
17+
18+
export default async function (
19+
rules: QualifiedRules,
20+
prompts: UserPromptConfig,
21+
inquirer: Inquirer
22+
): Promise<string> {
23+
setRules(rules);
24+
setPromptConfig(prompts);
25+
const questions = [
26+
...getHeaderQuestions(),
27+
...getBodyQuestions(),
28+
...getFooterQuestions(),
29+
];
30+
const answers = await inquirer.prompt(questions);
31+
const header = combineHeader(answers);
32+
const body = combineBody(answers);
33+
const footer = combineFooter(answers);
34+
35+
return [header, body, footer].filter(Boolean).join('\n');
36+
}

0 commit comments

Comments
 (0)