npub
Version:
publishing tool for your node projects hosted on github
60 lines (53 loc) • 1.59 kB
JavaScript
// Generated by CoffeeScript 1.9.1
var debug, fs, mkdirp, repeat, touch;
fs = require('fs');
mkdirp = require('mkdirp');
touch = require('touch');
debug = require('debug')('changelog');
repeat = function(pattern, count) {
var arr, idx;
arr = (function() {
var i, ref, results;
results = [];
for (idx = i = 1, ref = count; 1 <= ref ? i <= ref : i >= ref; idx = 1 <= ref ? ++i : --i) {
results.push(pattern);
}
return results;
})();
return arr.join('');
};
module.exports = function(dir, git) {
var changelogPath;
changelogPath = dir + "/CHANGELOG.md";
return {
build: function(version, callback) {
var currentChangelog;
debug("build");
touch.sync(changelogPath);
currentChangelog = fs.readFileSync(changelogPath);
return git.diffSinceLastTag(function(err, commits) {
var completeDiff;
if (err != null) {
return callback(err, commits);
}
completeDiff = [version, repeat("-", version.length), commits, currentChangelog].join("\n");
debug("prepend addition");
return callback(null, completeDiff);
});
},
write: function(changelog, filePath) {
mkdirp.sync('/tmp/npub');
fs.writeFileSync(filePath, changelog, {
flag: 'w'
});
return debug("wrote " + filePath);
},
update: function(filePath) {
var newChangelog;
debug("update from " + filePath);
touch.sync(changelogPath);
newChangelog = fs.readFileSync(filePath);
return this.write(newChangelog, changelogPath);
}
};
};