2018-02-03 23:35:23 +00:00
|
|
|
import { spawn } from './spawn'
|
|
|
|
import { sort as semverSort, inc, SemVer } from 'semver'
|
|
|
|
|
|
|
|
async function getLatestRelease(excludeBetaReleases: boolean): Promise<string> {
|
|
|
|
const allTags = await spawn('git', ['tag'])
|
|
|
|
let releaseTags = allTags
|
|
|
|
.split('\n')
|
|
|
|
.filter(tag => tag.startsWith('release-'))
|
|
|
|
.filter(tag => tag.indexOf('-linux') === -1)
|
|
|
|
.filter(tag => tag.indexOf('-test') === -1)
|
|
|
|
|
|
|
|
if (excludeBetaReleases) {
|
|
|
|
releaseTags = releaseTags.filter(tag => tag.indexOf('-beta') === -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
const releaseVersions = releaseTags.map(tag => tag.substr(8))
|
|
|
|
|
|
|
|
const sortedTags = semverSort(releaseVersions)
|
|
|
|
const latestTag = sortedTags[sortedTags.length - 1]
|
|
|
|
|
|
|
|
if (latestTag instanceof SemVer) {
|
|
|
|
console.log('we have types!?!?!?')
|
|
|
|
return latestTag.raw
|
|
|
|
}
|
|
|
|
|
|
|
|
return latestTag
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function run(args: ReadonlyArray<string>): Promise<void> {
|
2018-02-03 23:45:51 +00:00
|
|
|
//try {
|
|
|
|
// await spawn('git', ['diff-index', '--quiet', 'HEAD'])
|
|
|
|
//} catch {
|
|
|
|
// throw new Error(
|
|
|
|
// `There are uncommitted changes in the working directory. Aborting...`
|
|
|
|
// )
|
|
|
|
//}
|
2018-02-03 23:35:23 +00:00
|
|
|
|
|
|
|
if (args.length === 0) {
|
|
|
|
throw new Error(
|
|
|
|
`You have not specified a channel to draft this release for. Choose one of 'production' or 'beta'`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// first argument should be the channel
|
|
|
|
const channel = args[0]
|
|
|
|
|
|
|
|
if (channel === 'production') {
|
|
|
|
const latestVersion = await getLatestRelease(true)
|
|
|
|
const nextVersion = inc(latestVersion, 'patch')
|
|
|
|
throw new Error(
|
|
|
|
`Drafting a release from ${latestVersion} which will be ${nextVersion}`
|
|
|
|
)
|
|
|
|
} else if (channel === 'beta') {
|
|
|
|
const latestVersion = await getLatestRelease(false)
|
2018-02-03 23:49:28 +00:00
|
|
|
const betaTagIndex = latestVersion.indexOf('-beta')
|
|
|
|
if (betaTagIndex > -1) {
|
|
|
|
const betaNumber = latestVersion.substr(betaTagIndex + 5)
|
2018-02-03 23:39:55 +00:00
|
|
|
const newBeta = parseInt(betaNumber, 10) + 1
|
2018-02-03 23:54:15 +00:00
|
|
|
|
|
|
|
const newVersion = latestVersion.replace(
|
|
|
|
`-beta${betaNumber}`,
|
|
|
|
`-beta${newBeta}`
|
|
|
|
)
|
2018-02-03 23:39:55 +00:00
|
|
|
throw new Error(
|
2018-02-03 23:54:15 +00:00
|
|
|
`Drafting a beta release from ${latestVersion} which will be a new beta ${newVersion}`
|
2018-02-03 23:39:55 +00:00
|
|
|
)
|
|
|
|
} else {
|
2018-02-03 23:54:15 +00:00
|
|
|
const nextVersion = inc(latestVersion, 'patch')
|
|
|
|
const firstBeta = `${nextVersion}-beta1`
|
2018-02-03 23:39:55 +00:00
|
|
|
throw new Error(
|
2018-02-03 23:54:15 +00:00
|
|
|
`Drafting a beta release from ${latestVersion} which will be the first beta ${firstBeta}`
|
2018-02-03 23:39:55 +00:00
|
|
|
)
|
|
|
|
}
|
2018-02-03 23:35:23 +00:00
|
|
|
}
|
|
|
|
}
|