client/apps/tauri/render-version.ts
Alois 7ea3b32286
All checks were successful
/ build-web (push) Successful in 1m9s
/ build-desktop (push) Successful in 11m16s
/ build-mobile (push) Successful in 15m50s
/ release (push) Successful in 23s
(feat): add native notifications
(feat): add navbar profile popover
(fix): chat input box click area to slim
(qol): format
2026-05-24 18:31:27 +02:00

65 lines
1.8 KiB
TypeScript

import fs from "fs";
import path from "path";
// Config
const PLACEHOLDER_VERSION = "0.0.0";
const rootPackageJsonPath = path.resolve(__dirname, "../../package.json");
const cargoTomlPath = path.resolve(__dirname, "./src-tauri/Cargo.toml");
const tauriConfigPath = path.resolve(__dirname, "./src-tauri/tauri.conf.json");
// Args
const isUnrender = process.argv.includes("--unrender");
// Version Source
const packageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath, "utf8"));
const packageVersion: string = packageJson.version;
if (!packageVersion && !isUnrender) {
throw new Error("No version found in package.json");
}
const targetVersion = isUnrender ? PLACEHOLDER_VERSION : packageVersion;
// Helpers
function updateCargoToml(content: string): string {
const regex = /^version\s*=\s*".*"$/m;
if (!regex.test(content)) {
throw new Error("Could not find version field in Cargo.toml");
}
return content.replace(regex, `version = "${targetVersion}"`);
}
function updateTauriConfig(content: string): string {
const regex = /"version"\s*:\s*".*"/;
if (!regex.test(content)) {
throw new Error("Could not find version field in tauri.conf.json");
}
return content.replace(regex, `"version": "${targetVersion}"`);
}
// Update Cargo.toml
const cargoToml = fs.readFileSync(cargoTomlPath, "utf8");
const updatedCargoToml = updateCargoToml(cargoToml);
fs.writeFileSync(cargoTomlPath, updatedCargoToml, "utf8");
// Update tauri.conf.json
const tauriConfig = fs.readFileSync(tauriConfigPath, "utf8");
const updatedTauriConfig = updateTauriConfig(tauriConfig);
fs.writeFileSync(tauriConfigPath, updatedTauriConfig, "utf8");
// Finished
if (isUnrender) {
console.log(`Unrendered versions back to ${PLACEHOLDER_VERSION}`);
} else {
console.log(`Rendered version ${targetVersion}`);
}