export: introduce `export_profile to reduce boilerplate; cleanup
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I30469f47be8df27ee2a31f1acdcd68a16a6a6964
This commit is contained in:
parent
fc2d89892c
commit
255220b43c
1 changed files with 60 additions and 50 deletions
|
|
@ -6,65 +6,75 @@ pub trait ExportProfile {
|
|||
fn rules(&self) -> Vec<Box<dyn Rule>>;
|
||||
}
|
||||
|
||||
pub struct CurseForgeProfile;
|
||||
pub struct ModrinthProfile;
|
||||
pub struct ServerPackProfile;
|
||||
/// 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 CurseForgeProfile {
|
||||
fn name(&self) -> &'static str {
|
||||
"curseforge"
|
||||
}
|
||||
impl ExportProfile for $struct {
|
||||
fn name(&self) -> &'static str {
|
||||
$name
|
||||
}
|
||||
|
||||
fn rules(&self) -> Vec<Box<dyn Rule>> {
|
||||
vec![
|
||||
Box::new(super::rules::CopyProjectFilesRule),
|
||||
Box::new(super::rules::FilterByPlatformRule),
|
||||
Box::new(super::rules::MissingProjectsAsOverridesRule::new(
|
||||
"curseforge",
|
||||
)),
|
||||
Box::new(super::rules::CopyOverridesRule),
|
||||
Box::new(super::rules::CopyClientOverridesRule),
|
||||
Box::new(super::rules::FilterServerOnlyRule),
|
||||
Box::new(super::rules::GenerateManifestRule::curseforge()),
|
||||
Box::new(super::rules::FilterNonRedistributableRule),
|
||||
Box::new(super::rules::TextReplacementRule),
|
||||
]
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
impl ExportProfile for ModrinthProfile {
|
||||
fn name(&self) -> &'static str {
|
||||
"modrinth"
|
||||
}
|
||||
|
||||
fn rules(&self) -> Vec<Box<dyn Rule>> {
|
||||
vec![
|
||||
Box::new(super::rules::CopyProjectFilesRule),
|
||||
Box::new(super::rules::FilterByPlatformRule),
|
||||
Box::new(super::rules::MissingProjectsAsOverridesRule::new(
|
||||
"modrinth",
|
||||
)),
|
||||
Box::new(super::rules::CopyOverridesRule),
|
||||
Box::new(super::rules::CopyClientOverridesRule),
|
||||
Box::new(super::rules::FilterServerOnlyRule),
|
||||
Box::new(super::rules::GenerateManifestRule::modrinth()),
|
||||
Box::new(super::rules::TextReplacementRule),
|
||||
]
|
||||
export_profile! {
|
||||
ModrinthProfile => "modrinth" {
|
||||
CopyProjectFilesRule,
|
||||
FilterByPlatformRule,
|
||||
MissingProjectsAsOverridesRule::new("modrinth"),
|
||||
CopyOverridesRule,
|
||||
CopyClientOverridesRule,
|
||||
FilterServerOnlyRule,
|
||||
GenerateManifestRule::modrinth(),
|
||||
TextReplacementRule
|
||||
}
|
||||
}
|
||||
|
||||
impl ExportProfile for ServerPackProfile {
|
||||
fn name(&self) -> &'static str {
|
||||
"serverpack"
|
||||
}
|
||||
|
||||
fn rules(&self) -> Vec<Box<dyn Rule>> {
|
||||
vec![
|
||||
Box::new(super::rules::CopyProjectFilesRule),
|
||||
Box::new(super::rules::CopyServerOverridesRule),
|
||||
Box::new(super::rules::FilterClientOnlyRule),
|
||||
Box::new(super::rules::TextReplacementRule),
|
||||
]
|
||||
export_profile! {
|
||||
ServerPackProfile => "serverpack" {
|
||||
CopyProjectFilesRule,
|
||||
CopyServerOverridesRule,
|
||||
FilterClientOnlyRule,
|
||||
TextReplacementRule
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue