From 6742e91ee51a6c41ab4b7917350fa634148a6c5c Mon Sep 17 00:00:00 2001 From: imbolc Date: Mon, 21 Mar 2022 08:34:11 +0300 Subject: [PATCH 1/4] A hint to update cargo-generate --- src/cli/create/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/create/mod.rs b/src/cli/create/mod.rs index f00bc5dd9..9ab964711 100644 --- a/src/cli/create/mod.rs +++ b/src/cli/create/mod.rs @@ -59,7 +59,7 @@ impl Create { .output()?; if !generate_output.status.success() { - return custom_error!("Generate project failed."); + return custom_error!("Generate project failed. Try to update cargo-generate."); } let mut dioxus_file = File::open(project_path.join("Dioxus.toml"))?; From 3052e0ef116df6e7ac91bb943306c3453134344c Mon Sep 17 00:00:00 2001 From: imbolc Date: Mon, 21 Mar 2022 10:56:19 +0300 Subject: [PATCH 2/4] Fix buliding with redefined cargo target dir --- src/cargo.rs | 80 +++++++++++++++++++++++++++++++-------------------- src/config.rs | 5 ++-- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/cargo.rs b/src/cargo.rs index 67a3e48f1..251e9d848 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -10,6 +10,12 @@ use std::{ /// How many parent folders are searched for a `Cargo.toml` const MAX_ANCESTORS: u32 = 10; +/// Some fields parsed from `cargo metadata` command +pub struct Metadata { + pub workspace_root: PathBuf, + pub target_directory: PathBuf, +} + /// Returns the root of the crate that the command is run from /// /// If the command is run from the workspace root, this will return the top-level Cargo.toml @@ -31,37 +37,6 @@ pub fn crate_root() -> Result { .ok_or_else(|| Error::CargoError("Failed to find the cargo directory".to_string())) } -/// Returns the root of a workspace -/// TODO @Jon, find a different way that doesn't rely on the cargo metadata command (it's slow) -pub fn workspace_root() -> Result { - let output = Command::new("cargo") - .args(&["metadata"]) - .output() - .map_err(|_| Error::CargoError("Manifset".to_string()))?; - - if !output.status.success() { - let mut msg = str::from_utf8(&output.stderr).unwrap().trim(); - if msg.starts_with("error: ") { - msg = &msg[7..]; - } - - return Err(Error::CargoError(msg.to_string())); - } - - let stdout = str::from_utf8(&output.stdout).unwrap(); - if let Some(line) = stdout.lines().next() { - let meta: serde_json::Value = serde_json::from_str(line) - .map_err(|_| Error::CargoError("InvalidOutput".to_string()))?; - - let root = meta["workspace_root"] - .as_str() - .ok_or_else(|| Error::CargoError("InvalidOutput".to_string()))?; - return Ok(root.into()); - } - - Err(Error::CargoError("InvalidOutput".to_string())) -} - /// Checks if the directory contains `Cargo.toml` fn contains_manifest(path: &Path) -> bool { fs::read_dir(path) @@ -72,3 +47,46 @@ fn contains_manifest(path: &Path) -> bool { }) .unwrap_or(false) } + +impl Metadata { + /// Returns the struct filled from `cargo metadata` output + /// TODO @Jon, find a different way that doesn't rely on the cargo metadata command (it's slow) + pub fn get() -> Result { + let output = Command::new("cargo") + .args(&["metadata"]) + .output() + .map_err(|_| Error::CargoError("Manifset".to_string()))?; + + if !output.status.success() { + let mut msg = str::from_utf8(&output.stderr).unwrap().trim(); + if msg.starts_with("error: ") { + msg = &msg[7..]; + } + + return Err(Error::CargoError(msg.to_string())); + } + + let stdout = str::from_utf8(&output.stdout).unwrap(); + if let Some(line) = stdout.lines().next() { + let meta: serde_json::Value = serde_json::from_str(line) + .map_err(|_| Error::CargoError("InvalidOutput".to_string()))?; + + let workspace_root = meta["workspace_root"] + .as_str() + .ok_or_else(|| Error::CargoError("InvalidOutput".to_string()))? + .into(); + + let target_directory = meta["target_directory"] + .as_str() + .ok_or_else(|| Error::CargoError("InvalidOutput".to_string()))? + .into(); + + return Ok(Self { + workspace_root, + target_directory, + }); + } + + Err(Error::CargoError("InvalidOutput".to_string())) + } +} diff --git a/src/config.rs b/src/config.rs index ba0427191..9d2bfb870 100644 --- a/src/config.rs +++ b/src/config.rs @@ -120,8 +120,9 @@ impl CrateConfig { let dioxus_config = DioxusConfig::load()?; let crate_dir = crate::cargo::crate_root()?; - let workspace_dir = crate::cargo::workspace_root()?; - let target_dir = workspace_dir.join("target"); + let meta = crate::cargo::Metadata::get()?; + let workspace_dir = meta.workspace_root; + let target_dir = meta.target_directory; let out_dir = match dioxus_config.application.out_dir { Some(ref v) => crate_dir.join(v), From 49a451c707b0caf0bc030207965849da3eb36574 Mon Sep 17 00:00:00 2001 From: Joshua Kifer Date: Fri, 25 Mar 2022 07:54:18 -0600 Subject: [PATCH 3/4] Include missing error text in some errors --- src/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index d40868333..54dc2c981 100644 --- a/src/error.rs +++ b/src/error.rs @@ -23,10 +23,10 @@ pub enum Error { #[error("Failed to write error")] FailedToWrite, - #[error("Building project failed")] + #[error("Build Failed: {0}")] BuildFailed(String), - #[error("Failed to write error")] + #[error("Cargo Error: {0}")] CargoError(String), #[error("{0}")] From 56e6f19dd2713008e213a3ced03417ec55150c93 Mon Sep 17 00:00:00 2001 From: Joshua Kifer Date: Sun, 27 Mar 2022 10:17:06 -0600 Subject: [PATCH 4/4] Add meta viewport tag for scale (for phones) --- src/assets/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/assets/index.html b/src/assets/index.html index 9934e490d..09ad3a780 100644 --- a/src/assets/index.html +++ b/src/assets/index.html @@ -2,9 +2,10 @@ {app_title} + {style_include} - +