-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
63 lines (57 loc) · 1.81 KB
/
index.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
const commitlintLoad = require('@commitlint/load');
const commitlintLint = require('@commitlint/lint');
const { reportSummary, reportIsValid } = require('./commitlint-utils');
const getScopes = require('./get-scopes');
const getTypes = require('./get-types');
module.exports = {
prompter(cz, commit) {
commitlintLoad({ extends: ['peakfijn'] }).then(commitlintConfig => {
const scopeInfo = getScopes(commitlintConfig);
const typeInfo = getTypes(commitlintConfig);
const questions = [
{
type: 'list',
name: 'type',
message: 'What is the most appropriate change type? (in priority)\n',
choices: typeInfo.choices,
when: typeInfo.enabled,
},
{
type: 'list',
name: 'scope',
message: 'What is the scope of this change?\n',
choices: scopeInfo.choices,
when: scopeInfo.enabled,
},
{
type: 'input',
name: 'subject',
message: 'Write a short description of the change: (imperative tense, no punctuation)\n',
},
{
type: 'input',
name: 'body',
message: 'Provide a longer description of the change: (press enter to skip)\n',
},
{
type: 'input',
name: 'footer',
message: 'Provide any (external) references, separated by a space: (press enter to skip)\n',
},
];
cz.prompt(questions).then(answers => {
const scope = answers.scope ? `(${answers.scope})` : '';
const head = `${answers.type}${scope}: ${answers.subject.trim()}`;
const footer = (answers.footer || '').trim().split(' ').join('\n');
const commitMessage = `${head}\n\n${answers.body}\n\n${footer}`.trim();
commitlintLint(commitMessage, commitlintConfig.rules).then(report => {
if (reportIsValid(report)) {
commit(commitMessage);
} else {
console.log(reportSummary(report));
}
});
});
});
},
};