11'use strict' ;
22
3- const wrap = require ( 'word-wrap' ) ;
43const inquirer = require ( 'inquirer' ) ;
4+ const wrap = require ( 'word-wrap' ) ;
5+
56inquirer . registerPrompt ( 'limitedInput' , require ( './prompt/LimitedInput' ) ) ;
67
78const MAX_SUBJECT_LENGTH = 50 ;
@@ -10,104 +11,112 @@ const MIN_SUBJECT_LENGTH = 3;
1011const MIN_SUBJECT_LENGTH_ERROR_MESSAGE = `The subject must have at least ${ MIN_SUBJECT_LENGTH } characters` ;
1112
1213module . exports = {
13- prompter : ( cz , commit ) => {
14- inquirer . prompt ( [
14+ prompter ( cz , commit ) {
15+ return inquirer . prompt ( [
1516 {
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'
5354 } ,
5455 {
55- type : 'limitedInput' ,
56- name : 'subject' ,
57- maxLength : MAX_SUBJECT_LENGTH ,
5856 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 ;
6165 } ,
62- validate : ( input ) => input . length >= MIN_SUBJECT_LENGTH || MIN_SUBJECT_LENGTH_ERROR_MESSAGE ,
6366 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
6572 } ,
6673 {
67- type : 'input ' ,
74+ message : 'Provide a longer description of the change:\n ' ,
6875 name : 'body' ,
69- message : 'Provide a longer description of the change:\n '
76+ type : 'input '
7077 } ,
7178 {
72- type : 'input ' ,
79+ message : 'List any breaking changes:\n BREAKING CHANGE: ' ,
7380 name : 'breaking' ,
74- message : 'List any breaking changes:\n BREAKING CHANGE: '
81+ type : 'input '
7582 } ,
7683 {
77- type : 'input ' ,
84+ message : 'Reference any task that this commit closes:\n Issues: ' ,
7885 name : 'footer' ,
79- message : 'Reference any task that this commit closes:\n Issues: '
86+ type : 'input '
8087 }
8188 ] )
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+ } ;
8895
89- const head = answers . type + ': ' + answers . subject ;
96+ const head = answers . type + ': ' + answers . subject ;
9097
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 ) ;
95102
96- let msg = head ;
103+ let msg ;
97104
98- if ( body ) {
99- msg += '\n\n' + body ;
100- }
105+ msg = head ;
101106
102- if ( breaking ) {
103- msg += '\n\n' + 'BREAKING CHANGE: ' + breaking ;
104- }
107+ if ( body ) {
108+ msg += '\n\n' + body ;
109+ }
105110
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+ }
109118
110- commit ( msg ) ;
111- } ) ;
119+ return commit ( msg ) ;
120+ } ) ;
112121 }
113- }
122+ } ;
0 commit comments