use std::path::PathBuf;
use holochain_types::prelude::{AppManifest, AppManifestCurrentBuilder};
use holochain_types::web_app::{
AppManifestLocation, WebAppManifest, WebAppManifestCurrentBuilder, WebUI,
};
use crate::error::ScaffoldResult;
pub fn empty_happ_manifest(
app_name: &str,
app_description: Option<&str>,
) -> ScaffoldResult<String> {
let manifest: AppManifest = AppManifestCurrentBuilder::default()
.name(app_name.to_owned())
.description(app_description.map(String::from))
.roles(vec![])
.build()
.unwrap()
.into();
let s = serde_yaml::to_string(&manifest)?;
Ok(s)
}
pub fn web_happ_manifest<P: Into<PathBuf>>(
app_name: &str,
happ_path: P,
ui_zip_path: P,
) -> ScaffoldResult<String> {
let manifest: WebAppManifest = WebAppManifestCurrentBuilder::default()
.name(app_name.to_owned())
.happ(AppManifestLocation {
path: happ_path
.into()
.into_os_string()
.into_string()
.map_err(|str| anyhow::anyhow!("Invalid hApp path: {str:?}"))?,
})
.ui(WebUI {
path: ui_zip_path
.into()
.into_os_string()
.into_string()
.map_err(|str| anyhow::anyhow!("Invalid UI zip path: {str:?}"))?,
})
.build()
.unwrap()
.into();
let s = serde_yaml::to_string(&manifest)?;
Ok(s)
}