kmmp-project-manager 0.1.0

kmmp-project-manager is a Rust crate for Kotlin Multiplatform (KMP) projects, offering a lightweight alternative to Android Studio. It provides tools for project creation, structure management, build automation, code generation, IDE integration, dependency management, and project configuration.
Documentation
use crate::{
    Plugins,
    Metadata,
    ModuleContent,
};

use serde::{Serialize,Deserialize};

#[cfg(feature = "generate")]
use std::{
    fs::File,
    io::Write
};

/// Represents the build.gradle.kts of the module
#[derive(Deserialize, Serialize, Debug, PartialEq)]
#[serde(bound(deserialize = "'de: 'a"))]
pub struct ModuleGradle<'a> { 
    /// The plugins applied to the module.
    pub plugins: Plugins<'a>,
    /// The metadata of the module.
    pub metadata: Metadata<'a>,
    /// The content of the module.
    pub module_content: ModuleContent<'a>,
}

impl<'a> ModuleGradle<'a> {
     /// Name of generated file name for struct
     pub const FILE_NAME : &str = "build.gradle.kts";

    /// Creates a new `ModuleGradle` instance.
    ///
    /// # Arguments
    ///
    /// * `plugins` - The plugins configuration.
    /// * `metadata` - The metadata of the module.
    /// * `module_content` - The content of the module.
    ///
    /// # Example
    ///
    /// ```
    /// let plugins = Plugins::new(/* plugins details */);
    /// let metadata = Metadata::new(/* metadata details */);
    /// let module_content = ModuleContent::SourceSets(/* source sets details */);
    ///
    /// let module_gradle = ModuleGradle::new(plugins, metadata, module_content);
    /// ```
    pub fn new(plugins: Plugins<'a>, metadata: Metadata<'a>, module_content: ModuleContent<'a>) -> Self {
        ModuleGradle {
            plugins,
            metadata,
            module_content,
        }
    }
}

impl std::fmt::Display for ModuleGradle<'_> {
    /// Formats the `ModuleGradle` as a string.
    ///
    /// # Example
    ///
    /// ```
    /// let plugins = Plugins::new(/* plugins details */);
    /// let metadata = Metadata::new(/* metadata details */);
    /// let module_content = ModuleContent::SourceSets(/* source sets details */);
    ///
    /// let module_gradle = ModuleGradle::new(plugins, metadata, module_content);
    ///
    /// assert_eq!(module_gradle.to_string(), "/* formatted module.gradle file */");
    /// ```
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f,"{}\n",self.plugins.to_string())?;
        write!(f,"{}\n",self.metadata.to_string())?;
        write!(f,"{}\n",self.module_content.to_string())
    }
}

#[cfg(feature = "generate")]
impl crate::Generate for ModuleGradle<'_> {
    fn generate(&self,directory : &str) {
        let create_directory = format!("{}\\{}",directory,Self::FILE_NAME);
        let _ = File::create(&create_directory).expect("Error Creating File").write_all(self.to_string().as_bytes());
    }
}