2023-05-09 13:25:56 +00:00
|
|
|
import { exec } from './lib/exec'
|
2023-06-01 18:01:49 +00:00
|
|
|
import { nicelog } from './lib/nicelog'
|
2023-04-25 11:01:25 +00:00
|
|
|
import { getLatestVersion, publish, setAllVersions } from './lib/publishing'
|
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
async function main() {
|
|
|
|
const sha = (await exec('git', ['rev-parse', 'HEAD'])).trim().slice(0, 12)
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
async function setCanaryVersions(bump: 'major' | 'minor' | 'patch') {
|
|
|
|
const latestVersion = getLatestVersion()
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +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
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
setAllVersions(versionString)
|
|
|
|
}
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// module was called directly
|
2023-06-05 14:46:59 +00:00
|
|
|
const bumpType = (await exec('npx', ['auto', 'version'])).trim() as
|
|
|
|
| 'major'
|
|
|
|
| 'minor'
|
|
|
|
| 'patch'
|
|
|
|
| ''
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-06-01 18:01:49 +00:00
|
|
|
nicelog('bumpType', bumpType)
|
2023-04-25 11:01:25 +00:00
|
|
|
if (bumpType === '') {
|
2023-06-01 18:01:49 +00:00
|
|
|
nicelog('nothing to do')
|
2023-04-25 11:01:25 +00:00
|
|
|
} else if (['major', 'minor', 'patch'].includes(bumpType)) {
|
2023-06-01 18:01:49 +00:00
|
|
|
nicelog('setting canary versions')
|
2023-04-25 11:01:25 +00:00
|
|
|
setCanaryVersions(bumpType)
|
|
|
|
publish()
|
|
|
|
} else {
|
|
|
|
throw new Error('Invalid bump type provided')
|
|
|
|
}
|
|
|
|
}
|
2023-05-09 13:25:56 +00:00
|
|
|
|
|
|
|
main()
|