Skip to content

Commit

Permalink
Merge pull request box#59 from Box/changelog
Browse files Browse the repository at this point in the history
Add changelog generation
  • Loading branch information
Nicholas Zakas committed Mar 30, 2015
2 parents 214a35a + 6413f79 commit 5748663
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1.0.2 - February 20, 2015

* v1.0.2 (Jeff Tan)
* Detect circular service dependencies (fixes #51) (Nicholas C. Zakas)
51 changes: 50 additions & 1 deletion Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
require('shelljs/make');

var util = require('util'),
nodeCLI = require('shelljs-nodecli');
nodeCLI = require('shelljs-nodecli'),
semver = require('semver'),
dateformat = require('dateformat');

//------------------------------------------------------------------------------
// Data
Expand Down Expand Up @@ -101,6 +103,22 @@ function getSourceDirectories() {
return result;
}

/**
* Gets the git tags that represent versions.
* @returns {string[]} An array of tags in the git repo.
* @private
*/
function getVersionTags() {
var tags = exec("git tag", { silent: true }).output.trim().split(/\n/g);

return tags.reduce(function(list, tag) {
if (semver.valid(tag)) {
list.push(tag);
}
return list;
}, []).sort(semver.compare);
}

/**
* Creates a release version tag and pushes to origin.
* @param {string} type The type of release to do (patch, minor, major)
Expand All @@ -110,6 +128,7 @@ function release(type) {
target.test();

target.dist();
target.changelog();

execOrExit('git add -A');
execOrExit('git commit --amend --no-edit');
Expand Down Expand Up @@ -191,6 +210,36 @@ target.dist = function() {
cp(minDistFilename, minDistFilename.replace('.min.js', '-' + pkg.version + '.min.js'));
};

target.changelog = function() {

// get most recent two tags
var tags = getVersionTags(),
rangeTags = tags.slice(tags.length - 2),
now = new Date(),
timestamp = dateformat(now, 'mmmm d, yyyy');

// output header
(rangeTags[1] + ' - ' + timestamp + '\n').to('CHANGELOG.tmp');

// get log statements
var logs = exec('git log --pretty=format:"* %s (%an)" ' + rangeTags.join('..'), {silent: true}).output.split(/\n/g);
logs = logs.filter(function(line) {
return line.indexOf('Merge pull request') === -1 && line.indexOf('Merge branch') === -1;
});
logs.push(''); // to create empty lines
logs.unshift('');

// output log statements
logs.join('\n').toEnd('CHANGELOG.tmp');

// switch-o change-o
cat('CHANGELOG.tmp', 'CHANGELOG.md').to('CHANGELOG.md.tmp');
rm('CHANGELOG.tmp');
rm('CHANGELOG.md');
mv('CHANGELOG.md.tmp', 'CHANGELOG.md');
};


target.patch = function() {
release('patch');
};
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"private": true,
"devDependencies": {
"assertive-chai": "^1.0.2",
"dateformat": "^1.0.11",
"jquery": "^1.11.1",
"karma": "^0.12.31",
"karma-coverage": "^0.2.7",
Expand All @@ -23,6 +24,7 @@
"karma-threshold-reporter": "^0.1.15",
"mocha": "^2.2.1",
"phantomjs": "^1.9.16",
"semver": "^4.3.3",
"shelljs": "^0.4.0",
"shelljs-nodecli": "^0.1.1",
"sinon": "^1.14.1",
Expand Down

0 comments on commit 5748663

Please sign in to comment.