Last active
December 25, 2015 00:48
-
-
Save gcpantazis/6889981 to your computer and use it in GitHub Desktop.
Semantic version update for projects with a package.json in the target folder.
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
// Semantic Versioning Tool | |
// ======================== | |
// | |
// See: http://semver.org/ | |
// For projects with package.json in the target folder. | |
// | |
// * Author: George Pantazis | |
// | |
// * Usage: | |
// * Major (0.x.x -> 1.0.0) : `node version-update major` | |
// * Minor (x.0.x -> x.1.0) : `node version-update minor` | |
// * Patch (x.x.0 -> x.x.1) : `node version-update patch` | |
// * Custom (x.x.x -> 1.2.3) : `node version-update custom 1.2.3` | |
var exec = require('child_process').exec, | |
json = require('./package.json'), | |
newVersion, splitVersion; | |
if (process.argv[2] === 'custom') { | |
newVersion = process.argv[3]; | |
} else { | |
splitVersion = json.version.split('.'); | |
if (process.argv[2] === 'major') { | |
splitVersion[0] = splitVersion[0] * 1 + 1; | |
splitVersion[1] = 0; | |
splitVersion[2] = 0; | |
} | |
if (process.argv[2] === 'minor') { | |
splitVersion[1] = splitVersion[1] * 1 + 1; | |
splitVersion[2] = 0; | |
} | |
if (process.argv[2] === 'patch') { | |
splitVersion[2] = splitVersion[2] * 1 + 1; | |
} | |
newVersion = splitVersion.join('.'); | |
} | |
exec('find ./* -type f | xargs perl -pi -e \'s/' + json.version + '/' + newVersion + '/g\''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to be able to configure this more precisely; this could obviously replace unintended matches.