@@ -5,23 +5,23 @@ var map = require('lodash.map');
5
5
var longest = require ( 'longest' ) ;
6
6
var chalk = require ( 'chalk' ) ;
7
7
8
- var filter = function ( array ) {
9
- return array . filter ( function ( x ) {
8
+ var filter = function ( array ) {
9
+ return array . filter ( function ( x ) {
10
10
return x ;
11
11
} ) ;
12
12
} ;
13
13
14
- var headerLength = function ( answers ) {
14
+ var headerLength = function ( answers ) {
15
15
return (
16
16
answers . type . length + 2 + ( answers . scope ? answers . scope . length + 2 : 0 )
17
17
) ;
18
18
} ;
19
19
20
- var maxSummaryLength = function ( options , answers ) {
20
+ var maxSummaryLength = function ( options , answers ) {
21
21
return options . maxHeaderWidth - headerLength ( answers ) ;
22
22
} ;
23
23
24
- var filterSubject = function ( subject ) {
24
+ var filterSubject = function ( subject ) {
25
25
subject = subject . trim ( ) ;
26
26
if ( subject . charAt ( 0 ) . toLowerCase ( ) !== subject . charAt ( 0 ) ) {
27
27
subject =
@@ -36,14 +36,14 @@ var filterSubject = function(subject) {
36
36
// This can be any kind of SystemJS compatible module.
37
37
// We use Commonjs here, but ES6 or AMD would do just
38
38
// fine.
39
- module . exports = function ( options ) {
39
+ module . exports = function ( options ) {
40
40
var types = options . types ;
41
41
42
42
var length = longest ( Object . keys ( types ) ) . length + 1 ;
43
- var choices = map ( types , function ( type , key ) {
43
+ var choices = map ( types , function ( type , key ) {
44
44
return {
45
45
name : ( key + ':' ) . padEnd ( length ) + ' ' + type . description ,
46
- value : key
46
+ value : key ,
47
47
} ;
48
48
} ) ;
49
49
@@ -59,7 +59,7 @@ module.exports = function(options) {
59
59
//
60
60
// By default, we'll de-indent your commit
61
61
// template and will keep empty lines.
62
- prompter : function ( cz , commit ) {
62
+ prompter : function ( cz , commit ) {
63
63
// Let's ask some questions of the user
64
64
// so that we can populate our commit
65
65
// template.
@@ -73,32 +73,32 @@ module.exports = function(options) {
73
73
name : 'type' ,
74
74
message : "Select the type of change that you're committing:" ,
75
75
choices : choices ,
76
- default : options . defaultType
76
+ default : options . defaultType ,
77
77
} ,
78
78
{
79
79
type : 'input' ,
80
80
name : 'scope' ,
81
81
message :
82
82
'What is the scope of this change (e.g. component or file name): (press enter to skip)' ,
83
83
default : options . defaultScope ,
84
- filter : function ( value ) {
84
+ filter : function ( value ) {
85
85
return options . disableScopeLowerCase
86
86
? value . trim ( )
87
87
: value . trim ( ) . toLowerCase ( ) ;
88
- }
88
+ } ,
89
89
} ,
90
90
{
91
91
type : 'input' ,
92
92
name : 'subject' ,
93
- message : function ( answers ) {
93
+ message : function ( answers ) {
94
94
return (
95
95
'Write a short, imperative tense description of the change (max ' +
96
96
maxSummaryLength ( options , answers ) +
97
97
' chars):\n'
98
98
) ;
99
99
} ,
100
100
default : options . defaultSubject ,
101
- validate : function ( subject , answers ) {
101
+ validate : function ( subject , answers ) {
102
102
var filteredSubject = filterSubject ( subject ) ;
103
103
return filteredSubject . length == 0
104
104
? 'subject is required'
@@ -110,99 +110,94 @@ module.exports = function(options) {
110
110
filteredSubject . length +
111
111
' characters.' ;
112
112
} ,
113
- transformer : function ( subject , answers ) {
113
+ transformer : function ( subject , answers ) {
114
114
var filteredSubject = filterSubject ( subject ) ;
115
115
var color =
116
116
filteredSubject . length <= maxSummaryLength ( options , answers )
117
117
? chalk . green
118
118
: chalk . red ;
119
119
return color ( '(' + filteredSubject . length + ') ' + subject ) ;
120
120
} ,
121
- filter : function ( subject ) {
121
+ filter : function ( subject ) {
122
122
return filterSubject ( subject ) ;
123
- }
123
+ } ,
124
124
} ,
125
125
{
126
126
type : 'input' ,
127
127
name : 'body' ,
128
- message : function ( answers ) {
129
- return (
130
- 'Provide a longer description of the change (max ' +
131
- options . maxBodyLineWidth +
132
- ' chars per line): (press enter to skip)\n'
133
- ) ;
134
- } ,
128
+ message :
129
+ 'Provide a longer description of the change: (press enter to skip)\n' ,
135
130
default : options . defaultBody ,
136
- transformer : function ( body ) {
131
+ transformer : function ( body ) {
137
132
var color = chalk . green ;
138
133
return color ( '(' + body . length + ') ' + body ) ;
139
- }
134
+ } ,
140
135
} ,
141
136
{
142
137
type : 'confirm' ,
143
138
name : 'isBreaking' ,
144
139
message : 'Are there any breaking changes?' ,
145
- default : false
140
+ default : false ,
146
141
} ,
147
142
{
148
143
type : 'input' ,
149
144
name : 'breakingBody' ,
150
145
default : '-' ,
151
146
message :
152
147
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself:\n' ,
153
- when : function ( answers ) {
148
+ when : function ( answers ) {
154
149
return answers . isBreaking && ! answers . body ;
155
150
} ,
156
- validate : function ( breakingBody , answers ) {
151
+ validate : function ( breakingBody , answers ) {
157
152
return (
158
153
breakingBody . trim ( ) . length > 0 ||
159
154
'Body is required for BREAKING CHANGE'
160
155
) ;
161
- }
156
+ } ,
162
157
} ,
163
158
{
164
159
type : 'input' ,
165
160
name : 'breaking' ,
166
161
message : 'Describe the breaking changes:\n' ,
167
- when : function ( answers ) {
162
+ when : function ( answers ) {
168
163
return answers . isBreaking ;
169
- }
164
+ } ,
170
165
} ,
171
166
172
167
{
173
168
type : 'confirm' ,
174
169
name : 'isIssueAffected' ,
175
170
message : 'Does this change affect any open issues?' ,
176
- default : options . defaultIssues ? true : false
171
+ default : options . defaultIssues ? true : false ,
177
172
} ,
178
173
{
179
174
type : 'input' ,
180
175
name : 'issuesBody' ,
181
176
default : '-' ,
182
177
message :
183
178
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself:\n' ,
184
- when : function ( answers ) {
179
+ when : function ( answers ) {
185
180
return (
186
181
answers . isIssueAffected && ! answers . body && ! answers . breakingBody
187
182
) ;
188
- }
183
+ } ,
189
184
} ,
190
185
{
191
186
type : 'input' ,
192
187
name : 'issues' ,
193
188
message : 'Add issue references (e.g. "fix #123", "re #123".):\n' ,
194
- when : function ( answers ) {
189
+ when : function ( answers ) {
195
190
return answers . isIssueAffected ;
196
191
} ,
197
- default : options . defaultIssues ? options . defaultIssues : undefined
198
- }
199
- ] ) . then ( function ( answers ) {
192
+ default : options . defaultIssues ? options . defaultIssues : undefined ,
193
+ } ,
194
+ ] ) . then ( function ( answers ) {
200
195
var wrapOptions = {
201
196
trim : true ,
202
197
cut : false ,
203
198
newline : '\n' ,
204
199
indent : '' ,
205
- width : options . maxLineWidth
200
+ width : options . maxLineWidth ,
206
201
} ;
207
202
208
203
// parentheses are only needed when a scope is present
@@ -225,6 +220,6 @@ module.exports = function(options) {
225
220
226
221
commit ( filter ( [ head , body , breaking , issues ] ) . join ( '\n\n' ) ) ;
227
222
} ) ;
228
- }
223
+ } ,
229
224
} ;
230
225
} ;
0 commit comments