Skip to content

Commit

Permalink
feat(gen:gulp): port changelog code to gulp
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Awk34 committed Sep 27, 2016
1 parent ad44ee2 commit 045abfb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
58 changes: 58 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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('./'));
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 045abfb

Please sign in to comment.