@@ -4,7 +4,8 @@ import path = require('path');
4
4
import minimist = require( 'minimist' ) ;
5
5
import gulpUtils = require( 'gulp-util' ) ;
6
6
7
- let changelog = require ( 'gulp-conventional-changelog' ) ;
7
+ const changelog = require ( 'gulp-conventional-changelog' ) ;
8
+ const semver = require ( 'semver' ) ;
8
9
9
10
const args = minimist ( process . argv . slice ( 2 ) ) ;
10
11
const chalk = gulpUtils . colors ;
@@ -19,31 +20,33 @@ const VERSION = args['version'] || require(path.join(ROOT,'package.json')).versi
19
20
*/
20
21
task ( 'changelog' , function ( ) {
21
22
22
- var changelogPath = path . join ( ROOT , 'CHANGELOG.md' ) ;
23
- var previousTag = getLatestTag ( ) ;
24
- var currentTag = 'v' + VERSION ;
25
- var contextOptions = {
23
+ const changelogPath = path . join ( ROOT , 'CHANGELOG.md' ) ;
24
+ const previousTag = getLatestTag ( ) ;
25
+ const currentTag = 'v' + VERSION ;
26
+ const fromSHA = SHA || previousTag . sha ;
27
+ const contextOptions = {
26
28
version : VERSION ,
27
29
previousTag : previousTag . name ,
28
30
currentTag : currentTag
29
31
} ;
32
+
30
33
/* Validate different fork points for the changelog generation */
31
34
if ( previousTag . name === currentTag && ! SHA ) {
32
35
log ( chalk . yellow ( 'Warning: You are generating a changelog by comparing the same versions.' ) ) ;
33
36
} else if ( SHA ) {
34
37
log ( 'Generating changelog from commit ' + getShortSha ( SHA ) + '...' ) ;
35
38
} else {
36
- var shortSha = getShortSha ( previousTag . sha ) ;
39
+ let shortSha = getShortSha ( previousTag . sha ) ;
37
40
log ( 'Generating changelog from tag ' + previousTag . name + ' (' + shortSha + ')' ) ;
38
41
}
39
42
40
- return src ( changelogPath , {
41
- buffer : false
42
- } ) . pipe ( changelog ( {
43
- preset : 'angular'
44
- } , contextOptions , {
45
- from : SHA || previousTag . sha
46
- } ) . pipe ( dest ( ROOT ) ) ) ;
43
+ return src ( changelogPath )
44
+ . pipe ( changelog ( { preset : 'angular' } , contextOptions , {
45
+ from : fromSHA
46
+ } , { } , {
47
+ generateOn : _shouldGenerate
48
+ } ) )
49
+ . pipe ( dest ( ROOT ) ) ;
47
50
48
51
} ) ;
49
52
@@ -68,3 +71,17 @@ function getLatestTag() {
68
71
function getShortSha ( sha ) {
69
72
return sha . substring ( 0 , 7 ) ;
70
73
}
74
+
75
+ /**
76
+ * Function which determines whether the conventional-changelog should create
77
+ * a new section in the CHANGELOG or not.
78
+ *
79
+ * - If a SHA is specified, the first checked SHA will be used to generate a new section.
80
+ * - By default it just checks if the commit is tagged and if the version is valid.
81
+ *
82
+ * @param {Object= } commit Parsed commit from the conventional-changelog-parser.
83
+ */
84
+ let _isGenerated = 0 ;
85
+ function _shouldGenerate ( commit ) {
86
+ return SHA ? _isGenerated ++ === 0 : semver . valid ( commit . version ) ;
87
+ }
0 commit comments