( version: string, channel: Channel )
| 22 | } |
| 23 | |
| 24 | export function getNextVersionNumber( |
| 25 | version: string, |
| 26 | channel: Channel |
| 27 | ): string { |
| 28 | const semanticVersion = parse(version) |
| 29 | |
| 30 | if (semanticVersion == null) { |
| 31 | throw new Error(`Unable to parse input '${version}' into version`) |
| 32 | } |
| 33 | |
| 34 | switch (channel) { |
| 35 | case 'production': |
| 36 | if (isBetaTag(semanticVersion)) { |
| 37 | throw new Error( |
| 38 | `Unable to draft production release using beta version '${version}'` |
| 39 | ) |
| 40 | } |
| 41 | |
| 42 | if (isTestTag(semanticVersion)) { |
| 43 | throw new Error( |
| 44 | `Unable to draft production release using test version '${version}'` |
| 45 | ) |
| 46 | } |
| 47 | |
| 48 | const nextVersion = inc(version, 'patch') |
| 49 | if (nextVersion == null) { |
| 50 | throw new Error( |
| 51 | `Unable to increment next production version from release version '${version}'` |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | return nextVersion |
| 56 | |
| 57 | case 'beta': |
| 58 | if (isTestTag(semanticVersion)) { |
| 59 | throw new Error( |
| 60 | `Unable to draft beta release using test version '${version}'` |
| 61 | ) |
| 62 | } |
| 63 | |
| 64 | const betaNumber = tryGetBetaNumber(semanticVersion) |
| 65 | |
| 66 | if (betaNumber) { |
| 67 | return semanticVersion.version.replace( |
| 68 | `-beta${betaNumber}`, |
| 69 | `-beta${betaNumber + 1}` |
| 70 | ) |
| 71 | } else { |
| 72 | const nextVersion = inc(semanticVersion, 'patch') |
| 73 | const firstBeta = `${nextVersion}-beta1` |
| 74 | return firstBeta |
| 75 | } |
| 76 | case 'test': |
| 77 | if (isBetaTag(semanticVersion)) { |
| 78 | throw new Error( |
| 79 | `Unable to draft test release using beta version '${version}'` |
| 80 | ) |
| 81 | } |
no test coverage detected