1
0
mirror of https://github.com/sendevia/website.git synced 2026-03-05 23:32:45 +08:00

version: enhance version update logic to account for staged changes

This commit is contained in:
2026-01-09 15:07:11 +08:00
parent 04f543897b
commit e520af9578

View File

@@ -5,7 +5,10 @@ const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
// 获取提交数
const commitCount = parseInt(execSync("git rev-list --count HEAD").toString().trim(), 10);
const nextCommitCount = commitCount + 1;
// 检查是否有暂存的更改
const hasStagedChanges = execSync("git diff --cached --quiet || echo 'changed'").toString().trim() === "changed";
// 版本号中的提交数 = 当前提交数 + 1 (即将进行的提交) + (如果有暂存更改则额外+1)
const nextCommitCount = commitCount + 1 + (hasStagedChanges ? 1 : 0);
// 获取当前日期
const now = new Date();
@@ -19,3 +22,12 @@ pkg.version = newVersion;
fs.writeFileSync("./package.json", JSON.stringify(pkg, null, 2) + "\n");
console.log(`Version updated to: ${newVersion}`);
// 自动执行 git add 和 git commit
try {
execSync("git add package.json");
execSync(`git commit -m "chore(package): update to version ${newVersion}"`);
console.log(`Committed: chore(package): update to version ${newVersion}`);
} catch (error) {
console.error("Failed to commit version update:", error.message);
}