Files
nyaterm/scripts/sync-version.mjs
T
Kang 7894e410c4 chore: bump version to 0.1.5 and add version synchronization script
- Updated version in package.json, Cargo.toml, Cargo.lock, and tauri.conf.json to 0.1.5.
- Introduced a new script (sync-version.mjs) to synchronize version across configuration files.
- Modified build and release scripts to include version synchronization.
2026-03-06 10:13:42 +08:00

29 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { readFileSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
const version = pkg.version;
// 同步到 tauri.conf.json
const tauriConf = JSON.parse(readFileSync('src-tauri/tauri.conf.json', 'utf-8'));
tauriConf.version = version;
writeFileSync('src-tauri/tauri.conf.json', JSON.stringify(tauriConf, null, 2) + '\n');
// 同步到 Cargo.toml(仅替换 [package] 下的 version,不影响依赖项的 version
let cargo = readFileSync('src-tauri/Cargo.toml', 'utf-8');
cargo = cargo.replace(
/(\[package\]\s*\nname\s*=\s*"[^"]*"\s*\n)version\s*=\s*"[^"]*"/,
`$1version = "${version}"`
);
writeFileSync('src-tauri/Cargo.toml', cargo);
console.log(`✅ Version synced to ${version}`);
// 如果传入 --commit 参数,自动提交版本变更
if (process.argv.includes('--commit')) {
const files = ['package.json', 'src-tauri/tauri.conf.json', 'src-tauri/Cargo.toml'];
execSync(`git add ${files.join(' ')}`, { stdio: 'inherit' });
execSync(`git commit -m "chore: bump version to v${version}"`, { stdio: 'inherit' });
console.log(`✅ Committed: chore: bump version to v${version}`);
}