forked from JPeer264/node-semantic-git-commit-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestions.js
More file actions
109 lines (94 loc) · 2.71 KB
/
Copy pathquestions.js
File metadata and controls
109 lines (94 loc) · 2.71 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import chalk from 'chalk';
import combineTypeScope from './helpers/combineTypeScope';
import ruleWarningMessages from './rules/ruleWarningMessages';
const choices = (config) => {
const choicesList = [];
config.types.forEach((type) => {
const emoji = config.emoji && type.emoji ? `${type.emoji} ` : '';
const configType = config.lowercaseTypes ? type.type.toLowerCase() : type.type;
const description = type.description || '';
choicesList.push({
value: emoji + configType,
name: `${chalk.bold(configType)} ${description}`,
});
});
return choicesList;
};
const initMessage = (config) => {
let message = '';
if (config.emoji &&
typeof config.initialCommit === 'object' &&
config.initialCommit.isEnabled) {
message = `${config.initialCommit.emoji} ${config.initialCommit.message}`;
} else {
message = config.initialCommit.message;
}
return message;
};
const initQuestion = (config) => {
const message = initMessage(config);
return {
type: 'confirm',
name: 'initCommit',
message: `Confirm as first commit message: "${message}"`,
default: true,
};
};
const questions = (config) => {
const choicesList = choices(config);
const questionsList = [
{
type: 'list',
name: 'type',
message: 'Select the type of your commit:',
choices: choicesList,
},
{
type: 'input',
name: 'scope',
message: 'Enter your scope (no whitespaces allowed):',
when: () => config.scope,
validate: input => (input.match(/\s/) !== null ? 'No whitespaces allowed' : true),
filter: input => (input ? `(${input})` : input),
},
{
type: 'input',
name: 'description',
message: 'Enter your commit message:',
validate: (input, answers) => {
if (input.length === 0) {
return 'The commit message is not allowed to be empty';
}
const scope = answers.scope || '';
const type = combineTypeScope(answers.type, scope.trim());
const combinedInput = `${type} ${input.trim()}`;
const warnings = ruleWarningMessages(combinedInput, config);
return warnings || true;
},
},
{
type: 'confirm',
name: 'body',
message: 'Do you want to add a body?',
when: () => config.body,
default: false,
},
{
type: 'editor',
name: 'editor',
message: 'This will let you add more information',
when: answers => answers.body,
default: (answers) => {
const type = combineTypeScope(answers.type, answers.scope);
return `${type} ${answers.description}\n\n\n`;
},
},
];
return questionsList;
};
export default questions;
export {
choices,
initMessage,
initQuestion,
};