use axoasset::SourceFile;
use camino::Utf8PathBuf;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::errors::*;
use super::{BuildLayer, ComponentLayer, MarketingLayer, ProjectLayer, StyleLayer, WorkspaceLayer};
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct OrandaLayer {
pub project: Option<ProjectLayer>,
pub build: Option<BuildLayer>,
pub marketing: Option<MarketingLayer>,
pub styles: Option<StyleLayer>,
pub components: Option<ComponentLayer>,
pub workspace: Option<WorkspaceLayer>,
#[serde(rename = "$schema")]
pub _schema: Option<String>,
}
impl OrandaLayer {
pub fn load(config_path: &Utf8PathBuf) -> Result<Option<OrandaLayer>> {
let config_result = SourceFile::load_local(config_path.as_path());
match config_result {
Ok(config) => {
let data: OrandaLayer = config.deserialize_json()?;
Ok(Some(data))
}
Err(_) => {
tracing::debug!("No config found, using default values");
Ok(None)
}
}
}
}