2023-04-25 11:01:25 +00:00
|
|
|
import { Auto } from '@auto-it/core'
|
|
|
|
import { parse } from 'semver'
|
2023-05-09 13:25:56 +00:00
|
|
|
import { exec } from './lib/exec'
|
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 auto = new Auto({
|
|
|
|
plugins: ['npm'],
|
|
|
|
baseBranch: 'main',
|
|
|
|
owner: 'tldraw',
|
|
|
|
repo: 'tldraw-lite',
|
|
|
|
verbose: true,
|
|
|
|
})
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// module was called directly
|
2023-05-09 13:25:56 +00:00
|
|
|
const currentBranch = (await exec('git', ['rev-parse', '--abbrev-ref', 'HEAD'])).toString().trim()
|
2023-04-25 11:01:25 +00:00
|
|
|
if (currentBranch !== 'main') {
|
|
|
|
throw new Error('Must be on main branch to publish')
|
|
|
|
}
|
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
await auto.loadConfig()
|
|
|
|
const bump = await auto.getVersion()
|
|
|
|
if (!bump) {
|
|
|
|
console.log('nothing to do')
|
|
|
|
return
|
|
|
|
}
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
const latestVersion = parse(getLatestVersion())!
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
console.log('latestVersion', latestVersion)
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
const [prereleaseTag, prereleaseNumber] = latestVersion.prerelease
|
|
|
|
if (prereleaseTag && typeof prereleaseNumber !== 'number') {
|
|
|
|
throw new Error(`Invalid prerelease format in version ${latestVersion}, expected e.g. -alpha.1`)
|
|
|
|
}
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// if we're in prerelease mode, don't bump the version, only the prerelease number
|
|
|
|
const nextVersion = prereleaseTag
|
|
|
|
? `${latestVersion.major}.${latestVersion.minor}.${latestVersion.patch}-${prereleaseTag}.${
|
|
|
|
Number(prereleaseNumber) + 1
|
|
|
|
}`
|
|
|
|
: latestVersion.inc(bump).format()
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
setAllVersions(nextVersion)
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// stage the changes
|
|
|
|
await exec('git', ['add', 'lerna.json', 'bublic/packages/*/package.json'])
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// this creates a new commit
|
|
|
|
await auto.changelog({
|
|
|
|
useVersion: nextVersion,
|
|
|
|
title: `v${nextVersion}`,
|
|
|
|
})
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// create and push a new tag
|
|
|
|
await exec('git', ['tag', '-f', `v${nextVersion}`])
|
|
|
|
await exec('git', ['push', '--follow-tags'])
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// create a release on github
|
|
|
|
await auto.runRelease({ useVersion: nextVersion })
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// finally, publish the packages [IF THIS STEP FAILS, RUN THE `publish-manual.ts` script locally]
|
|
|
|
await publish()
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|
2023-05-09 13:25:56 +00:00
|
|
|
|
|
|
|
main()
|