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 serde::{Serialize,Deserialize};
/// Representation of the module metadata
#[derive(Deserialize, Serialize, Debug, PartialEq, PartialOrd)]
pub struct Metadata<'a> {
    /// The module name.
    pub module_name : &'a str,
    /// The module namespace.
    pub namespace: &'a str,
    /// The module version.
    pub version: &'a str,
    /// The Java version required by the module (optional).
    pub java_version: Option<&'a str>,
    /// The minimum iOS deployment target version (optional).
    pub ios_deployment_target: Option<&'a str>,
    /// The minimum Android SDK version (optional).
    pub min_sdk: Option<u8>,
    /// The maximum Android SDK version (optional).
    pub max_sdk: Option<u8>,
}

impl<'a> Metadata<'a> {
    /// Creates a new `Metadata` instance with the specified module, namespace, and version.
    ///
    /// # Arguments
    ///
    /// * `module` - The module name.
    /// * `namespace` - The module namespace.
    /// * `version` - The module version.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_structure::gradle::Metadata;
    ///
    /// let metadata = Metadata::new("my-module", "com.example", "1.0.0");
    /// ```
    pub fn new(module_name: &'a str, namespace: &'a str, version: &'a str) -> Self {
        Metadata {
            module_name,
            namespace,
            version,
            java_version: None,
            ios_deployment_target: None,
            min_sdk: None,
            max_sdk: None,
        }
    }
    
    /// Sets the Java version for the module.
    ///
    /// # Arguments
    ///
    /// * `java_version` - The Java version.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_structure::gradle::Metadata;
    ///
    /// let metadata = Metadata::new("my-module", "com.example", "1.0.0")
    ///     .with_java_version("1.8");
    /// ```
    pub fn with_java_version(mut self, java_version: &'a str) -> Self {
        self.java_version = Some(java_version);
        self
    }
    
    /// Sets the iOS deployment target for the module.
    ///
    /// # Arguments
    ///
    /// * `ios_deployment_target` - The iOS deployment target.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_structure::gradle::Metadata;
    ///
    /// let metadata = Metadata::new("my-module", "com.example", "1.0.0")
    ///     .with_ios_deployment_target("12.0");
    /// ```
    pub fn with_ios_deployment_target(mut self, ios_deployment_target: &'a str) -> Self {
        self.ios_deployment_target = Some(ios_deployment_target);
        self
    }
    
    /// Sets the minimum SDK version for the module.
    ///
    /// # Arguments
    ///
    /// * `min_sdk` - The minimum SDK version.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_structure::gradle::Metadata;
    ///
    /// let metadata = Metadata::new("my-module", "com.example", "1.0.0")
    ///     .with_min_sdk(21);
    /// ```
    pub fn with_min_sdk(mut self, min_sdk: u8) -> Self {
        self.min_sdk = Some(min_sdk);
        self
    }
    
    /// Sets the maximum SDK version for the module.
    ///
    /// # Arguments
    ///
    /// * `max_sdk` - The maximum SDK version.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_structure::gradle::Metadata;
    ///
    /// let metadata = Metadata::new("my-module", "com.example", "1.0.0")
    ///     .with_max_sdk(30);
    /// ```
    pub fn with_max_sdk(mut self, max_sdk: u8) -> Self {
        self.max_sdk = Some(max_sdk);
        self
    }
}

impl std::fmt::Display for Metadata<'_> {
    /// Formats the `Metadata` as a string.
    ///
    /// # Example
    ///
    /// ```
    /// use kmmp_structure::gradle::Metadata;
    ///
    /// let metadata = Metadata::new("my-module", "com.example", "1.0.0");
    ///
    /// assert_eq!(metadata.to_string(), "/* formatted metadata */");
    /// ```
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 
        write!(f, "object Metadata {{\n")?;
        write!(f, "    const val {} = \"{}\"\n", "module", self.module_name)?;
        write!(f, "    const val {} = \"{}\"\n", "namespace", self.namespace)?;
        write!(f, "    const val {} = \"{}\"\n", "version", self.version)?;
        write!(f, "\n")?;

        if let Some(java_version) = self.java_version {
            write!(f, "    const val {} = \"{}\"\n", "javaVersion", java_version)?;
            write!(
                f,
                "    val {} = {}\n",
                "asJavaVersionEnum ",
                "JavaVersion.values().find { it.name.endsWith(javaVersion) }"
            )?;
        }

        if let Some(ios_deployment_target) = self.ios_deployment_target {
            write!(f, "    const val {} = \"{}\"\n", "iosDeploymentTarget", ios_deployment_target)?;
        }

        if let Some(min_sdk) = self.min_sdk {
            write!(f, "    const val {} = {}\n", "minSDK", min_sdk)?;
        }

        if let Some(max_sdk) = self.max_sdk {
            write!(f, "    const val {} = {}\n", "maxSDK", max_sdk)?;
        }

        write!(f, "}}\n\n")?;
        Ok(())
    }
}