Skip to main content

lovely/targets/
mod.rs

1pub mod desktop;
2pub mod web;
3
4use crate::Result;
5use crate::check::DiagnosticReport;
6use crate::config::Config;
7use crate::lockfile::LockFile;
8use std::path::Path;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct BuildOutput {
12    pub target: String,
13    pub artifacts: Vec<std::path::PathBuf>,
14}
15
16pub trait TargetAdapter {
17    fn name(&self) -> &'static str;
18    fn doctor(&self, root: &Path, config: &Config, lock: &LockFile) -> Result<DiagnosticReport>;
19    fn build(&self, root: &Path, config: &Config, lock: &LockFile) -> Result<BuildOutput>;
20}
21
22pub fn adapter_for(target: &str) -> Option<Box<dyn TargetAdapter>> {
23    match target {
24        "web" => Some(Box::new(web::WebAdapter)),
25        "windows" => Some(Box::new(desktop::DesktopAdapter::new(
26            desktop::DesktopPlatform::Windows,
27        ))),
28        "macos" => Some(Box::new(desktop::DesktopAdapter::new(
29            desktop::DesktopPlatform::Macos,
30        ))),
31        "linux" => Some(Box::new(desktop::DesktopAdapter::new(
32            desktop::DesktopPlatform::Linux,
33        ))),
34        _ => None,
35    }
36}
37
38pub fn expand_targets(target: &str) -> Vec<&'static str> {
39    match target {
40        "all" => vec!["web", "windows", "macos", "linux"],
41        "desktop" => vec!["windows", "macos", "linux"],
42        "web" => vec!["web"],
43        "windows" => vec!["windows"],
44        "macos" => vec!["macos"],
45        "linux" => vec!["linux"],
46        _ => Vec::new(),
47    }
48}