Skip to content

Instantly share code, notes, and snippets.

@davemackintosh
Last active August 29, 2015 14:01
Show Gist options
  • Save davemackintosh/eae0a145040df7c463e1 to your computer and use it in GitHub Desktop.
Save davemackintosh/eae0a145040df7c463e1 to your computer and use it in GitHub Desktop.
Bump the version number in your package.json with this node tool. I use it in my makefiles for production releases.
/*!
* Copyright Dave Mackintosh. MIT License. 2014.
* Change the `fileName` var to where your package.json is;
* I usually put this file in `src/bin/` personally.
*/
"use strict";
{
let fs = require('fs');
let fileName = '../../package.json';
let conf = require(fileName);
let index = 2;
switch (process.argv[2]) {
case 'major':
index = 0;
break;
case 'minor':
index = 1;
break;
default:
index = 2;
break;
}
let parts = conf.version.split('.');
let buildAsNumber = parseInt(parts[index]);
parts[index] = ++buildAsNumber;
conf.version = parts.join('.');
fs.writeFile('package.json', JSON.stringify(conf, undefined, 2), {"flags": 'w'}, function(err) {
if (err) throw err;
console.log('saved ', fileName);
});
}
The MIT License (MIT)
Copyright (c) 2014 Dave Mackintosh
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment