9
9
// npm modules
10
10
import chalk from 'chalk' ;
11
11
import denodeify from 'denodeify' ;
12
+ import gitRawCommits from 'git-raw-commits' ;
12
13
import meow from 'meow' ;
13
14
import merge from 'lodash.merge' ;
14
15
import pick from 'lodash.pick' ;
@@ -52,10 +53,11 @@ const cli = meow({
52
53
} ,
53
54
// flag defaults
54
55
default : {
56
+ color : true ,
57
+ edit : false ,
55
58
from : null ,
56
- to : null ,
57
- e : true ,
58
59
preset : 'angular' ,
60
+ to : null ,
59
61
quiet : false
60
62
} ,
61
63
// fail on unknown
@@ -64,6 +66,20 @@ const cli = meow({
64
66
}
65
67
} ) ;
66
68
69
+ // Get commit messages
70
+ // TODO: move this to an own moduleddd
71
+ function getCommits ( options ) {
72
+ return new Promise ( ( resolve , reject ) => {
73
+ const data = [ ] ;
74
+ gitRawCommits ( options )
75
+ . on ( 'data' , chunk => data . push ( chunk . toString ( 'utf-8' ) ) )
76
+ . on ( 'error' , reject )
77
+ . on ( 'end' , ( ) => {
78
+ resolve ( data ) ;
79
+ } ) ;
80
+ } ) ;
81
+ }
82
+
67
83
// Get commit messages
68
84
// TODO: move this to an own module
69
85
async function getMessages ( settings ) {
@@ -72,9 +88,14 @@ async function getMessages(settings) {
72
88
if ( edit ) {
73
89
const editFile = await readFile ( `.git/COMMIT_EDITMSG` ) ;
74
90
return [ editFile . toString ( 'utf-8' ) ] ;
91
+ } else {
92
+ return await getCommits ( {
93
+ from,
94
+ to
95
+ } ) ;
75
96
}
76
97
77
- throw new Error ( `Reading from git history not supported yet.` ) ;
98
+ // throw new Error(`Reading from git history not supported yet.`);
78
99
}
79
100
80
101
// Resolve extend configs
@@ -159,6 +180,7 @@ async function main(options) {
159
180
} ) ;
160
181
161
182
if ( ! flags . quiet ) {
183
+ console . log ( `validating: ${ commit . split ( '\n' ) [ 0 ] } ` ) ;
162
184
console . log (
163
185
formatted
164
186
. join ( '\n' )
@@ -168,6 +190,8 @@ async function main(options) {
168
190
if ( report . errors . length > 0 ) {
169
191
throw new Error ( formatted [ formatted . length - 1 ] ) ;
170
192
}
193
+
194
+ console . log ( '' ) ;
171
195
} ) ) ;
172
196
}
173
197
0 commit comments