Last active
December 31, 2015 15:09
-
-
Save makomweb/8004863 to your computer and use it in GitHub Desktop.
Write all the GIT commit messages since the last tag (on the current branch) into a changelog file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var usage_description = "Usage: node create_changelog.js MyChangelog.txt \"Changelog for nightly build version 0.9.0.1\""; | |
var args = ParseArguments(); | |
var spawn = require('child_process').spawn; | |
var fs = require('fs'); | |
var prc = spawn('git', ['describe', '--tags', '--abbrev=0']); | |
prc.stdout.setEncoding('utf8'); | |
prc.stdout.on('data', function (data) { | |
var str = data.toString(); | |
var lines = str.split(/(\r?\n)/g); | |
var tag = lines[0]; | |
since(tag, function(messages) { | |
var path = args[0]; | |
var stream = fs.createWriteStream(path); | |
stream.once('open', function(fd) { | |
var header = args[1]; | |
stream.write(header + "\n"); | |
messages.forEach(function(m) { | |
stream.write(m + "\n"); | |
}); | |
stream.end(); | |
console.log(path + ' was written successfully.'); | |
}); | |
}); | |
}); | |
function since(tag, callback){ | |
var prc = spawn('git', ['cherry', '-v', tag]); | |
prc.stdout.setEncoding('utf8'); | |
prc.stdout.on('data', function (data) { | |
var str = data.toString() | |
var lines = str.split(/(\r?\n)/g); | |
var messages = []; | |
lines.forEach(function(line){ | |
if (/\S/.test(line)) | |
messages.push('* ' + line.split('* ')[1]); | |
}); | |
callback(messages); | |
}); | |
} | |
function ParseArguments() { | |
var args = []; | |
process.argv.slice(2).forEach(function (a) { | |
args.push(a); | |
}); | |
if (args.length != 2) | |
throw usage_description; | |
return args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment