Skip to main content

conduit_cli/core/io/project/
mod.rs

1pub mod manifest;
2pub mod lock;
3
4use std::fs;
5use crate::core::error::{CoreError, CoreResult};
6use crate::core::paths::CorePaths;
7pub use manifest::{ConduitConfig, InstanceType};
8pub use lock::ConduitLock;
9
10pub struct ProjectFiles;
11
12impl ProjectFiles {
13    pub fn load_manifest(paths: &CorePaths) -> CoreResult<ConduitConfig> {
14        let content = fs::read_to_string(paths.manifest_path())
15            .map_err(|_| CoreError::MissingConfig)?;
16        ConduitConfig::from_json(&content)
17    }
18
19    pub fn save_manifest(paths: &CorePaths, config: &ConduitConfig) -> CoreResult<()> {
20        let json = config.to_json()?;
21        fs::write(paths.manifest_path(), json)
22            .map_err(|e| CoreError::RuntimeError(format!("Failed to write conduit.json: {e}")))
23    }
24
25    pub fn load_lock(paths: &CorePaths) -> CoreResult<ConduitLock> {
26        let path = paths.lock_path();
27        if !path.exists() {
28            return Ok(ConduitLock::default());
29        }
30        let content = fs::read_to_string(path)
31            .map_err(|e| CoreError::RuntimeError(format!("Failed to read conduit.lock: {e}")))?;
32        ConduitLock::from_toml(&content)
33    }
34
35    pub fn save_lock(paths: &CorePaths, lock: &ConduitLock) -> CoreResult<()> {
36        let toml = lock.to_toml_with_header()?;
37        fs::write(paths.lock_path(), toml)
38            .map_err(|e| CoreError::RuntimeError(format!("Failed to write conduit.lock: {e}")))
39    }
40}