diff --git a/scripts/release.ts b/scripts/release.ts index 2625546..fc7916e 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -94,18 +94,18 @@ async function runTests(): Promise { } } -async function stepGitCommitTag(version: string): Promise { - // 检查工作区状态 - const statusProc = Bun.spawn(["git", "status", "--porcelain"], { +async function checkWorkingTree(): Promise { + const proc = Bun.spawn(["git", "status", "--porcelain"], { stdio: ["inherit", "pipe", "inherit"], }); - const statusOutput = await new Response(statusProc.stdout).text(); - const statusLines = statusOutput.trim().split("\n").filter(Boolean); - const nonPkgChanges = statusLines.filter((line) => !/^[?MADRCU ]{2} package\.json$/.test(line)); - if (nonPkgChanges.length > 0) { - throw new Error("工作区有其他未提交变更,请先清理后再运行 release"); + const output = await new Response(proc.stdout).text(); + const lines = output.trim().split("\n").filter(Boolean); + if (lines.length > 0) { + throw new Error("工作区有未提交变更,请先提交或清理后再运行 release"); } +} +async function stepGitCommitTag(version: string): Promise { console.log("\n准备提交:"); console.log(` git add package.json`); console.log(` git commit -m "chore: release v${version}"`); @@ -185,6 +185,8 @@ function writeVersion(version: string): void { } async function main(): Promise { + await checkWorkingTree(); + const newVersion = await stepBumpVersion(); console.log(`目标版本: ${newVersion}`);