use crate::error::{HylixError, HylixResult};
use std::path::Path;
#[derive(Debug, Clone, Copy)]
pub enum ValidationLevel {
Build, Run, Test, Clean, }
pub fn validate_project(level: ValidationLevel) -> HylixResult<()> {
match level {
ValidationLevel::Build => {
require_dir("contracts")?;
require_dir("server")?;
}
ValidationLevel::Run => {
require_dir("server")?;
}
ValidationLevel::Test => {
require_dir("contracts")?;
require_dir("server")?;
if !Path::new("tests").exists() {
crate::logging::log_info("No 'tests' directory found, running unit tests only");
}
}
ValidationLevel::Clean => {
if !Path::new("contracts").exists()
&& !Path::new("server").exists()
&& !Path::new("front").exists()
{
return Err(HylixError::project(
"No project directories found. Are you in a Hylix project directory?",
));
}
}
}
Ok(())
}
fn require_dir(name: &str) -> HylixResult<()> {
if !Path::new(name).exists() {
return Err(HylixError::project(format!(
"No '{name}' directory found. Are you in a Hylix project directory?"
)));
}
Ok(())
}