fix: 测试通过后再写回版本号,避免测试失败时污染 package.json
This commit is contained in:
@@ -80,9 +80,6 @@ async function stepBumpVersion(): Promise<string> {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
pkg.version = newVersion;
|
||||
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
||||
console.log(`版本号已更新: ${currentVersion} → ${newVersion}`);
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
@@ -180,18 +177,28 @@ async function stepNpmPublish(): Promise<void> {
|
||||
console.log("npm 发布成功");
|
||||
}
|
||||
|
||||
function writeVersion(version: string): void {
|
||||
const pkgPath = join(import.meta.dir, "..", "package.json");
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")) as { version: string };
|
||||
pkg.version = version;
|
||||
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const newVersion = await stepBumpVersion();
|
||||
console.log(`[1/4] 版本号递增完成: ${newVersion}`);
|
||||
console.log(`目标版本: ${newVersion}`);
|
||||
|
||||
await runTests();
|
||||
console.log("[2/4] 测试通过");
|
||||
console.log("[1/3] 测试通过");
|
||||
|
||||
writeVersion(newVersion);
|
||||
console.log(`[2/3] 版本号已更新: ${newVersion}`);
|
||||
|
||||
await stepGitCommitTag(newVersion);
|
||||
console.log(`[3/4] git commit 和 tag v${newVersion} 完成`);
|
||||
console.log(`[3/3] git commit 和 tag v${newVersion} 完成`);
|
||||
|
||||
await stepNpmPublish();
|
||||
console.log("[4/4] npm 发布完成");
|
||||
console.log("npm 发布完成");
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
|
||||
Reference in New Issue
Block a user