Skip to content

Instantly share code, notes, and snippets.

@gcpantazis
Last active December 25, 2015 00:48
Show Gist options
  • Save gcpantazis/6889981 to your computer and use it in GitHub Desktop.
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.
// 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\'');
@gcpantazis
Copy link
Author

Need to be able to configure this more precisely; this could obviously replace unintended matches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment