From 045abfbf1362888119c3964e9c698610b6ba4bec Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Tue, 27 Sep 2016 01:44:05 -0400 Subject: [PATCH] feat(gen:gulp): port changelog code to gulp [skip ci] --- gulpfile.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 59 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index f0cb747c6..5deea9cc1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,6 +16,7 @@ const runSequence = require('run-sequence'); const merge = require('merge-stream'); const shell = require('shelljs'); const ghPages = require('gulp-gh-pages'); +const conventionalChangelog = require('gulp-conventional-changelog'); var watching = false; @@ -194,3 +195,60 @@ gulp.task('gh-pages', () => { gulp.task('docs', cb => { return runSequence('daux', 'copy_docs_images', 'gh-pages', cb); }); + +let finalizeContext = function(context, writerOpts, commits, keyCommit) { + var gitSemverTags = context.gitSemverTags; + var commitGroups = context.commitGroups; + + if((!context.currentTag || !context.previousTag) && keyCommit) { + var match = /tag:\s*(.+?)[,\)]/gi.exec(keyCommit.gitTags); + var currentTag = context.currentTag = context.currentTag || match ? match[1] : null; + var index = gitSemverTags.indexOf(currentTag); + var previousTag = context.previousTag = gitSemverTags[index + 1]; + + if(!previousTag) { + if(options.append) { + context.previousTag = context.previousTag || commits[0] ? commits[0].hash : null; + } else { + context.previousTag = context.previousTag || commits[commits.length - 1] ? commits[commits.length - 1].hash : null; + } + } + } else { + context.previousTag = context.previousTag || gitSemverTags[0]; + context.currentTag = context.currentTag || 'v' + context.version; + } + + if(typeof context.linkCompare !== 'boolean' && context.previousTag && context.currentTag) { + context.linkCompare = true; + } + + if(Array.isArray(commitGroups)) { + for(var i = 0, commitGroupsLength = commitGroups.length; i < commitGroupsLength; i++) { + var commits = commitGroups[i].commits; + if(Array.isArray(commits)) { + for(var n = 1, commitsLength = commits.length; n < commitsLength; n++) { + var commit = commits[n], prevCommit = commits[n - 1]; + if(commit.scope && commit.scope === prevCommit.scope) { + commit.subScope = true; + if(prevCommit.scope && !prevCommit.subScope) { + prevCommit.leadScope = true; + } + } + } + } + } + } + return context; +}; +let commitPartial = fs.readFileSync(path.resolve(__dirname, 'task-utils/changelog-templates/commit.hbs')).toString(); + +gulp.task('changelog', () => { + return gulp.src('CHANGELOG.md', {buffer: false}) + .pipe(conventionalChangelog({ + preset: 'angular' + }, {/*context*/}, {/*git-raw-commits*/}, {/*conventional-commits-parser*/}, {/*conventional-changelog-writer*/ + finalizeContext, + commitPartial + })) + .pipe(gulp.dest('./')); +}); diff --git a/package.json b/package.json index f5ee4c24a..128b1ef4b 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "grunt-mocha-test": "^0.12.7", "grunt-release": "^0.14.0", "gulp": "^3.9.1", + "gulp-conventional-changelog": "^1.1.0", "gulp-gh-pages": "^0.5.4", "gulp-if": "^2.0.1", "gulp-mocha": "^3.0.0",