russel 0.0.3

A simple static site builder I built for myself.
Documentation
use crate::error::{Result, RussError};
use std::fs;
use std::path::Path;

pub fn create_directory_safe(path: &Path) -> Result<()> {
    // Check if directory already exists
    if path.exists() {
        return Err(RussError::new_project(format!(
            "The directory '{}' already exists",
            path.to_string_lossy()
        )));
    }

    // Create the directory
    fs::create_dir(path).map_err(|err| {
        RussError::new_project_with_source(
            format!("Failed to create directory '{}'", path.to_string_lossy()),
            err,
        )
    })?;

    Ok(())
}

pub fn create_file_safe(path: &Path, content: &str) -> Result<()> {
    // Check if file already exists
    if path.exists() {
        return Err(RussError::new_project(format!(
            "The file '{}' already exists",
            path.to_string_lossy()
        )));
    }

    // Create the file and write content
    fs::write(path, content).map_err(|err| {
        RussError::new_project_with_source(
            format!("Failed to create file '{}'", path.to_string_lossy()),
            err,
        )
    })?;

    Ok(())
}