mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
/**
|
|
* 本地构建脚本
|
|
* @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";
|
|
|
|
const __dirname = resolve(fileURLToPath(import.meta.url), "../");
|
|
|
|
// 判断是否GithubAction
|
|
const isGitHubActions = process.env.GITHUB_ACTIONS === "true";
|
|
|
|
// 获取版本
|
|
const pkgVersion = pkgJson.version;
|
|
|
|
// 解析命令行参数
|
|
const args = process.argv.slice(2);
|
|
const skipUpload = args.includes("su");
|
|
console.log(`🍄 SkipUpload:${skipUpload}`);
|
|
|
|
// 获取提交哈希
|
|
const commitHash = execSync("git rev-parse --short HEAD").toString().trim();
|
|
|
|
// 构建 Release 字符串
|
|
const release = `TeyvatGuide@${pkgVersion}`;
|
|
console.log(`🍄 gen sentry release ${release} env`);
|
|
|
|
// 修改 .env.production
|
|
const envPath = resolve(__dirname, "../.env.production");
|
|
const envRead = parse(readFileSync(envPath, "utf-8"));
|
|
envRead.VITE_SENTRY_RELEASE = release;
|
|
envRead.VITE_COMMIT_HASH = commitHash;
|
|
envRead.VITE_BUILD_TIME = Math.floor(Date.now() / 1000).toString();
|
|
writeFileSync(envPath, stringify(envRead), "utf-8");
|
|
console.log("✅ .env.production updated!");
|
|
|
|
// 执行 pnpm build
|
|
execSync("pnpm tauri build", { stdio: "inherit" });
|
|
|
|
// 上传pdb
|
|
if (isGitHubActions) {
|
|
if (process.env.GITHUB_ENV) {
|
|
writeFileSync(process.env.GITHUB_ENV, `SENTRY_RELEASE=${release}\n`, { flag: "a" });
|
|
console.log("📦 SENTRY_RELEASE exported to GitHub Actions env.");
|
|
} else {
|
|
console.warn("⚠️ Not running inside GitHub Actions. Skipping env export.");
|
|
}
|
|
process.exit();
|
|
}
|
|
if (skipUpload) process.exit();
|
|
const pdbGlob = "src-tauri/target/release/TeyvatGuide.pdb";
|
|
try {
|
|
console.log(`📦 Uploading PDBs from ${pdbGlob}...`);
|
|
execSync(`sentry-cli releases new "${release}"`, { stdio: "inherit" });
|
|
execSync(`sentry-cli debug-files upload --include-sources src-tauri/src ${pdbGlob}`, {
|
|
stdio: "inherit",
|
|
});
|
|
execSync(`sentry-cli releases finalize "${release}"`, { stdio: "inherit" });
|
|
console.log("✅ PDB upload complete!");
|
|
const distDir = resolve(__dirname, "../dist");
|
|
execSync(
|
|
`sentry-cli releases files "${release}" upload-sourcemaps "${distDir}" --rewrite --url-prefix "~/"`,
|
|
{ stdio: "inherit" },
|
|
);
|
|
console.log("✅ Frontend sourcemaps upload complete!");
|
|
} catch (err) {
|
|
console.error("❌ Failed to upload PDBs:", err);
|
|
process.exit(1);
|
|
}
|