@@ -296,34 +296,50 @@ module.exports = function(grunt) {
296
296
var done = grunt . task . current . async ( ) ;
297
297
var child = grunt . util . spawn ( {
298
298
cmd :process . platform === 'win32' ? 'git.cmd' : 'git' ,
299
- args :[ 'log' , changeFrom + '..' + changeTo , '--oneline' ]
299
+ args : [
300
+ 'log' ,
301
+ changeFrom + '..' + changeTo ,
302
+ '--format=%H%n%s%n%b%n==END=='
303
+ ]
300
304
} , function ( err , result , code ) {
301
305
302
- var changelog = {
303
- chore : { } , demo : { } , docs : { } , feat : { } , fix : { } , refactor : { } , style : { } , test : { }
304
- } ;
306
+ var changelog = { } ;
307
+ function addChange ( changeType , component , change ) {
308
+ if ( ! changelog [ changeType ] ) {
309
+ changelog [ changeType ] = { } ;
310
+ }
311
+ if ( ! changelog [ changeType ] [ component ] ) {
312
+ changelog [ changeType ] [ component ] = [ ] ;
313
+ }
314
+ changelog [ changeType ] [ component ] . push ( change ) ;
315
+ }
305
316
306
317
var COMMIT_MSG_REGEXP = / ^ ( c h o r e | d e m o | d o c s | f e a t | f i x | r e f a c t o r | s t y l e | t e s t ) \( ( .+ ) \) : ? ( .+ ) $ / ;
307
- var gitlog = ( '' + result ) . split ( '\n' ) . reverse ( ) ;
318
+ var gitlog = result . toString ( ) . split ( '\n==END== \n' ) . reverse ( ) ;
308
319
309
320
if ( code ) {
310
321
grunt . log . error ( err ) ;
311
322
done ( false ) ;
312
323
} else {
313
324
314
325
gitlog . forEach ( function ( logItem ) {
315
- var sha1 = logItem . slice ( 0 , 7 ) ;
316
- var fullMsg = logItem . slice ( 8 ) ;
326
+ var lines = logItem . split ( '\n' ) ;
327
+ var sha1 = lines . shift ( ) . substr ( 0 , 8 ) ; //Only first 7 of sha1
328
+ var subject = lines . shift ( ) ;
317
329
318
- var msgMatches = fullMsg . match ( COMMIT_MSG_REGEXP ) ;
330
+ var msgMatches = subject . match ( COMMIT_MSG_REGEXP ) ;
319
331
var changeType = msgMatches [ 1 ] ;
320
- var directive = msgMatches [ 2 ] ;
321
- var directiveMsg = msgMatches [ 3 ] ;
322
-
323
- if ( ! changelog [ changeType ] [ directive ] ) {
324
- changelog [ changeType ] [ directive ] = [ ] ;
332
+ var component = msgMatches [ 2 ] ;
333
+ var componentMsg = msgMatches [ 3 ] ;
334
+
335
+ var breaking = logItem . match ( / B R E A K I N G C H A N G E : ( [ \s \S ] * ) / ) ;
336
+ if ( breaking ) {
337
+ addChange ( 'breaking' , component , {
338
+ sha1 : sha1 ,
339
+ msg : breaking [ 1 ]
340
+ } ) ;
325
341
}
326
- changelog [ changeType ] [ directive ] . push ( { sha1 :sha1 , msg :directiveMsg } ) ;
342
+ addChange ( changeType , component , { sha1 :sha1 , msg :componentMsg } ) ;
327
343
} ) ;
328
344
329
345
console . log ( grunt . template . process ( grunt . file . read ( 'misc/changelog.tpl.md' ) , { data : {
0 commit comments