feat: clean command
This commit is contained in:
1 parent
9bb10c65a3
commit
7343af2089
10 files changed
+152
-34
No files matched your search
+21
-1
@@ -1,4 +1,6 @@
|
||||
use crate::cfg::ConfigOptsBuild;
|
||||
use std::{io::Write, path::PathBuf};
|
||||
|
||||
use crate::{cfg::ConfigOptsBuild, gen_page};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Build the Rust WASM app and all of its assets.
|
||||
@@ -18,6 +20,24 @@ impl Build {
|
||||
|
||||
crate::builder::build(&crate_config)?;
|
||||
|
||||
let temp = gen_page(&crate_config.dioxus_config, false);
|
||||
|
||||
let mut file = std::fs::File::create(
|
||||
crate_config
|
||||
.crate_dir
|
||||
.join(
|
||||
crate_config
|
||||
.dioxus_config
|
||||
.web
|
||||
.app
|
||||
.out_dir
|
||||
.clone()
|
||||
.unwrap_or(PathBuf::from("dist")),
|
||||
)
|
||||
.join("index.html"),
|
||||
)?;
|
||||
file.write_all(temp.as_bytes())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,41 @@
|
||||
use std::{
|
||||
fs::remove_dir_all,
|
||||
path::PathBuf,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Build the Rust WASM app and all of its assets.
|
||||
#[derive(Clone, Debug, StructOpt)]
|
||||
#[structopt(name = "clean")]
|
||||
pub struct Clean {}
|
||||
|
||||
impl Clean {
|
||||
pub fn clean(self) -> anyhow::Result<()> {
|
||||
let crate_config = crate::CrateConfig::new()?;
|
||||
|
||||
let output = Command::new("cargo")
|
||||
.arg("clean")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()?;
|
||||
|
||||
if !output.status.success() {
|
||||
log::error!("Cargo clean failed.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let out_dir = crate_config
|
||||
.dioxus_config
|
||||
.web
|
||||
.app
|
||||
.out_dir
|
||||
.unwrap_or(PathBuf::from("dist"));
|
||||
if crate_config.crate_dir.join(&out_dir).is_dir() {
|
||||
remove_dir_all(crate_config.crate_dir.join(&out_dir))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -37,8 +37,7 @@ pub enum Commands {
|
||||
/// Init a new project for Dioxus.
|
||||
Init(init::Init),
|
||||
// /// Clean output artifacts.
|
||||
// Clean(clean::Clean),
|
||||
|
||||
Clean(clean::Clean),
|
||||
// /// Trunk config controls.
|
||||
// Config(config::Config),
|
||||
}
|
||||
+11
-6
@@ -1,4 +1,4 @@
|
||||
use crate::{cfg::ConfigOptsServe, gen_page, server};
|
||||
use crate::{cfg::ConfigOptsServe, gen_page, server, CrateConfig};
|
||||
use std::{io::Write, path::PathBuf};
|
||||
use structopt::StructOpt;
|
||||
|
||||
@@ -18,6 +18,16 @@ impl Serve {
|
||||
|
||||
crate::builder::build(&crate_config).expect("build failed");
|
||||
|
||||
// generate dev-index page
|
||||
Serve::regen_dev_page(&crate_config)?;
|
||||
|
||||
// start the develop server
|
||||
server::startup(crate_config.clone()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn regen_dev_page(crate_config: &CrateConfig) -> anyhow::Result<()> {
|
||||
let serve_html = gen_page(&crate_config.dioxus_config, true);
|
||||
|
||||
let mut file = std::fs::File::create(
|
||||
@@ -36,11 +46,6 @@ impl Serve {
|
||||
)?;
|
||||
file.write_all(serve_html.as_bytes())?;
|
||||
|
||||
// start the develop server
|
||||
server::startup(crate_config.clone()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn regen_page() {}
|
||||
}
|
||||
Reference in new issue
Block a user