Files
gamenight/backend-actix/build.rs

41 lines
1.0 KiB
Rust

use std::{
fs::{exists, read_dir, remove_dir_all, File},
io::Write,
process::Command,
};
fn main() {
println!("cargo::rerun-if-changed=gamenight-api.yaml");
if exists("src/models").unwrap() {
remove_dir_all("src/models").unwrap();
}
let _ = Command::new("openapi-generator")
.args([
"generate",
"-i",
"gamenight-api.yaml",
"-g",
"rust",
"--global-property",
"models",
])
.output()
.expect("Failed to generate models sources for the gamenight API");
let mut file = File::create("src/models/mod.rs").unwrap();
let paths = read_dir("./src/models").unwrap();
for path in paths {
let path = path.unwrap();
let path = path.path();
let stem = path.file_stem().unwrap();
if stem == "mod" {
continue;
}
let line = format!("pub mod {};\n", stem.to_str().unwrap());
let _ = file.write(line.as_bytes()).unwrap();
}
}