Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I30469f47be8df27ee2a31f1acdcd68a16a6a6964
88 lines
2.1 KiB
Rust
88 lines
2.1 KiB
Rust
use super::rules::Rule;
|
|
use crate::error::{PakkerError, Result};
|
|
|
|
pub trait ExportProfile {
|
|
fn name(&self) -> &str;
|
|
fn rules(&self) -> Vec<Box<dyn Rule>>;
|
|
}
|
|
|
|
/// Implements [`ExportProfile`] for a unit struct with a static name and rule
|
|
/// list.
|
|
///
|
|
/// Each rule entry is an expression evaluated as
|
|
/// `Box::new(super::rules::<expr>)`, supporting both bare unit struct names and
|
|
/// constructor calls with arguments.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```ignore
|
|
/// export_profile! {
|
|
/// MyProfile => "my-profile" {
|
|
/// SomeRule,
|
|
/// AnotherRule::new("arg"),
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
macro_rules! export_profile {
|
|
($struct:ident => $name:literal { $($rule:expr),* $(,)? }) => {
|
|
pub struct $struct;
|
|
|
|
impl ExportProfile for $struct {
|
|
fn name(&self) -> &'static str {
|
|
$name
|
|
}
|
|
|
|
fn rules(&self) -> Vec<Box<dyn Rule>> {
|
|
use super::rules::*;
|
|
vec![
|
|
$(Box::new($rule)),*
|
|
]
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
export_profile! {
|
|
CurseForgeProfile => "curseforge" {
|
|
CopyProjectFilesRule,
|
|
FilterByPlatformRule,
|
|
MissingProjectsAsOverridesRule::new("curseforge"),
|
|
CopyOverridesRule,
|
|
CopyClientOverridesRule,
|
|
FilterServerOnlyRule,
|
|
GenerateManifestRule::curseforge(),
|
|
FilterNonRedistributableRule,
|
|
TextReplacementRule
|
|
}
|
|
}
|
|
|
|
export_profile! {
|
|
ModrinthProfile => "modrinth" {
|
|
CopyProjectFilesRule,
|
|
FilterByPlatformRule,
|
|
MissingProjectsAsOverridesRule::new("modrinth"),
|
|
CopyOverridesRule,
|
|
CopyClientOverridesRule,
|
|
FilterServerOnlyRule,
|
|
GenerateManifestRule::modrinth(),
|
|
TextReplacementRule
|
|
}
|
|
}
|
|
|
|
export_profile! {
|
|
ServerPackProfile => "serverpack" {
|
|
CopyProjectFilesRule,
|
|
CopyServerOverridesRule,
|
|
FilterClientOnlyRule,
|
|
TextReplacementRule
|
|
}
|
|
}
|
|
|
|
pub fn create_profile(name: &str) -> Result<Box<dyn ExportProfile>> {
|
|
match name {
|
|
"curseforge" => Ok(Box::new(CurseForgeProfile)),
|
|
"modrinth" => Ok(Box::new(ModrinthProfile)),
|
|
"serverpack" => Ok(Box::new(ServerPackProfile)),
|
|
_ => Err(PakkerError::InvalidExportProfile(name.to_string())),
|
|
}
|
|
}
|