1
1
'use strict' ;
2
2
3
- const wrap = require ( 'word-wrap' ) ;
4
3
const inquirer = require ( 'inquirer' ) ;
4
+ const wrap = require ( 'word-wrap' ) ;
5
+
5
6
inquirer . registerPrompt ( 'limitedInput' , require ( './prompt/LimitedInput' ) ) ;
6
7
7
8
const MAX_SUBJECT_LENGTH = 50 ;
@@ -10,104 +11,112 @@ const MIN_SUBJECT_LENGTH = 3;
10
11
const MIN_SUBJECT_LENGTH_ERROR_MESSAGE = `The subject must have at least ${ MIN_SUBJECT_LENGTH } characters` ;
11
12
12
13
module . exports = {
13
- prompter : ( cz , commit ) => {
14
- inquirer . prompt ( [
14
+ prompter ( cz , commit ) {
15
+ return inquirer . prompt ( [
15
16
{
16
- type : 'list' ,
17
- name : 'type' ,
18
- message : 'Select the type of change that you\'re committing: ' ,
19
- choices : [
20
- {
21
- name : 'feat: A new feature' ,
22
- value : 'feat'
23
- } ,
24
- {
25
- name : 'fix: A bug fix' ,
26
- value : 'fix'
27
- } ,
28
- {
29
- name : 'docs: Documentation only changes' ,
30
- value : 'docs'
31
- } ,
32
- {
33
- name : 'style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)' ,
34
- value : 'style'
35
- } ,
36
- {
37
- name : 'refactor: A code change that neither fixes a bug or adds a feature' ,
38
- value : 'refactor'
39
- } ,
40
- {
41
- name : 'perf: A code change that improves performance' ,
42
- value : 'perf'
43
- } ,
44
- {
45
- name : 'test: Adding missing tests' ,
46
- value : 'test'
47
- } ,
48
- {
49
- name : 'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation' ,
50
- value : 'chore'
51
- }
52
- ]
17
+ choices : [
18
+ {
19
+ name : 'feat: A new feature ' ,
20
+ value : 'feat'
21
+ } ,
22
+ {
23
+ name : 'fix: A bug fix' ,
24
+ value : 'fix'
25
+ } ,
26
+ {
27
+ name : 'docs: Documentation only changes' ,
28
+ value : 'docs'
29
+ } ,
30
+ {
31
+ name : 'style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)' ,
32
+ value : 'style'
33
+ } ,
34
+ {
35
+ name : 'refactor: A code change that neither fixes a bug or adds a feature' ,
36
+ value : 'refactor'
37
+ } ,
38
+ {
39
+ name : 'perf: A code change that improves performance' ,
40
+ value : 'perf'
41
+ } ,
42
+ {
43
+ name : 'test: Adding missing tests' ,
44
+ value : 'test'
45
+ } ,
46
+ {
47
+ name : 'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation' ,
48
+ value : 'chore'
49
+ }
50
+ ] ,
51
+ message : 'Select the type of change that you\'re committing:' ,
52
+ name : 'type' ,
53
+ type : 'list'
53
54
} ,
54
55
{
55
- type : 'limitedInput' ,
56
- name : 'subject' ,
57
- maxLength : MAX_SUBJECT_LENGTH ,
58
56
filter : ( input ) => {
59
- const subject = input . trim ( ) ;
60
- return subject . endsWith ( '.' ) ? subject . substr ( 0 , subject . length - 1 ) . trim ( ) : subject ;
57
+ let subject ;
58
+
59
+ subject = input . trim ( ) ;
60
+ while ( subject . endsWith ( '.' ) ) {
61
+ subject = subject . substr ( 0 , subject . length - 1 ) . trim ( ) ;
62
+ }
63
+
64
+ return subject ;
61
65
} ,
62
- validate : ( input ) => input . length >= MIN_SUBJECT_LENGTH || MIN_SUBJECT_LENGTH_ERROR_MESSAGE ,
63
66
leadingLabel : ( answers ) => `${ answers . type } :` ,
64
- message : 'Write a short, imperative mood description of the change:'
67
+ maxLength : MAX_SUBJECT_LENGTH ,
68
+ message : 'Write a short, imperative mood description of the change:' ,
69
+ name : 'subject' ,
70
+ type : 'limitedInput' ,
71
+ validate : ( input ) => input . length >= MIN_SUBJECT_LENGTH || MIN_SUBJECT_LENGTH_ERROR_MESSAGE
65
72
} ,
66
73
{
67
- type : 'input ' ,
74
+ message : 'Provide a longer description of the change:\n ' ,
68
75
name : 'body' ,
69
- message : 'Provide a longer description of the change:\n '
76
+ type : 'input '
70
77
} ,
71
78
{
72
- type : 'input ' ,
79
+ message : 'List any breaking changes:\n BREAKING CHANGE: ' ,
73
80
name : 'breaking' ,
74
- message : 'List any breaking changes:\n BREAKING CHANGE: '
81
+ type : 'input '
75
82
} ,
76
83
{
77
- type : 'input ' ,
84
+ message : 'Reference any task that this commit closes:\n Issues: ' ,
78
85
name : 'footer' ,
79
- message : 'Reference any task that this commit closes:\n Issues: '
86
+ type : 'input '
80
87
}
81
88
] )
82
- . then ( ( answers ) => {
83
- const wrapOptions = {
84
- trim : true ,
85
- indent : '' ,
86
- width : MAX_LINE_WIDTH
87
- } ;
89
+ . then ( ( answers ) => {
90
+ const wrapOptions = {
91
+ indent : '' ,
92
+ trim : true ,
93
+ width : MAX_LINE_WIDTH
94
+ } ;
88
95
89
- const head = answers . type + ': ' + answers . subject ;
96
+ const head = answers . type + ': ' + answers . subject ;
90
97
91
- // Wrap these lines at MAX_LINE_WIDTH characters
92
- const body = wrap ( answers . body , wrapOptions ) ;
93
- const breaking = wrap ( answers . breaking , wrapOptions ) ;
94
- const footer = wrap ( answers . footer , wrapOptions ) ;
98
+ // Wrap these lines at MAX_LINE_WIDTH characters
99
+ const body = wrap ( answers . body , wrapOptions ) ;
100
+ const breaking = wrap ( answers . breaking , wrapOptions ) ;
101
+ const footer = wrap ( answers . footer , wrapOptions ) ;
95
102
96
- let msg = head ;
103
+ let msg ;
97
104
98
- if ( body ) {
99
- msg += '\n\n' + body ;
100
- }
105
+ msg = head ;
101
106
102
- if ( breaking ) {
103
- msg += '\n\n' + 'BREAKING CHANGE: ' + breaking ;
104
- }
107
+ if ( body ) {
108
+ msg += '\n\n' + body ;
109
+ }
105
110
106
- if ( footer ) {
107
- msg += '\n\n' + 'Issues: ' + footer ;
108
- }
111
+ if ( breaking ) {
112
+ msg += '\n\nBREAKING CHANGE: ' + breaking ;
113
+ }
114
+
115
+ if ( footer ) {
116
+ msg += '\n\nIssues: ' + footer ;
117
+ }
109
118
110
- commit ( msg ) ;
111
- } ) ;
119
+ return commit ( msg ) ;
120
+ } ) ;
112
121
}
113
- }
122
+ } ;
0 commit comments