diff --git a/Dioxus.toml b/Dioxus.toml index ab85abe86..2db611914 100644 --- a/Dioxus.toml +++ b/Dioxus.toml @@ -1,12 +1,12 @@ [application] # dioxus project name -name = "{{project-name}}" +name = "dioxus-cli" # default platfrom # you can also use `dioxus serve/build --platform XXX` to use other platform # value: web | desktop -default_platform = "{{default-platform}}" +default_platform = "desktop" # Web `build` & `serve` dist path out_dir = "dist" diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 6e653507d..2c91c94dd 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -5,7 +5,6 @@ pub mod config; pub mod create; pub mod serve; pub mod translate; -pub mod tools; pub mod tool; use crate::{ diff --git a/src/cli/tool/mod.rs b/src/cli/tool/mod.rs index 1b8768497..51e41e384 100644 --- a/src/cli/tool/mod.rs +++ b/src/cli/tool/mod.rs @@ -1,3 +1,5 @@ +use crate::tools; + use super::*; /// Build the Rust WASM app and all of its assets. diff --git a/src/lib.rs b/src/lib.rs index 395cbc8dc..8cd4b1f2d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ pub mod builder; pub mod server; +pub mod tools; + pub use builder::*; pub mod cargo; diff --git a/src/cli/tools.rs b/src/tools.rs similarity index 92% rename from src/cli/tools.rs rename to src/tools.rs index 257c7f856..b5c9d658a 100644 --- a/src/cli/tools.rs +++ b/src/tools.rs @@ -47,6 +47,8 @@ pub fn tools_path() -> PathBuf { #[allow(clippy::should_implement_trait)] impl Tool { + + /// from str to tool enum pub fn from_str(name: &str) -> Option { match name { "binaryen" => Some(Self::Binaryen), @@ -54,18 +56,21 @@ impl Tool { } } + /// get current tool name str pub fn name(&self) -> &str { match self { Self::Binaryen => "binaryen", } } + /// get tool bin dir path pub fn bin_path(&self) -> &str { match self { Self::Binaryen => "bin", } } + /// get target platform pub fn target_platform(&self) -> &str { match self { Self::Binaryen => { @@ -82,6 +87,7 @@ impl Tool { } } + /// get tool package download url pub fn download_url(&self) -> String { match self { Self::Binaryen => { @@ -93,20 +99,24 @@ impl Tool { } } + /// get package extension name pub fn extension(&self) -> &str { match self { Self::Binaryen => "tar.gz", } } + /// check tool state pub fn is_installed(&self) -> bool { tools_path().join(self.name()).is_dir() } + /// get download temp path pub fn temp_out_path(&self) -> PathBuf { temp_path().join(format!("{}-tool.tmp", self.name())) } + /// start to download package pub async fn download_package(&self) -> anyhow::Result { let download_url = self.download_url(); let temp_out = self.temp_out_path(); @@ -125,6 +135,7 @@ impl Tool { Ok(temp_out) } + /// start to install package pub async fn install_package(&self) -> anyhow::Result<()> { let temp_path = self.temp_out_path(); let tool_path = tools_path();