/
index.ts
50 lines (41 loc) · 1.34 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { Inquirer } from 'inquirer';
import InquirerAutoComplete from 'inquirer-autocomplete-prompt';
import InquirerMaxLength from 'inquirer-maxlength-input-prompt';
import wrap from 'word-wrap';
import { getConfiguration } from './utils/configuration';
import { formatHeader, formatIssues, formatBreakingChange } from './pipes/commit-format';
import { getQuestions } from './utils/questions';
import type { ICommitFunc } from './interfaces/commit';
const prompter = async (cz: Inquirer, commit: ICommitFunc) => {
cz.prompt.registerPrompt('autocomplete', InquirerAutoComplete);
cz.prompt.registerPrompt('maxlength-input', InquirerMaxLength);
const configuration = await getConfiguration();
const wrapOptions = {
indent: '',
trim: true,
width: configuration.maxCommitLineWidth,
};
const questions = await getQuestions(configuration);
const answers = await cz.prompt(questions);
commit(
[
formatHeader(
configuration.headerFormat,
answers.type.type,
answers.scope,
answers.type.emoji,
answers.ticket_id,
answers.subject,
),
wrap(answers.body || '', wrapOptions),
wrap(formatBreakingChange(answers.breakingBody) || '', wrapOptions),
formatIssues(answers.issues),
]
.filter(Boolean)
.join('\n\n')
.trim(),
);
};
const InqObj = { prompter };
export * from './config';
export default InqObj;