use std::fs::File;
use std::env;
use std::fs;
use std::path::Path;
fn main() {
dotenv::dotenv().unwrap();
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("add_custom_state.rs");
let state_path = "daemon_state.json".to_string();
File::open(state_path.clone()).unwrap_or_else(|_| panic!("File should be present at {}", state_path));
fs::write(
dest_path,
format!(
"
use cw_orch::prelude::CwEnv;
pub fn custom_state<T: CwEnv>(chain: &mut T){{
chain.custom_state_file(\"{}\".to_string())
}}", state_path)
).unwrap();
assert!(std::fs::metadata("./artifacts").is_ok(), "You should create an artifacts dir in your crate to export the wasm files along with the cw-orch library");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed={}",state_path);
}