Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Update CLI for tag
Browse files Browse the repository at this point in the history
  • Loading branch information
boennemann committed Feb 7, 2013
1 parent f2a9683 commit 9c2ad36
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions bin/semver-sync
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,41 @@ var ERROR = '[ERROR] '.bold.red

var argv = optimist
.usage('Synchronizes version numbers accross package.json, component.json and other source files of your choosing.' +
'\n Usage: ' + 'semver-sync -s [source list] -b [release type].'.bold)
'\n Usage: ' + 'semver-sync -s [source list] -b [release type].'.bold)
.option('b', {
alias: 'bump',
describe: 'Bump the version number in package.json, component.json and all other specified source files. '
+ 'It can take one of the following values: ' + 'major, minor, patch'.bold + '. If no value is specified, ' +
'it defaults to ' + 'patch'.bold + '.'})
.option('s', {
alias: 'sources',
describe: 'Declare the JavaScript files in which the version number will be updated. If not explicitly '
describe: 'Declare the JavaScript files in which the version number will be updated. If not explicitly '
+ 'specified, it is read from the package.json "versionedSources" property. If it\'s not present in the '
+ 'package.json and not explicitly specified, only component.json and package.json will be synced. Optional.'})
.option('v', {
alias: 'verify',
describe: 'Verifies that package.json, component.json and all other source files have the same version '
describe: 'Verifies that package.json, component.json and all other source files have the same version '
+ 'number and checks if it conforms to the semver specification.'})
.option('t', {
alias: 'tag',
describe: 'Bump the version number, commit the changes to package.json, component.json and all other specified source files '
+ 'and create a git tag with the current version. '
+ 'It can take one of the following values: ' + 'major, minor, patch'.bold + '. If no value is specified, ' +
'it defaults to ' + 'patch'.bold + '.'})
.argv
;



if (argv.help || (!argv.verify && !argv.bump)) {
if (argv.help || (!argv.verify && !argv.bump && !argv.tag)) {
console.log(optimist.help());
process.exit(0);
}

if (argv.tag && !argv.bump) {
argv.bump = argv.tag;
}

if (argv.bump === true) {
argv.bump = 'patch';
}
Expand Down Expand Up @@ -69,7 +79,7 @@ var verify = function (sources, version) {
var errSources = [];
sources.forEach(function (source) {
if (sync.getVersion(source).version !== version) {
errSources.push(source);
errSources.push(source);
}
});

Expand All @@ -78,14 +88,14 @@ var verify = function (sources, version) {
process.exit(1);
} else {
console.log(SUCCESS + 'Everything is in sync, the version number is ' + version.bold.green + '.');
}
}
}

if (argv.verify) {
verify(sources, version);
}

if (argv.bump) {
if (argv.bump || argv.tag) {
verify(sources, version);
if (!~['major', 'minor', 'patch'].indexOf(argv.bump)) {
console.log(ERROR + 'Invalid release name specified, please use ' + 'major, minor or patch.'.bold);
Expand All @@ -94,6 +104,12 @@ if (argv.bump) {

version = semver.inc(version, argv.bump);
sync.setVersion(sources, version);
console.log(SUCCESS + 'Version number was updated to ' + version.bold.green + ' in '
console.log(SUCCESS + 'Version number was updated to ' + version.bold.green + ' in '
+ sources.join(', ').bold + '.');

if (argv.tag) {
sync.commitSourcesAndCreateTag(sources, version, function () {
console.log(SUCCESS + 'Files have been commited and tag ' + ('v' + version).bold.green + ' was created.');
});
}
}

0 comments on commit 9c2ad36

Please sign in to comment.