Skip to content

Commit

Permalink
Gruntfile: update changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Apr 27, 2017
1 parent 03252f7 commit eea9d6d
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions Gruntfile.js
Expand Up @@ -100,42 +100,67 @@ module.exports = function(grunt) {
grunt.task.run('nodeunit');
});

grunt.registerTask('changelog', '`changelog:0.0.0--0.0.2` or `changelog`', (range) => {
grunt.registerTask('changelog', '"changelog", "changelog:v0.0.0..v0.0.2" or "changelog:v0.0.0"', (arg) => {
var done = grunt.task.current.async();
var tags = cp.execSync('git tag --sort version:refname').toString().split('\n');
var tagIndex = -1;
var range;
var revisionRange;

if (!range) {
if (!arg) {
// grunt changelog
range = cp.execSync('git tag --sort version:refname').toString().split('\n');
range = tags.filter(Boolean).slice(-2);
} else {
// grunt changelog:previous--present
range = range.split('--');
if (arg.includes('..')) {
// grunt changelog:<revision-range>
if (!arg.startsWith('v') || !arg.includes('..v')) {
range = arg.split('..').map(tag => tag.startsWith('v') ? tag : `v${tag}`);
} else {
// arg is a well formed <revision-range>
revisionRange = arg;
}
} else {
// grunt changelog:<revision>
if (!arg.startsWith('v')) {
arg = `v${arg}`;
}

tagIndex = tags.indexOf(arg);
range = [tags[tagIndex - 1], tags[tagIndex]];
}
}

range = range.filter(Boolean).reverse();
if (!range && revisionRange) {
range = revisionRange.split('..');
}

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

cp.exec(`git log --format='|%h|%s|' ${revisionRange}`, (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}
${rows.join('\n')}
`;
}

0 comments on commit eea9d6d

Please sign in to comment.