Skip to content

Instantly share code, notes, and snippets.

@konsumer
Created January 20, 2015 09:38
Show Gist options
  • Save konsumer/2fdf01638ff3c7dcc24d to your computer and use it in GitHub Desktop.
Save konsumer/2fdf01638ff3c7dcc24d to your computer and use it in GitHub Desktop.
Bump script for npm auto-deploy
var fs = require('fs');
var exec = require('child_process').exec;
exports = function(file, cb){
var pkg = JSON.parse(fs.readFileSync(file));
var v = pkg.version.split('.');
v[2]++;
pkg.version = v.join('.');
fs.writeFile(file, JSON.stringify(pkg,null,2), function(err){
if (err) return cb(err);
exec('git add -A && git commit -am "bump to v"' + pkg.version + ' && git tag v' + pkg.version + '&& git push --tags && git push', function(err, stdout, stderr){
if (err) return cb(err);
cb(null, pkg.version);
});
});
};
if (!module.parent) {
var ver = exports(__dirname + '/package.json', function(err, version){
if (err){
console.error(err);
process.exit(1);
}
console.log('\033[32m ↑ bumped to \033[39mv' + version);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment