mecha10-cli 0.1.47

Mecha10 CLI tool
Documentation
//! Meta project file template generation
//!
//! Handles generation of project metadata files:
//! - README.md
//! - .gitignore
//! - package.json
//! - requirements.txt

use crate::paths;
use anyhow::Result;
use std::path::Path;

/// Template files embedded at compile time
const README: &str = include_str!("../../templates/README.md.template");
const GITIGNORE: &str = include_str!("../../templates/.gitignore.template");
const PACKAGE_JSON: &str = include_str!("../../templates/package.json.template");
const REQUIREMENTS_TXT: &str = include_str!("../../templates/requirements.txt.template");

/// Meta template generator
pub struct MetaTemplates;

impl MetaTemplates {
    /// Create a new MetaTemplates instance
    pub fn new() -> Self {
        Self
    }

    /// Create README.md for the project
    ///
    /// # Arguments
    ///
    /// * `path` - Project root path
    /// * `project_name` - Name of the project
    pub async fn create_readme(&self, path: &Path, project_name: &str) -> Result<()> {
        let content = README.replace("{{project_name}}", project_name);
        tokio::fs::write(path.join(paths::meta::README), content).await?;
        Ok(())
    }

    /// Create .gitignore for the project
    pub async fn create_gitignore(&self, path: &Path) -> Result<()> {
        tokio::fs::write(path.join(paths::meta::GITIGNORE), GITIGNORE).await?;
        Ok(())
    }

    /// Create package.json for the project
    ///
    /// # Arguments
    ///
    /// * `path` - Project root path
    /// * `project_name` - Name of the project
    pub async fn create_package_json(&self, path: &Path, project_name: &str) -> Result<()> {
        let content = PACKAGE_JSON.replace("{{project_name}}", project_name);
        tokio::fs::write(path.join(paths::meta::PACKAGE_JSON), content).await?;
        Ok(())
    }

    /// Create requirements.txt for Python dependencies
    ///
    /// # Arguments
    ///
    /// * `path` - Project root path
    pub async fn create_requirements_txt(&self, path: &Path) -> Result<()> {
        tokio::fs::write(path.join(paths::meta::REQUIREMENTS_TXT), REQUIREMENTS_TXT).await?;
        Ok(())
    }
}

impl Default for MetaTemplates {
    fn default() -> Self {
        Self::new()
    }
}