Skip to content

Commit b4d2501

Browse files
committed
chore: make release script work again
1 parent 6c611cf commit b4d2501

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

scripts/release.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import { fileURLToPath } from 'url'
44
import c from 'picocolors'
55
import prompts from 'prompts'
66
import { execa } from 'execa'
7-
import { inc as _inc, valid } from 'semver'
8-
import { version as currentVersion } from '../package.json'
7+
import semver from 'semver'
8+
import pkg from '../package.json' assert { type: 'json' }
9+
10+
const { version: currentVersion } = pkg
11+
const { inc: _inc, valid } = semver
912

1013
const versionIncrements = ['patch', 'minor', 'major']
1114

1215
const tags = ['latest', 'next']
1316

14-
const dir = dirname(fileURLToPath(import.meta.url))
17+
const dir = fileURLToPath(new URL('.', import.meta.url))
1518
const inc = (i) => _inc(currentVersion, i)
1619
const run = (bin, args, opts = {}) =>
1720
execa(bin, args, { stdio: 'inherit', ...opts })
@@ -20,31 +23,35 @@ const step = (msg) => console.log(c.cyan(msg))
2023
async function main() {
2124
let targetVersion
2225

26+
const versions = versionIncrements
27+
.map((i) => `${i} (${inc(i)})`)
28+
.concat(['custom'])
29+
2330
const { release } = await prompts({
2431
type: 'select',
2532
name: 'release',
2633
message: 'Select release type',
27-
choices: versionIncrements.map((i) => `${i} (${inc(i)})`).concat(['custom'])
34+
choices: versions
2835
})
29-
30-
if (release === 'custom') {
36+
console.log(release, release === 3)
37+
if (release === 3) {
3138
targetVersion = (
3239
await prompts({
33-
type: 'input',
40+
type: 'text',
3441
name: 'version',
3542
message: 'Input custom version',
3643
initial: currentVersion
3744
})
3845
).version
3946
} else {
40-
targetVersion = release.match(/\((.*)\)/)[1]
47+
targetVersion = versions[release].match(/\((.*)\)/)[1]
4148
}
4249

4350
if (!valid(targetVersion)) {
4451
throw new Error(`Invalid target version: ${targetVersion}`)
4552
}
4653

47-
const { tag } = await enquirer.prompt({
54+
const { tag } = await prompts({
4855
type: 'select',
4956
name: 'tag',
5057
message: 'Select tag type',
@@ -54,7 +61,7 @@ async function main() {
5461
const { yes: tagOk } = await prompts({
5562
type: 'confirm',
5663
name: 'yes',
57-
message: `Releasing v${targetVersion} in ${tag}. Confirm?`
64+
message: `Releasing v${targetVersion} on ${tags[tag]}. Confirm?`
5865
})
5966

6067
if (!tagOk) {
@@ -95,7 +102,7 @@ async function main() {
95102
await run('pnpm', [
96103
'publish',
97104
'--tag',
98-
tag,
105+
tags[tag],
99106
'--ignore-scripts',
100107
'--no-git-checks'
101108
])

0 commit comments

Comments
 (0)