mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
🌱 构建脚本
This commit is contained in:
1
.env.production
Normal file
1
.env.production
Normal file
@@ -0,0 +1 @@
|
||||
VITE_SENTRY_RELEASE=TeyvatGuide@0.9.0_0c8eda3f_windows
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,4 +10,4 @@ dist
|
||||
*.tsbuildinfo
|
||||
|
||||
# Sentry Config File
|
||||
.env.sentry-build-plugin
|
||||
.env.development.local
|
||||
3
.sentryclirc
Normal file
3
.sentryclirc
Normal file
@@ -0,0 +1,3 @@
|
||||
[defaults]
|
||||
org = teyvat-guide
|
||||
project = teyvat-guide
|
||||
@@ -6,7 +6,7 @@
|
||||
"packageManager": "pnpm@10.26.2",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tauri build",
|
||||
"build": "tsx scripts/auto-build.ts",
|
||||
"debug": "tauri build --debug",
|
||||
"dev": "tauri dev --exit-on-panic",
|
||||
"eslint:pre": "pnpx @eslint/config-inspector@latest",
|
||||
@@ -119,6 +119,7 @@
|
||||
"@vitejs/plugin-vue": "^6.0.3",
|
||||
"app-root-path": "^3.1.0",
|
||||
"concurrently": "^9.2.1",
|
||||
"envfile": "^7.1.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-jsonc": "^2.21.0",
|
||||
|
||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -150,6 +150,9 @@ importers:
|
||||
concurrently:
|
||||
specifier: ^9.2.1
|
||||
version: 9.2.1
|
||||
envfile:
|
||||
specifier: ^7.1.0
|
||||
version: 7.1.0
|
||||
eslint:
|
||||
specifier: ^9.39.2
|
||||
version: 9.39.2(jiti@2.6.1)
|
||||
@@ -2118,6 +2121,11 @@ packages:
|
||||
resolution: {integrity: sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
envfile@7.1.0:
|
||||
resolution: {integrity: sha512-dyH4QnnZsArCLhPASr29eqBWDvKpq0GggQFTmysTT/S9TTmt1JrEKNvTBc09Cd7ujVZQful2HBGRMe2agu7Krg==}
|
||||
engines: {node: '>=8'}
|
||||
hasBin: true
|
||||
|
||||
environment@1.1.0:
|
||||
resolution: {integrity: sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -6253,6 +6261,8 @@ snapshots:
|
||||
|
||||
env-paths@2.2.1: {}
|
||||
|
||||
envfile@7.1.0: {}
|
||||
|
||||
environment@1.1.0: {}
|
||||
|
||||
error-ex@1.3.4:
|
||||
|
||||
61
scripts/auto-build.ts
Normal file
61
scripts/auto-build.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 本地构建脚本
|
||||
* @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 commitHash = execSync("git rev-parse --short HEAD").toString().trim();
|
||||
|
||||
// 获取当前平台
|
||||
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}_${commitHash}_${platform}`;
|
||||
console.log(`🍄 gen sentry release ${release}`);
|
||||
|
||||
// 修改 .env.production
|
||||
const envPath = resolve(__dirname, "../.env.production");
|
||||
const envRead = parse(readFileSync(envPath, "utf-8"));
|
||||
envRead.VITE_SENTRY_RELEASE = release;
|
||||
writeFileSync(envPath, stringify(envRead), "utf-8");
|
||||
console.log("✅ .env.production updated!");
|
||||
|
||||
// 执行 pnpm build
|
||||
execSync("pnpm tauri build", { stdio: "inherit" });
|
||||
|
||||
// 上传pdb
|
||||
if (isGitHubActions) {
|
||||
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 upload-dif ${pdbGlob}`, { stdio: "inherit" });
|
||||
execSync(`sentry-cli releases finalize "${release}"`, { stdio: "inherit" });
|
||||
console.log("✅ PDB upload complete!");
|
||||
} catch (err) {
|
||||
console.error("❌ Failed to upload PDBs:", err);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
//! @file src/main.rs
|
||||
//! @desc 主模块,用于启动应用
|
||||
//! @since Beta v0.7.2
|
||||
// 主模块,用于启动应用
|
||||
// @since Beta v0.9.1
|
||||
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
@@ -9,11 +8,10 @@ fn main() {
|
||||
let _guard = sentry::init((
|
||||
"https://8d59057c08ff381e1fccf3c9e97c6a6c@o4510617609175040.ingest.de.sentry.io/4510617659506768",
|
||||
sentry::ClientOptions {
|
||||
release: sentry::release_name!(),
|
||||
// Capture user IPs and potentially sensitive headers when using HTTP server integrations
|
||||
// see https://docs.sentry.io/platforms/rust/data-management/data-collected for more info
|
||||
release: sentry::release_name!().into(),
|
||||
send_default_pii: true,
|
||||
..Default::default()
|
||||
}));
|
||||
|
||||
teyvat_guide_lib::run()
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import type { Event, UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";
|
||||
import { mkdir } from "@tauri-apps/plugin-fs";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { getBuildTime } from "@utils/TGBuild.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { getWindowSize, resizeWindow } from "@utils/TGWindow.js";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -384,7 +383,8 @@ async function checkUpdate(): Promise<void> {
|
||||
showSnackbar.error("请到设置页手动更新数据库!", 3000);
|
||||
return;
|
||||
}
|
||||
buildTime.value = getBuildTime();
|
||||
// @ts-expect-error import.meta
|
||||
buildTime.value = import.meta.env.VITE_SENTRY_RELEASE;
|
||||
await TGSqlite.update();
|
||||
showSnackbar.success("数据库已更新!", 3000);
|
||||
await openUrl("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");
|
||||
|
||||
@@ -8,8 +8,6 @@ import * as Sentry from "@sentry/vue";
|
||||
import { createApp } from "vue";
|
||||
import { createVuetify } from "vuetify";
|
||||
|
||||
import pkgJson from "../package.json" with { type: "json" };
|
||||
|
||||
import App from "./App.vue";
|
||||
import router from "./router/index.js";
|
||||
import store from "./store/index.js";
|
||||
@@ -23,7 +21,7 @@ const app = createApp(App);
|
||||
Sentry.init({
|
||||
app,
|
||||
dsn: "https://8d59057c08ff381e1fccf3c9e97c6a6c@o4510617609175040.ingest.de.sentry.io/4510617659506768",
|
||||
release: `TeyvatGuide@${pkgJson.version}`,
|
||||
release: import.meta.env.VITE_SENTRY_RELEASE,
|
||||
enableLogs: true,
|
||||
integrations: [
|
||||
Sentry.feedbackAsyncIntegration(<FeedbackInternalOptions>{
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
{{ deviceInfo.device_name }}({{ deviceInfo.product }}) - {{ deviceInfo.device_fp }}
|
||||
</v-list-item-subtitle>
|
||||
<template #append>
|
||||
<v-icon @click="confirmUpdateDevice(true)" title="强制刷新设备信息">mdi-bug</v-icon>
|
||||
<v-icon title="强制刷新设备信息" @click="confirmUpdateDevice(true)">mdi-bug</v-icon>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="清除缓存" @click="confirmDelCache">
|
||||
@@ -64,7 +64,7 @@
|
||||
</v-list-item>
|
||||
<v-list-subheader :inset="true" class="config-header" title="调试" @click="tryShowReset" />
|
||||
<v-divider :inset="true" class="border-opacity-75" />
|
||||
<v-list-item v-if="isDevEnv" title="调试模式" subtitle="开启后将显示调试信息">
|
||||
<v-list-item v-if="isDevEnv" subtitle="开启后将显示调试信息" title="调试模式">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-bug-play</v-icon>
|
||||
@@ -73,15 +73,15 @@
|
||||
<template #append>
|
||||
<v-switch
|
||||
v-model="devMode"
|
||||
:label="devMode ? '开启' : '关闭'"
|
||||
:inset="true"
|
||||
color="#FAC51E"
|
||||
:label="devMode ? '开启' : '关闭'"
|
||||
class="config-switch"
|
||||
color="#FAC51E"
|
||||
@click="submitDevMode"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="窗口回正" subtitle="根据分辨率动态调整窗体大小">
|
||||
<v-list-item subtitle="根据分辨率动态调整窗体大小" title="窗口回正">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-window-restore</v-icon>
|
||||
@@ -90,15 +90,15 @@
|
||||
<template #append>
|
||||
<v-switch
|
||||
v-model="isNeedResize"
|
||||
:label="isNeedResize ? '开启' : '关闭'"
|
||||
:inset="true"
|
||||
color="#FAC51E"
|
||||
:label="isNeedResize ? '开启' : '关闭'"
|
||||
class="config-switch"
|
||||
color="#FAC51E"
|
||||
@click="submitResize"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="关闭到托盘" subtitle="关闭窗口时最小化到系统托盘而不是退出应用">
|
||||
<v-list-item subtitle="关闭窗口时最小化到系统托盘而不是退出应用" title="关闭到托盘">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-tray-arrow-down</v-icon>
|
||||
@@ -107,14 +107,14 @@
|
||||
<template #append>
|
||||
<v-switch
|
||||
v-model="closeToTray"
|
||||
:label="closeToTray ? '开启' : '关闭'"
|
||||
:inset="true"
|
||||
:label="closeToTray ? '开启' : '关闭'"
|
||||
class="config-switch"
|
||||
color="#FAC51E"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="无痕浏览" subtitle="关闭后将记录帖子浏览记录">
|
||||
<v-list-item subtitle="关闭后将记录帖子浏览记录" title="无痕浏览">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-incognito</v-icon>
|
||||
@@ -123,15 +123,15 @@
|
||||
<template #append>
|
||||
<v-switch
|
||||
v-model="appStore.incognito"
|
||||
:label="appStore.incognito ? '开启' : '关闭'"
|
||||
:inset="true"
|
||||
:label="appStore.incognito ? '开启' : '关闭'"
|
||||
class="config-switch"
|
||||
color="#FAC51E"
|
||||
@click="switchIncognito"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="分享设置" v-if="platform() === 'windows'">
|
||||
<v-list-item v-if="platform() === 'windows'" title="分享设置">
|
||||
<template #subtitle>默认保存到剪贴板,超过{{ shareDefaultFile }}MB时保存到文件</template>
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
@@ -184,7 +184,6 @@ import { remove } from "@tauri-apps/plugin-fs";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { backUpUserData, restoreUserData } from "@utils/dataBS.js";
|
||||
import { getBuildTime } from "@utils/TGBuild.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { bytesToSize, getCacheDir, getDeviceInfo, getRandomString } from "@utils/toolFunc.js";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -292,7 +291,8 @@ async function confirmUpdate(title?: string): Promise<void> {
|
||||
}
|
||||
await showLoading.start("正在更新数据库", "");
|
||||
await TGSqlite.update();
|
||||
buildTime.value = getBuildTime();
|
||||
// @ts-expect-error import.meta
|
||||
buildTime.value = import.meta.env.VITE_SENTRY_RELEASE;
|
||||
await showLoading.end();
|
||||
showSnackbar.success("数据库已更新!即将刷新页面");
|
||||
await TGLogger.Info("[Config][confirmUpdate] 数据库更新完成");
|
||||
@@ -446,9 +446,8 @@ async function tryShowReset(): Promise<void> {
|
||||
showSnackbar.cancel("已取消");
|
||||
return;
|
||||
}
|
||||
const time = getBuildTime();
|
||||
const code = time.startsWith("dev.") ? "dev" : time;
|
||||
if (codeInput === code || codeInput === "reset1128") {
|
||||
// @ts-expect-error import.meta
|
||||
if (codeInput === import.meta.env.VITE_SENTRY_RELEASE || codeInput === "reset1128") {
|
||||
showReset.value = true;
|
||||
showSnackbar.success("已开启重置数据库选项");
|
||||
return;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Sqlite 初始化数据 sql 语句
|
||||
* @since Beta v0.7.2
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
|
||||
import { app } from "@tauri-apps/api";
|
||||
import { getBuildTime } from "@utils/TGBuild.js";
|
||||
|
||||
import createTable from "./createTable.sql?raw";
|
||||
|
||||
@@ -16,7 +15,8 @@ import createTable from "./createTable.sql?raw";
|
||||
async function initAppData(): Promise<Array<string>> {
|
||||
const sqlRes: Array<string> = [];
|
||||
const appVersion = await app.getVersion();
|
||||
const buildTime: string = getBuildTime();
|
||||
// @ts-expect-error import.meta
|
||||
const buildTime: string = import.meta.VITE_SENTRY_RELEASE;
|
||||
// 初始化应用版本
|
||||
sqlRes.push(`
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* 用于获取 vite 打包时间
|
||||
* @see https://gitee.com/lihanspace/vite-plugin-build-time
|
||||
* @since Alpha v0.1.4
|
||||
*/
|
||||
|
||||
import type { Plugin } from "vite";
|
||||
|
||||
const buildTimeKey = "buildTime";
|
||||
|
||||
const buildTimePlugin = (modes: Array<string> = []): Plugin => {
|
||||
let _mode = "";
|
||||
return {
|
||||
name: "build-time",
|
||||
config(uc, { mode }) {
|
||||
_mode = mode;
|
||||
},
|
||||
transformIndexHtml() {
|
||||
if (_mode !== "production" && !modes.includes(_mode)) return;
|
||||
return [
|
||||
{
|
||||
tag: "script",
|
||||
children: `window.${buildTimeKey} = '${Math.floor(Date.now() / 1000)}'`,
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getBuildTime = (): string => {
|
||||
if (typeof window === "undefined") {
|
||||
console.warn("getBuildTime() should only be called in the browser");
|
||||
return "dev";
|
||||
}
|
||||
const windowEnv = <typeof window & { [buildTimeKey]?: string }>window;
|
||||
if (!windowEnv[buildTimeKey]) {
|
||||
console.info("当前环境为开发环境");
|
||||
return `dev.${Math.floor(Date.now() / 1000)}`;
|
||||
}
|
||||
return windowEnv[buildTimeKey];
|
||||
};
|
||||
|
||||
export default buildTimePlugin;
|
||||
4
src/vite-env.d.ts
vendored
4
src/vite-env.d.ts
vendored
@@ -26,6 +26,10 @@ declare type ImportMeta = {
|
||||
* - `"test"` 测试模式
|
||||
*/
|
||||
MODE: string;
|
||||
/**
|
||||
* Sentry Release
|
||||
*/
|
||||
VITE_SENTRY_RELEASE: string;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -10,25 +10,20 @@ import { defineConfig } from "vite";
|
||||
import VueDevtools from "vite-plugin-vue-devtools";
|
||||
import vuetify from "vite-plugin-vuetify";
|
||||
|
||||
import pkgJson from "./package.json" with { type: "json" };
|
||||
import buildTimePlugin from "./src/utils/TGBuild.js";
|
||||
|
||||
const host = process.env.TAURI_DEV_HOST;
|
||||
const commitHash = (process.env.APP_VERSION || "test").slice(0, 7);
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
vuetify(),
|
||||
buildTimePlugin(),
|
||||
VueDevtools(),
|
||||
sentryVitePlugin({
|
||||
org: "teyvat-guide",
|
||||
project: "teyvat-guide",
|
||||
authToken: process.env.SENTRY_AUTH_TOKEN ?? "",
|
||||
release: {
|
||||
name: `TeyvatGuide@${pkgJson.version}_${commitHash}`,
|
||||
name: process.env.VITE_SENTRY_RELEASE,
|
||||
setCommits: { auto: true },
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user