release.js
function getNewVersion () {
    header();
    const options = getVersionOptions(oldVersion);
    let key, version;
    log(`The current version is ${oldVersion.cyan}.`);
    log('');
    log('What should the next version be?');
    for (key in options) { log((+key + 1) + ') ' + options[ key ].cyan); }
    log('');
    write('Please select a new version: ');
    const type = prompt();

    if (options[ type - 1 ]) version = options[ type - 1 ];
    else if (type.match(/^\d+\.\d+\.\d+(-rc\.?\d+)?$/)) version = type;
    else throw new Error('Your entry was invalid.');

    log('');
    log('The new version will be ' + version.cyan + '.');
    write(`Is this correct? ${"[yes/no]".cyan} `);
    return prompt() === 'yes' ? version : getNewVersion();

    function getVersionOptions (version) {
      return version.match(/-rc\.?\d+$/)
          ? [increment(version, 'rc'), increment(version, 'minor')]
          : [increment(version, 'patch'), addRC(increment(version, 'minor'))];

      function increment (versionString, type) {
        const version = parseVersion(versionString);
        if (version.rc) {
          switch (type) {
            case 'minor': version.rc = 0; break;
            case 'rc': version.rc++; break;
          }
        } else {
          version[ type ]++;
          // reset any version numbers lower than the one changed
          switch (type) {
            case 'minor': version.patch = 0;
            case 'patch': version.rc = 0;
          }
        }
        return getVersionString(version);

        function parseVersion (version) {
          const parts = version.split(/-rc\.|\./g);
          return {
            string: version,
            major:  parts[ 0 ],
            minor:  parts[ 1 ],
            patch:  parts[ 2 ],
            rc:     parts[ 3 ] || 0
          };
        }

        function getVersionString (version) {
          let str = version.major + '.' + version.minor + '.' + version.patch;
          if (version.rc) str += '-rc.' + version.rc;
          return str;
        }
      }

      function addRC (str) {
        return str + '-rc.1';
      }
    }
  }
function getNewVersion () {
    header();
    const options = getVersionOptions(oldVersion);
    let key, version;
    log(`The current version is ${oldVersion.cyan}.`);
    log('');
    log('What should the next version be?');
    for (key in options) { log((+key + 1) + ') ' + options[ key ].cyan); }
    log('');
    write('Please select a new version: ');
    const type = prompt();

    if (options[ type - 1 ]) version = options[ type - 1 ];
    else if (type.match(/^\d+\.\d+\.\d+(-rc\.?\d+)?$/)) version = type;
    else throw new Error('Your entry was invalid.');

    log('');
    log('The new version will be ' + version.cyan + '.');
    write(`Is this correct? ${"[yes/no]".cyan} `);
    return prompt() === 'yes' ? version : getNewVersion();

    function getVersionOptions (version) {
      return version.match(/-rc\.?\d+$/)
          ? [increment(version, 'rc'), increment(version, 'minor')]
          : [increment(version, 'patch'), addRC(increment(version, 'minor'))];

      function increment (versionString, type) {
        const version = parseVersion(versionString);
        if (version.rc) {
          switch (type) {
            case 'minor': version.rc = 0; break;
            case 'rc': version.rc++; break;
          }
        } else {
          version[ type ]++;
          // reset any version numbers lower than the one changed
          switch (type) {
            case 'minor': version.patch = 0;
            case 'patch': version.rc = 0;
          }
        }
        return getVersionString(version);

        function parseVersion (version) {
          const parts = version.split(/-rc\.|\./g);
          return {
            string: version,
            major:  parts[ 0 ],
            minor:  parts[ 1 ],
            patch:  parts[ 2 ],
            rc:     parts[ 3 ] || 0
          };
        }

        function getVersionString (version) {
          let str = version.major + '.' + version.minor + '.' + version.patch;
          if (version.rc) str += '-rc.' + version.rc;
          return str;
        }
      }

      function addRC (str) {
        return str + '-rc.1';
      }
    }
  }
function getNewVersion ( ) { header ( ) ; const options = getVersionOptions ( oldVersion ) ; let key , version ; log ( ` ${ oldVersion . cyan } ` ) ; log ( '' ) ; log ( 'What should the next version be?' ) ; for ( key in options ) { log ( ( + key + 1 ) + ') ' + options [ key ] . cyan ) ; } log ( '' ) ; write ( 'Please select a new version: ' ) ; const type = prompt ( ) ; if ( options [ type - 1 ] ) version = options [ type - 1 ] ; else if ( type . match ( / ^\d+\.\d+\.\d+(-rc\.?\d+)?$ / ) ) version = type ; else throw new Error ( 'Your entry was invalid.' ) ; log ( '' ) ; log ( 'The new version will be ' + version . cyan + '.' ) ; write ( ` ${ "[yes/no]" . cyan } ` ) ; return prompt ( ) === 'yes' ? version : getNewVersion ( ) ; function getVersionOptions ( version ) { return version . match ( / -rc\.?\d+$ / ) ? [ increment ( version , 'rc' ) , increment ( version , 'minor' ) ] : [ increment ( version , 'patch' ) , addRC ( increment ( version , 'minor' ) ) ] ; function increment ( versionString , type ) { const version = parseVersion ( versionString ) ; if ( version . rc ) { switch ( type ) { case 'minor' : version . rc = 0 ; break ; case 'rc' : version . rc ++ ; break ; } } else { version [ type ] ++ ; // reset any version numbers lower than the one changed switch ( type ) { case 'minor' : version . patch = 0 ; case 'patch' : version . rc = 0 ; } } return getVersionString ( version ) ; function parseVersion ( version ) { const parts = version . split ( / -rc\.|\. / g ) ; return { string : version , major : parts [ 0 ] , minor : parts [ 1 ] , patch : parts [ 2 ] , rc : parts [ 3 ] || 0 } ; } function getVersionString ( version ) { let str = version . major + '.' + version . minor + '.' + version . patch ; if ( version . rc ) str += '-rc.' + version . rc ; return str ; } } function addRC ( str ) { return str + '-rc.1' ; } } }
prompts the user for the new version
prompts the user for the new version