tldraw/scripts/publish-canary.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

import { exec } from './lib/exec'
2023-04-25 11:01:25 +00:00
import { getLatestVersion, publish, setAllVersions } from './lib/publishing'
async function main() {
const sha = (await exec('git', ['rev-parse', 'HEAD'])).trim().slice(0, 12)
2023-04-25 11:01:25 +00:00
async function setCanaryVersions(bump: 'major' | 'minor' | 'patch') {
const latestVersion = getLatestVersion()
2023-04-25 11:01:25 +00:00
const nextVersion = latestVersion.prerelease.length
? // if the package is in prerelease mode, we want to release a canary for the current version rather than bumping
latestVersion
: latestVersion?.inc(bump)
const versionString = `${nextVersion.major}.${nextVersion.minor}.${nextVersion.patch}-canary.${sha}`
2023-04-25 11:01:25 +00:00
setAllVersions(versionString)
}
2023-04-25 11:01:25 +00:00
// module was called directly
const bumpType = (await exec('auto', ['version'])).trim() as 'major' | 'minor' | 'patch' | ''
2023-04-25 11:01:25 +00:00
console.log('bumpType', bumpType)
if (bumpType === '') {
console.log('nothing to do')
} else if (['major', 'minor', 'patch'].includes(bumpType)) {
console.log('setting canary versions')
setCanaryVersions(bumpType)
publish()
} else {
throw new Error('Invalid bump type provided')
}
}
main()