use crate::manifest::Manifest; use anyhow::Result; use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ProjectConfig { #[serde(flatten)] pub manifest: Manifest, pub script_fe: String, pub entry: PathBuf, } impl ProjectConfig { pub fn load(project_dir: &Path) -> Result { let config_path = project_dir.join("prometeu.json"); let content = std::fs::read_to_string(&config_path)?; let config: ProjectConfig = serde_json::from_str(&content) .map_err(|e| anyhow::anyhow!("JSON error in {:?}: {}", config_path, e))?; // Use manifest validation crate::manifest::load_manifest(project_dir) .map_err(|e| anyhow::anyhow!("{}", e))?; Ok(config) } } #[cfg(test)] mod tests { use super::*; use std::fs; use tempfile::tempdir; #[test] fn test_load_valid_config() { let dir = tempdir().unwrap(); let config_path = dir.path().join("prometeu.json"); fs::write( config_path, r#"{ "name": "test_project", "version": "0.1.0", "script_fe": "pbs", "entry": "main.pbs" }"#, ) .unwrap(); let config = ProjectConfig::load(dir.path()).unwrap(); assert_eq!(config.manifest.name, "test_project"); assert_eq!(config.script_fe, "pbs"); assert_eq!(config.entry, PathBuf::from("main.pbs")); } }