use-nuxt 0.0.1

Nuxt app structure metadata primitives for RustUse
Documentation
#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]

/// Nuxt version-family labels.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum NuxtVersionFamily {
    Nuxt2,
    Nuxt3,
    Nuxt4,
}

impl NuxtVersionFamily {
    /// Returns the version-family label.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Nuxt2 => "nuxt2",
            Self::Nuxt3 => "nuxt3",
            Self::Nuxt4 => "nuxt4",
        }
    }
}

/// Common Nuxt directory labels.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum NuxtDirectoryKind {
    Pages,
    Components,
    Composables,
    Layouts,
    Middleware,
    Plugins,
    Server,
    Content,
    Assets,
    Public,
}

impl NuxtDirectoryKind {
    /// Returns the directory label.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Pages => "pages",
            Self::Components => "components",
            Self::Composables => "composables",
            Self::Layouts => "layouts",
            Self::Middleware => "middleware",
            Self::Plugins => "plugins",
            Self::Server => "server",
            Self::Content => "content",
            Self::Assets => "assets",
            Self::Public => "public",
        }
    }
}

/// Nuxt rendering mode labels.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum NuxtRenderingMode {
    Ssr,
    Spa,
    Static,
    Hybrid,
}

impl NuxtRenderingMode {
    /// Returns the rendering mode label.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Ssr => "ssr",
            Self::Spa => "spa",
            Self::Static => "static",
            Self::Hybrid => "hybrid",
        }
    }
}

/// Common Nuxt config file labels.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum NuxtConfigFile {
    JavaScript,
    TypeScript,
    Mjs,
    Mts,
}

impl NuxtConfigFile {
    /// Returns the config file label.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::JavaScript => "nuxt.config.js",
            Self::TypeScript => "nuxt.config.ts",
            Self::Mjs => "nuxt.config.mjs",
            Self::Mts => "nuxt.config.mts",
        }
    }
}

#[cfg(test)]
mod tests {
    use super::{NuxtConfigFile, NuxtDirectoryKind, NuxtRenderingMode, NuxtVersionFamily};

    #[test]
    fn exposes_nuxt_labels() {
        assert_eq!(NuxtVersionFamily::Nuxt3.as_str(), "nuxt3");
        assert_eq!(NuxtDirectoryKind::Composables.as_str(), "composables");
        assert_eq!(NuxtRenderingMode::Ssr.as_str(), "ssr");
        assert_eq!(NuxtConfigFile::TypeScript.as_str(), "nuxt.config.ts");
    }
}