diff options
| author | Vojta Jina | 2012-03-17 03:10:03 -0700 | 
|---|---|---|
| committer | Igor Minar | 2012-03-29 07:22:13 -0700 | 
| commit | 4557881cf84f168855fc8615e174f24d6c2dd6ce (patch) | |
| tree | fbc956578b95dc1af6ffa85158fe55fbba44b175 /version.js | |
| parent | af0ad6561c0d75c4f155b07e9cfc36a983af55bd (diff) | |
| download | angular.js-4557881cf84f168855fc8615e174f24d6c2dd6ce.tar.bz2 | |
chore(release scripts): auto release scripts
Diffstat (limited to 'version.js')
| -rwxr-xr-x | version.js | 67 | 
1 files changed, 67 insertions, 0 deletions
diff --git a/version.js b/version.js new file mode 100755 index 00000000..f985327e --- /dev/null +++ b/version.js @@ -0,0 +1,67 @@ +#!/usr/bin/env node + +var FILE = 'version.yaml'; +var fs = require('fs'); +var optimist = require('optimist'); + +optimist +  .usage('Manage ' + FILE + '.\nUsage: $0 [options]') +  .describe('remove-snapshot', 'Remove -snapshot suffix.') +  .describe('minor-bump', 'Bump minor version one step.') +  .describe('minor-next', 'Return next minor version.') +  .describe('current', 'Return current verion') +  .describe('help', 'Show usage'); + + +var bumpMinor = function(version) { +  var parts = version.split('.'); +  var last = parts.pop(); + +  var rc = last.match(/(\d*)rc(\d*)/); +  if (rc) { +    parts.push(rc[1] + 'rc' + (parseInt(rc[2], 10) + 1)); +  } else { +    parts.push('' + (parseInt(last, 10) + 1)); +  } + +  return parts.join('.'); +}; + +fs.readFile(FILE, 'utf8', function(err, content) { +  var version = content.match(/version\:\s([^\-\n]*)/)[1]; + +  var args = optimist.argv; +  if (args['remove-snapshot']) { +    fs.writeFile(FILE, content.replace('-snapshot', ''), function(err) { +      if (!err) { +        console.log('Version updated (removed -snapshot).'); +        process.exit(0); +      } else { +        console.error('Version update failed.'); +        process.exit(1); +      } +    }); +  } else if (args['minor-next']) { +    process.stdout.write(bumpMinor(version) + '\n'); +    process.exit(0); +  } else if (args['current']) { +    process.stdout.write(version + '\n'); +    process.exit(0); +  } else if (args['minor-bump']) { +    var bumped = bumpMinor(version); + +    if (!content.match(/\-snapshot/)) bumped += '-snapshot'; +    fs.writeFile(FILE, content.replace(version, bumped), function(err) { +      if (!err) { +        console.log('Version updated (bumped to ' + bumped + ').'); +        process.exit(0); +      } else { +        console.error('Version update failed.'); +        process.exit(1); +      } +    }); +  } else { +    console.log(optimist.help()); +    process.exit(args['help'] ? 0 : 1); +  } +});  | 
