use wasm_bindgen::prelude::*;
use crate::config::Config;
use crate::spec::registry::CommandRegistry;
#[wasm_bindgen]
pub fn format(source: &str, config_yaml: &str) -> Result<String, JsValue> {
let (config, commands_yaml) = Config::from_yaml_str_with_commands(config_yaml)
.map_err(|e| JsValue::from_str(&format!("config error: {e}")))?;
let mut registry =
CommandRegistry::load().map_err(|e| JsValue::from_str(&format!("registry error: {e}")))?;
if let Some(commands_yaml) = commands_yaml {
registry
.merge_yaml_overrides(commands_yaml.as_ref())
.map_err(|e| JsValue::from_str(&format!("spec error: {e}")))?;
}
crate::format_source_with_registry(source, &config, ®istry)
.map_err(|e| JsValue::from_str(&e.to_string()))
}
#[wasm_bindgen]
pub fn default_config_yaml() -> String {
crate::default_config_template()
}