1use dmc_diagnostic::{Code, DiagResult};
2use duck_diagnostic::diag;
3use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6use crate::engine::{collection::Collection, compile::CompileConfig};
7
8#[derive(Debug, Deserialize, Serialize, Clone)]
10#[serde(default)]
11pub struct EngineConfig {
12 pub root: PathBuf,
13 pub output_dir: PathBuf,
14 pub output_name: Option<String>,
15 pub output_format: Option<String>,
16 pub clean: bool,
17 pub strict: bool,
18 pub collections: Vec<Collection>,
19 pub include_html: bool,
20 pub cache_enabled: bool,
22
23 #[serde(flatten)]
24 pub compile: CompileConfig,
25}
26
27impl Default for EngineConfig {
28 fn default() -> Self {
29 Self {
30 root: PathBuf::new(),
31 output_dir: PathBuf::new(),
32 output_name: None,
33 output_format: None,
34 clean: false,
35 strict: false,
36 collections: Vec::new(),
37 include_html: false,
38 cache_enabled: true,
39 compile: CompileConfig::default(),
40 }
41 }
42}
43
44impl EngineConfig {
45 pub(crate) fn load(config_path: &PathBuf) -> DiagResult<EngineConfig> {
46 let raw = std::fs::read_to_string(config_path)
47 .map_err(|e| diag!(Code::InvalidConfigPath, format!("config error: {}", e.to_string())))?;
48
49 let cfg: EngineConfig =
50 toml::from_str(&raw).map_err(|e| diag!(Code::InvalidConfig, format!("config error: {}", e.to_string())))?;
51
52 Ok(cfg)
53 }
54}