use std::{fmt::Write, fs, io, path::Path};
pub mod javascript;
pub mod python;
pub mod rust;
pub use javascript::generate_javascript_client;
pub use python::generate_python_client;
pub use rust::generate_rust_client;
pub const MANUAL_GENERIC_TYPES: &[&str] = &["SeriesData", "SeriesEndpoint"];
pub fn write_description(output: &mut String, desc: &str, prefix: &str, empty_prefix: &str) {
for line in desc.lines() {
if line.is_empty() {
writeln!(output, "{}", empty_prefix).unwrap();
} else {
writeln!(output, "{}{}", prefix, line).unwrap();
}
}
}
pub fn normalize_return_type(return_type: &str) -> String {
let mut result = return_type.to_string();
for type_name in MANUAL_GENERIC_TYPES {
result = result.replace(type_name, &format!("Any{}", type_name));
}
result
}
pub fn write_if_changed(path: &Path, content: &str) -> io::Result<()> {
if let Ok(existing) = fs::read_to_string(path)
&& existing == content
{
return Ok(());
}
fs::write(path, content)
}