From 692e6ccc9433f0900cdd106243635497ad245033 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Tue, 30 Dec 2025 02:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20dev=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- scripts/auto-dev.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 scripts/auto-dev.ts diff --git a/package.json b/package.json index 64a68b76..358a9cce 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "build": "tsx scripts/auto-build.ts", "debug": "tauri build --debug", - "dev": "tauri dev --exit-on-panic", + "dev": "tsx scripts/auto-dev.ts", "eslint:pre": "pnpx @eslint/config-inspector@latest", "oxlint": "oxlint", "lint": "concurrently \"pnpm:lint:*(!fix)\"", diff --git a/scripts/auto-dev.ts b/scripts/auto-dev.ts new file mode 100644 index 00000000..a30b5636 --- /dev/null +++ b/scripts/auto-dev.ts @@ -0,0 +1,50 @@ +/** + * 本地调试脚本 + * @since Beta v0.9.1 + */ +import { resolve } from "path"; +import { fileURLToPath } from "node:url"; +import pkgJson from "../package.json" with { type: "json" }; +import { execSync } from "child_process"; +import { parse, stringify } from "envfile"; +import { readFileSync, writeFileSync } from "fs"; +import { existsSync } from "node:fs"; + +const __dirname = resolve(fileURLToPath(import.meta.url), "../"); + +// 获取版本 +const pkgVersion = pkgJson.version; + +// 获取提交哈希 +const commitHash = execSync("git rev-parse --short HEAD").toString().trim(); + +// 获取当前时间 +const timeNow = Math.floor(Date.now() / 1000); + +// 获取当前平台 +let platform = "unknown"; +if (process.platform === "win32") { + platform = "windows"; +} else if (process.platform === "darwin") { + platform = process.arch === "arm64" ? "macos-arm" : "macos-intel"; +} else { + platform = `${process.platform}-${process.arch}`; +} + +// 构建 Release 字符串 +const release = `TeyvatGuide@${pkgVersion}_dev_${commitHash}_${platform}_${timeNow}`; +console.log(`🍄 gen sentry dev release ${release}`); + +// 修改 .env.development.local +const envPath = resolve(__dirname, "../.env.development.local"); +if (!existsSync(envPath)) { + writeFileSync(envPath, `VITE_SENTRY_RELEASE=${release}`, "utf-8"); +} else { + const envRead = parse(readFileSync(envPath, "utf-8")); + envRead.VITE_SENTRY_RELEASE = release; + writeFileSync(envPath, stringify(envRead), "utf-8"); +} +console.log("✅ .env.development.local updated!"); + +// 执行 tauri dev +execSync("pnpm tauri dev --exit-on-panic", { stdio: "inherit" });