use std::path::PathBuf;
use ts_rs::{Config, TS};
use workload_spec::*;
const HEADER: &str = "\
// AUTO-GENERATED by `cargo run -p yah-workload-spec --bin export-ts`.
// Source of truth: crates/yah/workload-spec/src/lib.rs.
// Do not edit by hand. Regenerate after changing the Rust types and commit
// the result; CI fails if this file drifts from the Rust schema.
";
fn main() {
let cfg = Config::default();
let mut out = String::from(HEADER);
macro_rules! emit {
($t:ty) => {
out.push_str("export ");
out.push_str(&<$t as TS>::decl(&cfg));
out.push_str("\n\n");
};
}
emit!(SchemaVersion);
emit!(Millis);
emit!(MachineId);
emit!(MeshIdent);
emit!(TierTag);
emit!(MeshLookup);
emit!(EnvValue);
emit!(EnvVar);
emit!(SecretRef);
emit!(SecretTarget);
emit!(SecretMount);
emit!(VolumeSource);
emit!(VolumeMount);
emit!(ImageRef);
emit!(ResourceLimits);
emit!(HealthProbe);
emit!(Healthcheck);
emit!(BackoffPolicy);
emit!(RestartPolicy);
emit!(StopPolicy);
emit!(MeshExpose);
emit!(PublicTls);
emit!(PublicExpose);
emit!(OperatorExpose);
emit!(ExposeSpec);
emit!(WorkloadSpec);
emit!(BuildConfig);
emit!(BuildMode);
emit!(MesofactStaticWorkload);
emit!(AlmanacTarget);
emit!(NotReadyPolicy);
emit!(Cadence);
emit!(AlmanacManifest);
emit!(BlakeHash);
emit!(License);
emit!(FetchSource);
emit!(TransformSpec);
emit!(AssetDerive);
emit!(AssetEntry);
emit!(StaticAssetWorkload);
emit!(Workload);
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace_root = manifest_dir
.parent()
.and_then(|p| p.parent())
.and_then(|p| p.parent())
.expect("CARGO_MANIFEST_DIR has at least three parents");
let path = workspace_root.join("packages/yah/workload-spec/index.ts");
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent).expect("create parent dirs");
}
std::fs::write(&path, &out).expect("write index.ts");
println!("Wrote {} ({} bytes)", path.display(), out.len());
}