From da7770f76a5bb9acc114d6a2dfe65347e4ed4bae Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Tue, 9 Jun 2026 17:56:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E9=80=92=E5=A2=9E=E4=B8=8E=E4=BA=A4=E4=BA=92=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/release.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/scripts/release.ts b/scripts/release.ts index 777a918..e3fbb89 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -1,3 +1,7 @@ +import { readFileSync, writeFileSync } from "node:fs"; +import { createInterface } from "node:readline"; +import { join } from "node:path"; + interface Semver { major: number; minor: number; @@ -33,9 +37,55 @@ export function bumpVersion(current: string, type: BumpType): string { } } +async function ask(query: string): Promise { + const rl = createInterface({ input: process.stdin, output: process.stdout }); + return new Promise((resolve) => { + rl.question(query, (answer) => { + rl.close(); + resolve(answer.trim()); + }); + }); +} + +async function selectBumpType(): Promise { + console.log("选择版本递增类型:"); + console.log(" 1) major - 不兼容的 API 变更"); + console.log(" 2) minor - 向下兼容的功能新增"); + console.log(" 3) patch - 向下兼容的问题修正"); + + while (true) { + const answer = await ask("请输入 1/2/3 [3]: "); + const choice = answer || "3"; + if (choice === "1") return "major"; + if (choice === "2") return "minor"; + if (choice === "3") return "patch"; + console.log("无效选择,请输入 1、2 或 3"); + } +} + +async function stepBumpVersion(): Promise { + const pkgPath = join(import.meta.dir, "..", "package.json"); + const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")) as { version: string }; + const currentVersion = pkg.version; + + const bumpType = await selectBumpType(); + const newVersion = bumpVersion(currentVersion, bumpType); + + const answer = await ask(`确认版本号 ${currentVersion} → ${newVersion}? [y/N]: `); + if (answer.toLowerCase() !== "y") { + console.log("已取消"); + process.exit(0); + } + + pkg.version = newVersion; + writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n"); + console.log(`版本号已更新: ${currentVersion} → ${newVersion}`); + return newVersion; +} + async function main(): Promise { - // 后续 task 中实现流程编排 - console.log("release 脚本骨架就绪"); + const newVersion = await stepBumpVersion(); + console.log(`[1/4] 版本号递增完成: ${newVersion}`); } main().catch((err: unknown) => {