feat: commit code
This commit is contained in:
1 parent
25ff6c5937
commit
eea01f7f8c
5 files changed
+93
-4
No files matched your search
@@ -43,6 +43,8 @@ headers = "0.3.7"
|
|||||||
# tools download
|
# tools download
|
||||||
dirs = "4.0.0"
|
dirs = "4.0.0"
|
||||||
reqwest = { version = "0.11", features = ["rustls-tls", "stream", "trust-dns"] }
|
reqwest = { version = "0.11", features = ["rustls-tls", "stream", "trust-dns"] }
|
||||||
|
flate2 = "1.0.22"
|
||||||
|
tar = "0.4.38"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ pub mod create;
|
|||||||
pub mod serve;
|
pub mod serve;
|
||||||
pub mod translate;
|
pub mod translate;
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
pub mod tool;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cfg::{ConfigOptsBuild, ConfigOptsServe},
|
cfg::{ConfigOptsBuild, ConfigOptsServe},
|
||||||
@@ -56,4 +57,7 @@ pub enum Commands {
|
|||||||
/// Dioxus config file controls.
|
/// Dioxus config file controls.
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
Config(config::Config),
|
Config(config::Config),
|
||||||
|
/// Install & Manage tools for Dioxus-cli.
|
||||||
|
#[clap(subcommand)]
|
||||||
|
Tool(tool::Tool),
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// Build the Rust WASM app and all of its assets.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Subcommand)]
|
||||||
|
#[clap(name = "tool")]
|
||||||
|
pub enum Tool {
|
||||||
|
/// Return all dioxus-cli support tools.
|
||||||
|
List {},
|
||||||
|
Add {
|
||||||
|
name: String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tool {
|
||||||
|
pub async fn tool(self) -> Result<()> {
|
||||||
|
match self {
|
||||||
|
Tool::List {} => {
|
||||||
|
for item in tools::tool_list() {
|
||||||
|
if tools::Tool::from_str(item).unwrap().is_installed() {
|
||||||
|
println!("{item} [installed]");
|
||||||
|
} else {
|
||||||
|
println!("{item}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Tool::Add { name } => {
|
||||||
|
let tool_list = tools::tool_list();
|
||||||
|
|
||||||
|
if !tool_list.contains(&name.as_str()) {
|
||||||
|
log::error!("Tool {name} not found.");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let target_tool = tools::Tool::from_str(&name).unwrap();
|
||||||
|
println!("{:?}", target_tool.download_package().await);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
+41
-4
@@ -8,6 +8,10 @@ pub enum Tool {
|
|||||||
WasmOpt,
|
WasmOpt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tool_list() -> Vec<&'static str> {
|
||||||
|
vec!["wasm-opt"]
|
||||||
|
}
|
||||||
|
|
||||||
pub fn app_path() -> PathBuf {
|
pub fn app_path() -> PathBuf {
|
||||||
let data_local = dirs::data_local_dir().unwrap();
|
let data_local = dirs::data_local_dir().unwrap();
|
||||||
let dioxus_dir = data_local.join("dioxus");
|
let dioxus_dir = data_local.join("dioxus");
|
||||||
@@ -26,7 +30,24 @@ pub fn temp_path() -> PathBuf {
|
|||||||
temp_path
|
temp_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tools_path(tool: &Tool) -> PathBuf {
|
||||||
|
let app_path = app_path();
|
||||||
|
let temp_path = app_path.join("tools");
|
||||||
|
if !temp_path.is_dir() {
|
||||||
|
create_dir_all(&temp_path).unwrap();
|
||||||
|
}
|
||||||
|
temp_path.join(tool.name())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::should_implement_trait)]
|
||||||
impl Tool {
|
impl Tool {
|
||||||
|
pub fn from_str(name: &str) -> Option<Self> {
|
||||||
|
match name {
|
||||||
|
"wasm-opt" => Some(Self::WasmOpt),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
Self::WasmOpt => "wasm-opt",
|
Self::WasmOpt => "wasm-opt",
|
||||||
@@ -72,11 +93,23 @@ impl Tool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn download_package(&self) -> anyhow::Result<PathBuf> {
|
pub fn extension(&self) -> &str {
|
||||||
let temp_dir = temp_path();
|
match self {
|
||||||
let download_url = self.download_url();
|
Self::WasmOpt => "tar.gz",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let temp_out = temp_dir.join(format!("{}-tool.tmp", self.name()));
|
pub fn is_installed(&self) -> bool {
|
||||||
|
tools_path(self).is_dir()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn temp_out_path(&self) -> PathBuf {
|
||||||
|
temp_path().join(format!("{}-tool.tmp", self.name()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn download_package(&self) -> anyhow::Result<PathBuf> {
|
||||||
|
let download_url = self.download_url();
|
||||||
|
let temp_out = self.temp_out_path();
|
||||||
let mut file = tokio::fs::File::create(&temp_out)
|
let mut file = tokio::fs::File::create(&temp_out)
|
||||||
.await
|
.await
|
||||||
.context("failed creating temporary output file")?;
|
.context("failed creating temporary output file")?;
|
||||||
@@ -91,4 +124,8 @@ impl Tool {
|
|||||||
|
|
||||||
Ok(temp_out)
|
Ok(temp_out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn install_package() -> anyhow::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,12 @@ async fn main() -> Result<()> {
|
|||||||
log::error!("config error: {}", e);
|
log::error!("config error: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Commands::Tool(opts) => {
|
||||||
|
if let Err(e) = opts.tool().await {
|
||||||
|
log::error!("tool error: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in new issue
Block a user