33 lines
867 B
Rust
33 lines
867 B
Rust
use jana_sessions_webpage::webpage::SessionConfig;
|
|
use serde::Serialize;
|
|
use std::fs::File;
|
|
use std::path::Path;
|
|
use std::{env, fs, io};
|
|
|
|
fn main() -> io::Result<()> {
|
|
let out_dir = env::var_os("TRUNK_STAGING_DIR").unwrap_or("target/default_configs".into());
|
|
fs::create_dir_all(&out_dir)?;
|
|
|
|
create_default_config::<SessionConfig, _>("session_config", &out_dir)?;
|
|
Ok(())
|
|
}
|
|
|
|
fn create_default_config<T, P>(name: &str, out_dir: P) -> io::Result<()>
|
|
where
|
|
T: Serialize + Default,
|
|
P: AsRef<Path>,
|
|
{
|
|
create_config(name, out_dir, &T::default())
|
|
}
|
|
|
|
fn create_config<T, P>(name: &str, out_dir: P, default_config: &T) -> io::Result<()>
|
|
where
|
|
T: Serialize,
|
|
P: AsRef<Path>,
|
|
{
|
|
let out_path = out_dir.as_ref().join(format!("default_{name}.json"));
|
|
let out_file = File::create(&out_path)?;
|
|
serde_json::to_writer_pretty(out_file, default_config)?;
|
|
Ok(())
|
|
}
|