Skip to content

Commit

Permalink
got build script working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneish committed Mar 28, 2023
1 parent 30dcdb1 commit 97c92ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ glcp = "0.1.2"
serde = "1.0.158"
serde_derive = "1.0.158"
toml = "0.7.3"

[build-dependencies]
dirs = "5.0.0"
17 changes: 15 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use std::env::var;
use dir::home_dir;
use std::path::PathBuf;
use std::include_str;
use std::fs;
use std::io::Write;
use dirs::home_dir;

fn generate_config() {
let mut home = home_dir().unwrap();
Expand All @@ -13,9 +17,18 @@ fn generate_config() {
default_config_path
}
};
if !config_path.exists() {
fs::create_dir_all(&config_path.parent().unwrap_or(&home_dir().expect("[error] Cannot find home directory.")))
.expect("[error] Could not create config directory.");
let mut new_config_file =
fs::File::create(&config_path).expect("[error] Could not create config file.");
new_config_file
.write_all(include_str!("src/resources/default.toml").as_bytes())
.expect("[error] Could not write to config file.");
};
}

fn main() {
println!("cargo:rerun-if-env-changed=SHRTCUT_CONFIG_FILE");
let _ = Configs::new();
generate_config();
}

0 comments on commit 97c92ba

Please sign in to comment.