Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit f698717

Browse files
chore(build): add changelog task for grunt
1 parent d8cc019 commit f698717

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Diff for: Gruntfile.js

+49
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,55 @@ module.exports = function(grunt) {
287287
var options = ['--no-single-run', '--auto-watch'].concat(this.args);
288288
runTestacular('start', options);
289289
});
290+
291+
//changelog generation
292+
grunt.registerTask('changelog', 'generates changelog markdown from git commits', function () {
293+
294+
var changeFrom = this.args[0], changeTo = this.args[1] || 'HEAD';
295+
296+
var done = grunt.task.current.async();
297+
var child = grunt.util.spawn({
298+
cmd:process.platform === 'win32' ? 'git.cmd' : 'git',
299+
args:['log', changeFrom + '..' + changeTo, '--oneline']
300+
}, function (err, result, code) {
301+
302+
var changelog = {
303+
chore: {}, demo: {}, docs: {}, feat: {}, fix: {}, refactor: {}, style: {}, test: {}
304+
};
305+
306+
var COMMIT_MSG_REGEXP = /^(chore|demo|docs|feat|fix|refactor|style|test)\((.+)\):? (.+)$/;
307+
var gitlog = ('' + result).split('\n').reverse();
308+
309+
if (code) {
310+
grunt.log.error(err);
311+
done(false);
312+
} else {
313+
314+
gitlog.forEach(function (logItem) {
315+
var sha1 = logItem.slice(0, 7);
316+
var fullMsg = logItem.slice(8);
317+
318+
var msgMatches = fullMsg.match(COMMIT_MSG_REGEXP);
319+
var changeType = msgMatches[1];
320+
var directive = msgMatches[2];
321+
var directiveMsg = msgMatches[3];
322+
323+
if (!changelog[changeType][directive]) {
324+
changelog[changeType][directive] = [];
325+
}
326+
changelog[changeType][directive].push({sha1:sha1, msg:directiveMsg});
327+
});
328+
329+
console.log(grunt.template.process(grunt.file.read('misc/changelog.tpl.md'), {data: {
330+
changelog: changelog,
331+
today: grunt.template.today('yyyy-mm-dd'),
332+
version : grunt.config('pkg.version')
333+
}}));
334+
335+
done();
336+
}
337+
});
338+
});
290339

291340
return grunt;
292341
};

Diff for: misc/changelog.tpl.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# <%= version%> (<%= today%>)
2+
3+
## Features
4+
5+
<% _(changelog.feat).forEach(function(changes, directive) { %>- **<%= directive%>:**
6+
<% changes.forEach(function(change) { %> - <%= change.msg%> ([<%= change.sha1%>](https://github.com/angular-ui/bootstrap/commit/<%= change.sha1%>))
7+
<% }) %><% }) %>
8+
## Bug fixes
9+
10+
<% _(changelog.fix).forEach(function(changes, directive) { %>- **<%= directive%>:**
11+
<% changes.forEach(function(change) { %> - <%= change.msg%> ([<%= change.sha1%>](https://github.com/angular-ui/bootstrap/commit/<%= change.sha1%>))
12+
<% }) %><% }) %>

0 commit comments

Comments
 (0)