chore: make release script work again

pull/699/head
Kia King Ishii 3 years ago
parent 6c611cfe85
commit b4d2501017

@ -4,14 +4,17 @@ import { fileURLToPath } from 'url'
import c from 'picocolors' import c from 'picocolors'
import prompts from 'prompts' import prompts from 'prompts'
import { execa } from 'execa' import { execa } from 'execa'
import { inc as _inc, valid } from 'semver' import semver from 'semver'
import { version as currentVersion } from '../package.json' import pkg from '../package.json' assert { type: 'json' }
const { version: currentVersion } = pkg
const { inc: _inc, valid } = semver
const versionIncrements = ['patch', 'minor', 'major'] const versionIncrements = ['patch', 'minor', 'major']
const tags = ['latest', 'next'] const tags = ['latest', 'next']
const dir = dirname(fileURLToPath(import.meta.url)) const dir = fileURLToPath(new URL('.', import.meta.url))
const inc = (i) => _inc(currentVersion, i) const inc = (i) => _inc(currentVersion, i)
const run = (bin, args, opts = {}) => const run = (bin, args, opts = {}) =>
execa(bin, args, { stdio: 'inherit', ...opts }) execa(bin, args, { stdio: 'inherit', ...opts })
@ -20,31 +23,35 @@ const step = (msg) => console.log(c.cyan(msg))
async function main() { async function main() {
let targetVersion let targetVersion
const versions = versionIncrements
.map((i) => `${i} (${inc(i)})`)
.concat(['custom'])
const { release } = await prompts({ const { release } = await prompts({
type: 'select', type: 'select',
name: 'release', name: 'release',
message: 'Select release type', message: 'Select release type',
choices: versionIncrements.map((i) => `${i} (${inc(i)})`).concat(['custom']) choices: versions
}) })
console.log(release, release === 3)
if (release === 'custom') { if (release === 3) {
targetVersion = ( targetVersion = (
await prompts({ await prompts({
type: 'input', type: 'text',
name: 'version', name: 'version',
message: 'Input custom version', message: 'Input custom version',
initial: currentVersion initial: currentVersion
}) })
).version ).version
} else { } else {
targetVersion = release.match(/\((.*)\)/)[1] targetVersion = versions[release].match(/\((.*)\)/)[1]
} }
if (!valid(targetVersion)) { if (!valid(targetVersion)) {
throw new Error(`Invalid target version: ${targetVersion}`) throw new Error(`Invalid target version: ${targetVersion}`)
} }
const { tag } = await enquirer.prompt({ const { tag } = await prompts({
type: 'select', type: 'select',
name: 'tag', name: 'tag',
message: 'Select tag type', message: 'Select tag type',
@ -54,7 +61,7 @@ async function main() {
const { yes: tagOk } = await prompts({ const { yes: tagOk } = await prompts({
type: 'confirm', type: 'confirm',
name: 'yes', name: 'yes',
message: `Releasing v${targetVersion} in ${tag}. Confirm?` message: `Releasing v${targetVersion} on ${tags[tag]}. Confirm?`
}) })
if (!tagOk) { if (!tagOk) {
@ -95,7 +102,7 @@ async function main() {
await run('pnpm', [ await run('pnpm', [
'publish', 'publish',
'--tag', '--tag',
tag, tags[tag],
'--ignore-scripts', '--ignore-scripts',
'--no-git-checks' '--no-git-checks'
]) ])

Loading…
Cancel
Save