nextversion.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Licensed to the Apache Software Foundation (ASF) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The ASF licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. 'use strict';
  18. function getNextVersion (previousVersion) {
  19. // get previous version number
  20. // NOTE:
  21. // only versions of the form N.x are accepted
  22. var previousVersionMatch = previousVersion.match(/^(\d+)\.x$/);
  23. if (!previousVersionMatch) {
  24. throw 'invalid version';
  25. }
  26. // get next major version
  27. var previousMajor = previousVersionMatch[1];
  28. var nextMajor = parseInt(previousMajor) + 1;
  29. // create next version
  30. var nextVersion = nextMajor + '.x';
  31. return nextVersion;
  32. }
  33. function main () {
  34. // get arg
  35. var previousVersion = process.argv[2];
  36. if (!previousVersion) {
  37. console.error('no version specified');
  38. process.exit(1);
  39. }
  40. // try to get the next version
  41. var nextVersion = null;
  42. try {
  43. nextVersion = getNextVersion(previousVersion);
  44. } catch (e) {
  45. console.error(e);
  46. process.exit(1);
  47. }
  48. console.log(nextVersion);
  49. }
  50. module.exports = {
  51. getNextVersion: getNextVersion
  52. };
  53. if (require.main === module) {
  54. main();
  55. }