mod.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. use crate::{
  5. helpers::{
  6. app_paths::tauri_dir,
  7. cargo_manifest::{crate_version, CargoLock, CargoManifest},
  8. },
  9. interface::rust::get_workspace_dir,
  10. Result,
  11. };
  12. use std::{fs::read_to_string, str::FromStr};
  13. use anyhow::Context;
  14. mod migrations;
  15. pub fn command() -> Result<()> {
  16. crate::helpers::app_paths::resolve();
  17. let tauri_dir = tauri_dir();
  18. let manifest_contents =
  19. read_to_string(tauri_dir.join("Cargo.toml")).context("failed to read Cargo manifest")?;
  20. let manifest = toml::from_str::<CargoManifest>(&manifest_contents)
  21. .context("failed to parse Cargo manifest")?;
  22. let workspace_dir = get_workspace_dir()?;
  23. let lock_path = workspace_dir.join("Cargo.lock");
  24. let lock = if lock_path.exists() {
  25. let lockfile_contents = read_to_string(lock_path).context("failed to read Cargo lockfile")?;
  26. let lock =
  27. toml::from_str::<CargoLock>(&lockfile_contents).context("failed to parse Cargo lockfile")?;
  28. Some(lock)
  29. } else {
  30. None
  31. };
  32. let tauri_version = crate_version(tauri_dir, Some(&manifest), lock.as_ref(), "tauri")
  33. .version
  34. .context("failed to get tauri version")?;
  35. let tauri_version = semver::Version::from_str(&tauri_version)?;
  36. if tauri_version.major == 1 {
  37. migrations::v1::run().context("failed to migrate from v1")?;
  38. } else if tauri_version.major == 2 {
  39. if let Some((pre, _number)) = tauri_version.pre.as_str().split_once('.') {
  40. if pre == "beta" {
  41. migrations::v2_rc::run().context("failed to migrate from v2 beta to rc")?;
  42. }
  43. }
  44. }
  45. Ok(())
  46. }