build.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. use std::{
  2. env,
  3. env::current_dir,
  4. error::Error,
  5. fs::{read_to_string, File},
  6. io::{BufWriter, Write},
  7. path::Path,
  8. };
  9. mod config_definition;
  10. pub fn main() -> Result<(), Box<dyn Error>> {
  11. let out_dir = env::var("OUT_DIR")?;
  12. let dest_bundle_umd_path = Path::new(&out_dir).join("tauri.bundle.umd.js");
  13. let mut bundle_umd_file = BufWriter::new(File::create(&dest_bundle_umd_path)?);
  14. let bundle_umd_path = current_dir()?.join("../../api/dist/tauri.bundle.umd.js");
  15. println!("cargo:rerun-if-changed={:?}", bundle_umd_path);
  16. if let Ok(bundle_umd_js) = read_to_string(bundle_umd_path) {
  17. write!(bundle_umd_file, "{}", bundle_umd_js)?;
  18. } else {
  19. write!(
  20. bundle_umd_file,
  21. r#"throw new Error("you are trying to use the global Tauri script but the @tauri-apps/api package wasn't compiled; run `yarn build` first")"#
  22. )?;
  23. }
  24. let schema = schemars::schema_for!(config_definition::Config);
  25. let schema_file_path = current_dir()?.join("schema.json");
  26. let mut schema_file = BufWriter::new(File::create(&schema_file_path)?);
  27. write!(
  28. schema_file,
  29. "{}",
  30. serde_json::to_string_pretty(&schema).unwrap()
  31. )?;
  32. Ok(())
  33. }