From 38d6d8c4a7011a0d9c5e418afeb8f5ffc9c7b391 Mon Sep 17 00:00:00 2001 From: sendevia Date: Fri, 9 Jan 2026 14:59:37 +0800 Subject: [PATCH] feat(version): add script to automatically update package version --- scripts/update-version.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 scripts/update-version.js diff --git a/scripts/update-version.js b/scripts/update-version.js new file mode 100644 index 0000000..4a0bafc --- /dev/null +++ b/scripts/update-version.js @@ -0,0 +1,21 @@ +import fs from "node:fs"; +import { execSync } from "node:child_process"; + +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 now = new Date(); +const year = now.getFullYear().toString().slice(-2); +const month = now.getMonth() + 1; +const date = now.getDate(); + +const newVersion = `${year}.${month}.${date}(${nextCommitCount})`; + +pkg.version = newVersion; + +fs.writeFileSync("./package.json", JSON.stringify(pkg, null, 2) + "\n"); +console.log(`Version updated to: ${newVersion}`);