trunk 0.7.1

Build, bundle & ship your Rust WASM application to the web.
use std::path::PathBuf;

use anyhow::{ensure, Result};
use async_process::{Command, Stdio};
use async_std::fs;
use structopt::StructOpt;

use crate::config::{ConfigOpts, ConfigOptsClean};

/// Clean output artifacts.
#[derive(StructOpt)]
#[structopt(name = "clean")]
pub struct Clean {
    #[structopt(flatten)]
    pub clean: ConfigOptsClean,
}

impl Clean {
    pub async fn run(self, config: Option<PathBuf>) -> Result<()> {
        let cfg = ConfigOpts::rtc_clean(self.clean, config).await?;
        let _ = fs::remove_dir_all(&cfg.dist).await;
        if cfg.cargo {
            let output = Command::new("cargo")
                .arg("clean")
                .stdout(Stdio::piped())
                .stderr(Stdio::piped())
                .output()
                .await?;
            ensure!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr));
        }
        Ok(())
    }
}