chore: refactor version syncing logic in sync-version.ts
This commit is contained in:
1 parent
57158bab15
commit
e1c6e35f95
1 file changed
+12
-5
+12
-5
@@ -3,19 +3,26 @@ import path from 'path';
|
|||||||
import * as toml from '@iarna/toml';
|
import * as toml from '@iarna/toml';
|
||||||
import { cwd } from 'process';
|
import { cwd } from 'process';
|
||||||
|
|
||||||
|
const packageJsonPath = path.join(cwd(), 'package.json');
|
||||||
const cargoTomlPath = path.join(cwd(), 'src-tauri', 'Cargo.toml');
|
const cargoTomlPath = path.join(cwd(), 'src-tauri', 'Cargo.toml');
|
||||||
const tauriConfPath = path.join(cwd(), 'src-tauri', 'tauri.conf.json');
|
const tauriConfPath = path.join(cwd(), 'src-tauri', 'tauri.conf.json');
|
||||||
|
|
||||||
const cargoToml = fs.readFileSync(cargoTomlPath, 'utf8');
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
const cargo = toml.parse(cargoToml) as Record<string, string>;
|
const version = packageJson.version;
|
||||||
|
if (!version) throw new Error('Could not find version in package.json');
|
||||||
|
|
||||||
const version = cargo.package['version'];
|
let cargoTomlContent = fs.readFileSync(cargoTomlPath, 'utf8');
|
||||||
if (!version) throw new Error('Could not find version in Cargo.toml');
|
const cargo = toml.parse(cargoTomlContent) as { package: { version: string } };
|
||||||
|
|
||||||
|
if (cargo.package.version !== version) {
|
||||||
|
cargoTomlContent = cargoTomlContent.replace(/version = ".*?"/, `version = "${version}"`);
|
||||||
|
fs.writeFileSync(cargoTomlPath, cargoTomlContent);
|
||||||
|
console.log(`✅ Synced Cargo.toml version to ${version}`);
|
||||||
|
}
|
||||||
|
|
||||||
const tauriConf = JSON.parse(fs.readFileSync(tauriConfPath, 'utf8'));
|
const tauriConf = JSON.parse(fs.readFileSync(tauriConfPath, 'utf8'));
|
||||||
if (tauriConf.version !== version) {
|
if (tauriConf.version !== version) {
|
||||||
tauriConf.version = version;
|
tauriConf.version = version;
|
||||||
|
|
||||||
fs.writeFileSync(tauriConfPath, JSON.stringify(tauriConf, null, 2));
|
fs.writeFileSync(tauriConfPath, JSON.stringify(tauriConf, null, 2));
|
||||||
console.log(`✅ Synced tauri.conf.json version to ${version}`);
|
console.log(`✅ Synced tauri.conf.json version to ${version}`);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user