Skip to content

Commit 045abfb

Browse files
committed
feat(gen:gulp): port changelog code to gulp
[skip ci]
1 parent ad44ee2 commit 045abfb

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Diff for: gulpfile.js

+58
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const runSequence = require('run-sequence');
1616
const merge = require('merge-stream');
1717
const shell = require('shelljs');
1818
const ghPages = require('gulp-gh-pages');
19+
const conventionalChangelog = require('gulp-conventional-changelog');
1920

2021
var watching = false;
2122

@@ -194,3 +195,60 @@ gulp.task('gh-pages', () => {
194195
gulp.task('docs', cb => {
195196
return runSequence('daux', 'copy_docs_images', 'gh-pages', cb);
196197
});
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+
});

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"grunt-mocha-test": "^0.12.7",
7272
"grunt-release": "^0.14.0",
7373
"gulp": "^3.9.1",
74+
"gulp-conventional-changelog": "^1.1.0",
7475
"gulp-gh-pages": "^0.5.4",
7576
"gulp-if": "^2.0.1",
7677
"gulp-mocha": "^3.0.0",

0 commit comments

Comments
 (0)