use std::process::Command;
fn main() {
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.map(|out| out.stdout)
.unwrap_or_else(|_| "unknown".as_bytes().to_vec());
println!(
"cargo:rustc-env=GIT_HASH={}",
String::from_utf8(output).expect("failed to convert hash to valid utf8")
);
if let Ok(docs_path) = std::env::var("DOCS_DIR") {
let mut engine = vsmtp_rule_engine::RuleEngine::new_rhai_engine();
vsmtp_rule_engine::RuleEngine::build_static_modules(
&mut engine,
&vsmtp_config::Config::default(),
)
.expect("failed to build static modules");
let docs = rhai_autodocs::options()
.format_sections_with(rhai_autodocs::SectionFormat::Tabs)
.include_standard_packages(false)
.order_functions_with(rhai_autodocs::FunctionOrder::ByIndex)
.generate(&engine)
.expect("failed to generate documentation");
write_docs(&docs_path, &docs);
}
}
fn write_docs(path: &str, docs: &rhai_autodocs::ModuleDocumentation) {
std::fs::write(
std::path::PathBuf::from_iter([path, &format!("fn::{}.md", &docs.name)]),
&docs.documentation,
)
.expect("failed to write documentation");
for doc in &docs.sub_modules {
write_docs(path, doc);
}
}