mrxiaozhuox преди 3 години
родител
ревизия
5fb1b3e20b
променени са 4 файла, в които са добавени 79 реда и са изтрити 2 реда
  1. 6 1
      Cargo.toml
  2. 3 1
      src/assets/dioxus.toml
  3. 1 0
      src/cli/mod.rs
  4. 69 0
      src/cli/tools.rs

+ 6 - 1
Cargo.toml

@@ -9,10 +9,12 @@ license = "MIT/Apache-2.0"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
+
 # cli core
 clap = {version = "3.0.14", features = ["derive"]}
 thiserror = "1.0.30"
 wasm-bindgen-cli-support = "0.2.79"
+
 # features
 log = "0.4.14"
 fern = { version = "0.6.0", features = ["colored"] }
@@ -37,7 +39,10 @@ hyper = "0.14.17"
 axum = { version = "0.4.5", features = ["ws", "headers"] }
 tower-http = { version = "0.2.2", features = ["fs", "trace"] }
 headers = "0.3.7"
-# hyper = { version = "0.14.11", features = ["full"] }
+
+# tools download
+dirs = "4.0.0"
+reqwest = { version = "0.11", features = ["json"] }
 
 [[bin]]
 path = "src/main.rs"

+ 3 - 1
src/assets/dioxus.toml

@@ -36,4 +36,6 @@ script = []
 
 # Javascript code file
 # serve: [dev-server] only
-script = []
+script = []
+
+[web.tools]

+ 1 - 0
src/cli/mod.rs

@@ -5,6 +5,7 @@ pub mod config;
 pub mod create;
 pub mod serve;
 pub mod translate;
+pub mod tools;
 
 use crate::{
     cfg::{ConfigOptsBuild, ConfigOptsServe},

+ 69 - 0
src/cli/tools.rs

@@ -0,0 +1,69 @@
+use std::path::PathBuf;
+
+pub enum Tool {
+    WasmOpt,
+}
+
+pub fn app_path() {
+    let data_local = dirs::data_local_dir().unwrap();
+    
+}
+
+impl Tool {
+    pub fn name(&self) -> &str {
+        match self {
+            Self::WasmOpt => "wasm-opt",
+        }
+    }
+
+    pub fn bin_path(&self) -> &str {
+        if cfg!(target_os = "windows") {
+            match self {
+                Self::WasmOpt => "bin/wasm-opt.exe",
+            }
+        } else {
+            match self {
+                Self::WasmOpt => "bin/wasm-opt",
+            }
+        }
+    }
+
+    pub fn target_platform(&self) -> &str {
+        match self {
+            Self::WasmOpt => {
+                if cfg!(target_os = "windows") {
+                    "windows"
+                } else if cfg!(target_os = "macos") {
+                    "macos"
+                } else if cfg!(target_os = "linux") {
+                    "linux"
+                } else {
+                    panic!("unsupported platformm");
+                }
+            }
+        }
+    }
+
+    pub fn download_url(&self) -> String {
+        match self {
+            Self::WasmOpt => {
+                format!(
+                    "https://github.com/WebAssembly/binaryen/releases/download/version_105/binaryen-version_105-x86_64-{target}.tar.gz",
+                    target = self.target_platform()
+                )
+            }
+        }
+    }
+
+    pub async fn download_package(&self) {
+        
+        let download_dir = dirs::download_dir().unwrap();
+        let download_url = self.download_url();
+
+        let resp = reqwest::get(download_url).await.unwrap();
+
+        resp.
+
+    }
+
+}