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)]
12#[serde(default)]
13pub struct EngineConfig {
14 pub root: PathBuf,
15 pub output_dir: PathBuf,
16 pub output_name: Option<String>,
17 pub output_format: Option<String>,
18 pub clean: bool,
19 pub strict: bool,
20 pub collections: Vec<Collection>,
21 pub include_html: bool,
22 pub cache_enabled: bool,
26
27 #[serde(flatten)]
28 pub compile: CompileConfig,
29}
30
31impl Default for EngineConfig {
32 fn default() -> Self {
33 Self {
34 root: PathBuf::new(),
35 output_dir: PathBuf::new(),
36 output_name: None,
37 output_format: None,
38 clean: false,
39 strict: false,
40 collections: Vec::new(),
41 include_html: false,
42 cache_enabled: true,
43 compile: CompileConfig::default(),
44 }
45 }
46}
47
48impl EngineConfig {
49 pub(crate) fn load(config_path: &PathBuf) -> DiagResult<EngineConfig> {
52 let raw = std::fs::read_to_string(config_path)
53 .map_err(|e| diag!(Code::InvalidConfigPath, format!("config error: {}", e.to_string())))?;
54
55 let cfg: EngineConfig =
56 toml::from_str(&raw).map_err(|e| diag!(Code::InvalidConfig, format!("config error: {}", e.to_string())))?;
57
58 Ok(cfg)
59 }
60}