use std::env;
use std::io::{Error, ErrorKind, Result};
use std::path::PathBuf;
use std::process::{Command, ExitStatus};
fn main() -> Result<()> {
let repo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let docs_dir = repo_root.join("apps").join("docs");
let mut npm_args: Vec<String> = vec!["run".to_string(), "openapi:generate".to_string()];
let passthrough: Vec<String> = env::args().skip(1).collect();
if !passthrough.is_empty() {
npm_args.push("--".to_string());
npm_args.extend(passthrough);
}
let npm_bin = if cfg!(windows) { "npm.cmd" } else { "npm" };
let status: ExitStatus = Command::new(npm_bin)
.current_dir(&docs_dir)
.args(&npm_args)
.status()
.map_err(|err| Error::new(ErrorKind::Other, format!("failed to run npm: {}", err)))?;
if status.success() {
println!("OpenAPI generation completed.");
Ok(())
} else {
Err(Error::new(
ErrorKind::Other,
format!("openapi generation failed with status {}", status),
))
}
}