vertigo-cli 0.11.4

Reactive Real-DOM library with SSR for Rust - packaging/serving tool
Documentation
use std::{fs, path::PathBuf};

use crate::{
    build::find_target::profile_name,
    commons::{ErrorCode, command::CommandRun},
};

use super::Workspace;

const TARGET: &str = "wasm32-unknown-unknown";

pub fn run_cargo_build(
    package_name: &str,
    vertigo_public_path: &str,
    ws: &Workspace,
    allow_error: bool,
    release: bool,
    cargo_opts: &[String],
) -> Result<Result<PathBuf, String>, ErrorCode> {
    log::info!("Building {package_name}");

    let profile = profile_name(release);

    let target_dir = ws.get_target_dir().join(TARGET).join(profile);

    let _ = fs::remove_dir_all(target_dir.join("tailwind"));

    let mut command = CommandRun::new("cargo").add_param("build");

    if release {
        command = command.add_param("--release");
        command = command.add_param("--locked");
    }

    command = command
        .add_param("--target")
        .add_param(TARGET)
        .add_param("--package")
        .add_param(package_name)
        .env("VERTIGO_PUBLIC_PATH", vertigo_public_path)
        // Tell macros that we're bundling so it will produce artifacts
        .env("VERTIGO_BUNDLE", "true");

    for opt in cargo_opts {
        command = command.add_param(opt);
    }

    if allow_error {
        command = command.allow_error();
    } else {
        command = command.set_error_code(ErrorCode::BuildFailed);
    }

    let (status, output) = command.output_with_status()?;

    if status.success() {
        Ok(Ok(ws.get_target_dir().join(TARGET).join(profile)))
    } else {
        Ok(Err(output))
    }
}