|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import { spawn } from 'node:child_process'
|
|
|
|
|
import { readFileSync, writeFileSync } from 'node:fs'
|
|
|
|
|
import { spawn } from 'cross-spawn'
|
|
|
|
|
import type { SpawnOptions } from 'node:child_process'
|
|
|
|
|
import fs from 'node:fs'
|
|
|
|
|
import { createRequire } from 'node:module'
|
|
|
|
|
import { resolve } from 'node:path'
|
|
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
|
@ -12,17 +13,16 @@ const { version: currentVersion } = createRequire(import.meta.url)(
|
|
|
|
|
)
|
|
|
|
|
const { inc: _inc, valid } = semver
|
|
|
|
|
|
|
|
|
|
const versionIncrements = ['patch', 'minor', 'major']
|
|
|
|
|
const versionIncrements = ['patch', 'minor', 'major'] as const
|
|
|
|
|
|
|
|
|
|
const tags = ['latest', 'next']
|
|
|
|
|
const tags = ['latest', 'next'] as const
|
|
|
|
|
|
|
|
|
|
const dir = fileURLToPath(new URL('.', import.meta.url))
|
|
|
|
|
const inc = (i) => _inc(currentVersion, i)
|
|
|
|
|
const run = (bin, args, opts = {}) =>
|
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
|
const inc = (i: semver.ReleaseType) => _inc(currentVersion, i)
|
|
|
|
|
const run = (bin: string, args: string[], opts: SpawnOptions = {}) =>
|
|
|
|
|
new Promise<void>((resolve, reject) => {
|
|
|
|
|
const child = spawn(bin, args, {
|
|
|
|
|
stdio: 'inherit',
|
|
|
|
|
shell: process.platform === 'win32',
|
|
|
|
|
...opts
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
@ -37,10 +37,10 @@ const run = (bin, args, opts = {}) =>
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
const step = (msg) => console.log(c.cyan(msg))
|
|
|
|
|
const step = (msg: string) => console.log(c.cyan(msg))
|
|
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
|
let targetVersion
|
|
|
|
|
let targetVersion: string
|
|
|
|
|
|
|
|
|
|
const versions = versionIncrements
|
|
|
|
|
.map((i) => `${i} (${inc(i)})`)
|
|
|
|
|
@ -50,7 +50,7 @@ async function main() {
|
|
|
|
|
type: 'select',
|
|
|
|
|
name: 'release',
|
|
|
|
|
message: 'Select release type',
|
|
|
|
|
choices: versions
|
|
|
|
|
choices: versions.map((title, value) => ({ title, value }))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (release === 3) {
|
|
|
|
|
@ -63,7 +63,7 @@ async function main() {
|
|
|
|
|
})
|
|
|
|
|
).version
|
|
|
|
|
} else {
|
|
|
|
|
targetVersion = versions[release].match(/\((.*)\)/)[1]
|
|
|
|
|
targetVersion = versions[release].match(/\((.*)\)/)![1]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!valid(targetVersion)) {
|
|
|
|
|
@ -74,7 +74,7 @@ async function main() {
|
|
|
|
|
type: 'select',
|
|
|
|
|
name: 'tag',
|
|
|
|
|
message: 'Select tag type',
|
|
|
|
|
choices: tags
|
|
|
|
|
choices: tags.map((title, value) => ({ title, value }))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const { yes: tagOk } = await prompts({
|
|
|
|
|
@ -132,13 +132,13 @@ async function main() {
|
|
|
|
|
await run('git', ['push'])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updatePackage(version) {
|
|
|
|
|
function updatePackage(version: string) {
|
|
|
|
|
const pkgPath = resolve(resolve(dir, '..'), 'package.json')
|
|
|
|
|
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
|
|
|
|
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
|
|
|
|
|
|
|
|
pkg.version = version
|
|
|
|
|
|
|
|
|
|
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
|
|
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main().catch((err) => console.error(err))
|