diff --git a/package.json b/package.json index 9a15fe9..d28e1e1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "dev": "vite", "build": "vue-tsc --noEmit && vite build", "preview": "vite preview", - "tauri": "tauri" + "tauri": "tauri", + "sync-version": "node scripts/sync-version.js", + "postversion": "pnpm sync-version" }, "dependencies": { "@tailwindcss/vite": "^4.2.0", diff --git a/scripts/sync-version.js b/scripts/sync-version.js new file mode 100644 index 0000000..3775b9d --- /dev/null +++ b/scripts/sync-version.js @@ -0,0 +1,34 @@ +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const rootDir = path.join(__dirname, '..'); + +// 1. 获取 package.json 的版本号 +const pkgPath = path.join(rootDir, 'package.json'); +const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); +const version = pkg.version; + +console.log(`[Version Sync] New version detected: v${version}`); + +// 2. 更新 src-tauri/tauri.conf.json +const tauriConfPath = path.join(rootDir, 'src-tauri', 'tauri.conf.json'); +if (fs.existsSync(tauriConfPath)) { + const tauriConf = JSON.parse(fs.readFileSync(tauriConfPath, 'utf8')); + tauriConf.version = version; + fs.writeFileSync(tauriConfPath, JSON.stringify(tauriConf, null, 2) + '\n'); + console.log(`[Version Sync] Updated src-tauri/tauri.conf.json`); +} + +// 3. 更新 src-tauri/Cargo.toml +const cargoTomlPath = path.join(rootDir, 'src-tauri', 'Cargo.toml'); +if (fs.existsSync(cargoTomlPath)) { + let cargoToml = fs.readFileSync(cargoTomlPath, 'utf8'); + // 匹配 [package] 下的首个 version = "..." + cargoToml = cargoToml.replace(/^version\s*=\s*".*"/m, `version = "${version}"`); + fs.writeFileSync(cargoTomlPath, cargoToml); + console.log(`[Version Sync] Updated src-tauri/Cargo.toml`); +} + +console.log('[Version Sync] All versions are now synchronized.'); diff --git a/src/App.vue b/src/App.vue index 6f6afab..323443f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -14,6 +14,7 @@ import { } from 'lucide-vue-next'; import { fetch } from '@tauri-apps/plugin-http'; import { useSettingsStore, LANGUAGES, DEFAULT_TEMPLATE } from './stores/settings'; +import pkg from '../package.json'; import { clsx, type ClassValue } from 'clsx'; import { twMerge } from 'tailwind-merge'; @@ -449,7 +450,7 @@ const translate = async () => { {{ settings.ollamaApiAddress }}