mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-05 15:29:06 +00:00
Read metadata to update project information
This commit is contained in:
parent
c7ae71863f
commit
3adad8fb55
@ -2,6 +2,54 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri_build::build();
|
tauri_build::build();
|
||||||
|
|
||||||
|
// Tells Cargo to re-run this script only, when the version.txt file was changed:
|
||||||
|
println!("cargo:rerun-if-changed=../metadata.txt");
|
||||||
|
|
||||||
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||||
println!("cargo:rustc-env=OUT_DIR={}", out_dir.to_str().unwrap());
|
println!("cargo:rustc-env=OUT_DIR={}", out_dir.to_str().unwrap());
|
||||||
|
|
||||||
|
let metadata = include_str!("../metadata.txt");
|
||||||
|
let mut metadata_lines = metadata.lines();
|
||||||
|
let version = metadata_lines.next().unwrap();
|
||||||
|
|
||||||
|
update_cargo_toml("Cargo.toml", version);
|
||||||
|
update_tauri_conf("tauri.conf.json", version);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_cargo_toml(cargo_path: &str, version: &str) {
|
||||||
|
let cargo_toml = std::fs::read_to_string(cargo_path).unwrap();
|
||||||
|
let cargo_toml_lines = cargo_toml.lines();
|
||||||
|
let mut new_cargo_toml = String::new();
|
||||||
|
|
||||||
|
for line in cargo_toml_lines {
|
||||||
|
if line.starts_with("version = ") {
|
||||||
|
new_cargo_toml.push_str(&format!("version = \"{version}\""));
|
||||||
|
} else {
|
||||||
|
new_cargo_toml.push_str(line);
|
||||||
|
}
|
||||||
|
new_cargo_toml.push('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
std::fs::write(cargo_path, new_cargo_toml).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_tauri_conf(tauri_conf_path: &str, version: &str) {
|
||||||
|
let tauri_conf = std::fs::read_to_string(tauri_conf_path).unwrap();
|
||||||
|
let tauri_conf_lines = tauri_conf.lines();
|
||||||
|
let mut new_tauri_conf = String::new();
|
||||||
|
|
||||||
|
for line in tauri_conf_lines {
|
||||||
|
// The version in Tauri's config is formatted like this:
|
||||||
|
// "version": "0.1.0-alpha.0"
|
||||||
|
// Please notice, that the version number line might have a leading tab, etc.
|
||||||
|
if line.contains("\"version\": ") {
|
||||||
|
new_tauri_conf.push_str(&format!("\t\"version\": \"{version}\""));
|
||||||
|
} else {
|
||||||
|
new_tauri_conf.push_str(line);
|
||||||
|
}
|
||||||
|
new_tauri_conf.push('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
std::fs::write(tauri_conf_path, new_tauri_conf).unwrap();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user