@@ -16,6 +16,7 @@ const runSequence = require('run-sequence'); |
16 | 16 | const merge = require('merge-stream'); |
17 | 17 | const shell = require('shelljs'); |
18 | 18 | const ghPages = require('gulp-gh-pages'); |
| 19 | +const conventionalChangelog = require('gulp-conventional-changelog'); |
19 | 20 |
|
20 | 21 | var watching = false; |
21 | 22 |
|
@@ -194,3 +195,60 @@ gulp.task('gh-pages', () => { |
194 | 195 | gulp.task('docs', cb => { |
195 | 196 | return runSequence('daux', 'copy_docs_images', 'gh-pages', cb); |
196 | 197 | }); |
| 198 | + |
| 199 | +let finalizeContext = function(context, writerOpts, commits, keyCommit) { |
| 200 | + var gitSemverTags = context.gitSemverTags; |
| 201 | + var commitGroups = context.commitGroups; |
| 202 | + |
| 203 | + if((!context.currentTag || !context.previousTag) && keyCommit) { |
| 204 | + var match = /tag:\s*(.+?)[,\)]/gi.exec(keyCommit.gitTags); |
| 205 | + var currentTag = context.currentTag = context.currentTag || match ? match[1] : null; |
| 206 | + var index = gitSemverTags.indexOf(currentTag); |
| 207 | + var previousTag = context.previousTag = gitSemverTags[index + 1]; |
| 208 | + |
| 209 | + if(!previousTag) { |
| 210 | + if(options.append) { |
| 211 | + context.previousTag = context.previousTag || commits[0] ? commits[0].hash : null; |
| 212 | + } else { |
| 213 | + context.previousTag = context.previousTag || commits[commits.length - 1] ? commits[commits.length - 1].hash : null; |
| 214 | + } |
| 215 | + } |
| 216 | + } else { |
| 217 | + context.previousTag = context.previousTag || gitSemverTags[0]; |
| 218 | + context.currentTag = context.currentTag || 'v' + context.version; |
| 219 | + } |
| 220 | + |
| 221 | + if(typeof context.linkCompare !== 'boolean' && context.previousTag && context.currentTag) { |
| 222 | + context.linkCompare = true; |
| 223 | + } |
| 224 | + |
| 225 | + if(Array.isArray(commitGroups)) { |
| 226 | + for(var i = 0, commitGroupsLength = commitGroups.length; i < commitGroupsLength; i++) { |
| 227 | + var commits = commitGroups[i].commits; |
| 228 | + if(Array.isArray(commits)) { |
| 229 | + for(var n = 1, commitsLength = commits.length; n < commitsLength; n++) { |
| 230 | + var commit = commits[n], prevCommit = commits[n - 1]; |
| 231 | + if(commit.scope && commit.scope === prevCommit.scope) { |
| 232 | + commit.subScope = true; |
| 233 | + if(prevCommit.scope && !prevCommit.subScope) { |
| 234 | + prevCommit.leadScope = true; |
| 235 | + } |
| 236 | + } |
| 237 | + } |
| 238 | + } |
| 239 | + } |
| 240 | + } |
| 241 | + return context; |
| 242 | +}; |
| 243 | +let commitPartial = fs.readFileSync(path.resolve(__dirname, 'task-utils/changelog-templates/commit.hbs')).toString(); |
| 244 | + |
| 245 | +gulp.task('changelog', () => { |
| 246 | + return gulp.src('CHANGELOG.md', {buffer: false}) |
| 247 | + .pipe(conventionalChangelog({ |
| 248 | + preset: 'angular' |
| 249 | + }, {/*context*/}, {/*git-raw-commits*/}, {/*conventional-commits-parser*/}, {/*conventional-changelog-writer*/ |
| 250 | + finalizeContext, |
| 251 | + commitPartial |
| 252 | + })) |
| 253 | + .pipe(gulp.dest('./')); |
| 254 | +}); |