use std::io;
use std::path::Path;
use arora_registry::local::LocalRegistry;
use arora_registry::local_yaml::write_records_to_yaml_dir;
use arora_types::module::low::{Executor, Header};
use crate::animation;
pub const GUEST_FILE: &str = "animation.wasm";
pub fn guest_header() -> Header {
animation::header(Executor {
name: "wasm".to_string(),
min_version: None,
max_version: None,
})
}
pub fn records() -> LocalRegistry {
let mut registry = LocalRegistry::new();
futures::executor::block_on(
registry.add_declared_module::<animation::Module>(guest_header().version.into()),
)
.expect("the declaration's records add to an empty registry");
registry
}
pub fn write(dir: &Path, guest: Option<&Path>) -> io::Result<()> {
std::fs::create_dir_all(dir)?;
let header = serde_json::to_string_pretty(&guest_header()).map_err(io::Error::other)?;
std::fs::write(dir.join("header.json"), header)?;
let records = dir.join("records");
if records.exists() {
std::fs::remove_dir_all(&records)?;
}
write_records_to_yaml_dir(&self::records(), &records).map_err(io::Error::other)?;
if let Some(guest) = guest {
std::fs::copy(guest, dir.join(GUEST_FILE))?;
}
Ok(())
}