From 40b5cacbeb39ea4e287e28ace973bee063386774 Mon Sep 17 00:00:00 2001 From: OldGodShen <2415479434@qq.com> Date: Fri, 7 Jun 2024 00:21:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update-version.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 update-version.ts diff --git a/update-version.ts b/update-version.ts new file mode 100644 index 0000000..ad3696a --- /dev/null +++ b/update-version.ts @@ -0,0 +1,37 @@ +import fs from 'fs'; +import path from 'path'; +import toml from 'toml'; + +const packageJsonPath = path.join(__dirname, 'package.json'); +const cargoTomlPath = path.join(__dirname, 'src-tauri', 'Cargo.toml'); +const tauriConfJsonPath = path.join(__dirname, 'src-tauri', 'tauri.conf.json'); + +const newVersion = process.argv[2]; + +if (!newVersion) { + console.error('Please provide a new version.'); + process.exit(1); +} + +// Update package.json +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); +packageJson.version = newVersion; +fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); +console.log(`Updated package.json to version ${newVersion}`); + +// Update Cargo.toml +const cargoTomlContent = fs.readFileSync(cargoTomlPath, 'utf8'); +const cargoToml = toml.parse(cargoTomlContent); +cargoToml.package.version = newVersion; +const newCargoTomlContent = cargoTomlContent.replace( + /version\s*=\s*".*"/, + `version = "${newVersion}"` +); +fs.writeFileSync(cargoTomlPath, newCargoTomlContent); +console.log(`Updated Cargo.toml to version ${newVersion}`); + +// Update tauri.conf.json +const tauriConfJson = JSON.parse(fs.readFileSync(tauriConfJsonPath, 'utf8')); +tauriConfJson.version = newVersion; +fs.writeFileSync(tauriConfJsonPath, JSON.stringify(tauriConfJson, null, 2)); +console.log(`Updated tauri.conf.json to version ${newVersion}`);