sync version

This commit is contained in:
Julian Freeman
2026-02-22 17:28:55 -04:00
parent fa278a6a8b
commit 2539fa44ec
3 changed files with 39 additions and 2 deletions

View File

@@ -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",

34
scripts/sync-version.js Normal file
View File

@@ -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.');

View File

@@ -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 }}
</div>
<div class="text-[10px] text-slate-400">
GemmaTrans v0.1.0
GemmaTrans v{{ pkg.version }}
</div>
</footer>
</div>