Skip to content

Commit

Permalink
Grunt: changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Nov 2, 2016
1 parent bf50c91 commit 14fa316
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// System Objects
var cp = require("child_process");
var path = require("path");

// Third Party Dependencies
var tags = require("common-tags");


module.exports = function(grunt) {

// Project configuration.
Expand Down Expand Up @@ -92,4 +100,44 @@ module.exports = function(grunt) {

grunt.task.run('nodeunit');
});

grunt.registerTask('changelog', '`changelog:0.0.0--0.0.2` or `changelog`', (range) => {
var done = grunt.task.current.async();

if (!range) {
// grunt changelog
range = cp.execSync('git tag --sort version:refname').toString().split('\n');
} else {
// grunt changelog:previous--present
range = range.split('--');
}

range = range.filter(Boolean).reverse();

cp.exec(`git log --format='|%h|%s|' ${range[1]}..${range[0]}`, (error, result) => {
if (error) {
console.log(error.message);
return;
}

var rows = result.split('\n').filter(commit => {
return !commit.includes('|Merge ') && !commit.includes(range[0]);
}).join('\n');

// Extra whitespace above and below makes it easier to quickly copy/paste from terminal
grunt.log.writeln(`\n\n${changelog(rows)}\n\n`);

done();
});
});

};

function changelog(rows) {
return tags.stripIndent `
| Commit | Message/Description |
| ------ | ------------------- |
${rows}
`;
}

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"license": "MIT",
"devDependencies": {
"common-tags": "^1.3.1",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-contrib-jshint": "^1.0.0",
Expand Down

0 comments on commit 14fa316

Please sign in to comment.