forked from leoforfree/cz-customizable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestions.js
More file actions
155 lines (135 loc) · 4.42 KB
/
questions.js
File metadata and controls
155 lines (135 loc) · 4.42 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
'use strict';
var buildCommit = require('./buildCommit');
var log = require('winston');
var isNotWip = function(answers) {
return answers.type.toLowerCase() !== 'wip';
};
module.exports = {
getQuestions: function(config, cz) {
// normalize config optional options
var scopeOverrides = config.scopeOverrides || {};
var messages = config.messages || {};
messages.type = messages.type || 'Select the type of change that you\'re committing:';
messages.scope = messages.scope || '\nDenote the SCOPE of this change (optional):';
messages.customScope = messages.customScope || 'Denote the SCOPE of this change:';
messages.subject = messages.subject || 'Write a SHORT, IMPERATIVE tense description of the change:\n';
messages.body = messages.body || 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n';
messages.breaking = messages.breaking || 'List any BREAKING CHANGES (optional):\n';
messages.footer = messages.footer || 'List any ISSUES CLOSED by this change (optional). E.g.: #31, #34:\n';
messages.confirmCommit = messages.confirmCommit || 'Are you sure you want to proceed with the commit above?';
var questions = [];
if (!config.skipType) {
questions.push({
type: 'list',
name: 'type',
message: messages.type,
choices: config.types
});
}
if (!config.skipScope) {
questions.push({
type: 'list',
name: 'scope',
message: messages.scope,
choices: function(answers) {
var scopes = [];
if (scopeOverrides[answers.type]) {
scopes = scopes.concat(scopeOverrides[answers.type]);
} else {
scopes = scopes.concat(config.scopes);
}
if (config.allowCustomScopes || scopes.length === 0) {
scopes = scopes.concat([
new cz.Separator(),
{ name: 'empty', value: false },
{ name: 'custom', value: 'custom' }
]);
}
return scopes;
},
when: function(answers) {
var hasScope = false;
if (scopeOverrides[answers.type]) {
hasScope = !!(scopeOverrides[answers.type].length > 0);
} else {
hasScope = !!(config.scopes && (config.scopes.length > 0));
}
if (!hasScope) {
answers.scope = 'custom';
return false;
} else {
return isNotWip(answers);
}
}
});
questions.push({
type: 'input',
name: 'scope',
message: messages.customScope,
when: function(answers) {
return answers.scope === 'custom';
}
});
}
if (!config.skipSubject) {
questions.push({
type: 'input',
name: 'subject',
message: messages.subject,
validate: function(value) {
var limit = config.subjectLimit || 100;
if (value.length > limit) {
return 'Exceed limit: ' + limit;
}
return true;
},
filter: function(value) {
return value.charAt(0).toLowerCase() + value.slice(1);
}
});
}
if (!config.skipBody) {
questions.push({
type: 'input',
name: 'body',
message: messages.body
});
}
if (!config.skipBreaking) {
questions.push({
type: 'input',
name: 'breaking',
message: messages.breaking,
when: function(answers) {
if (config.allowBreakingChanges && config.allowBreakingChanges.indexOf(answers.type.toLowerCase()) >= 0) {
return true;
}
return false; // no breaking changes allowed unless specifed
}
});
}
if (!config.skipFooter) {
questions.push({
type: 'input',
name: 'footer',
message: messages.footer,
when: isNotWip
});
}
questions.push({
type: 'expand',
name: 'confirmCommit',
choices: [
{ key: 'y', name: 'Yes', value: 'yes' },
{ key: 'n', name: 'Abort commit', value: 'no' },
{ key: 'e', name: 'Edit message', value: 'edit' }
],
message: function(answers) {
var SEP = '###--------------------------------------------------------###';
log.info('\n' + SEP + '\n' + buildCommit(answers, config) + '\n' + SEP + '\n');
return messages.confirmCommit;
}
});
return questions;
}
};