Merge branch 'master' into master
This commit is contained in:
5 files changed
+56
-36
No files matched your search
@@ -2,6 +2,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>{app_title}</title>
|
<title>{app_title}</title>
|
||||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
{style_include}
|
{style_include}
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
+49
-31
@@ -10,6 +10,12 @@ use std::{
|
|||||||
/// How many parent folders are searched for a `Cargo.toml`
|
/// How many parent folders are searched for a `Cargo.toml`
|
||||||
const MAX_ANCESTORS: u32 = 10;
|
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
|
/// 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
|
/// 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<PathBuf> {
|
|||||||
.ok_or_else(|| Error::CargoError("Failed to find the cargo directory".to_string()))
|
.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<PathBuf> {
|
|
||||||
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`
|
/// Checks if the directory contains `Cargo.toml`
|
||||||
fn contains_manifest(path: &Path) -> bool {
|
fn contains_manifest(path: &Path) -> bool {
|
||||||
fs::read_dir(path)
|
fs::read_dir(path)
|
||||||
@@ -72,3 +47,46 @@ fn contains_manifest(path: &Path) -> bool {
|
|||||||
})
|
})
|
||||||
.unwrap_or(false)
|
.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<Self> {
|
||||||
|
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()))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ impl Create {
|
|||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !generate_output.status.success() {
|
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"))?;
|
let mut dioxus_file = File::open(project_path.join("Dioxus.toml"))?;
|
||||||
|
|||||||
+3
-2
@@ -122,8 +122,9 @@ impl CrateConfig {
|
|||||||
let dioxus_config = DioxusConfig::load()?;
|
let dioxus_config = DioxusConfig::load()?;
|
||||||
|
|
||||||
let crate_dir = crate::cargo::crate_root()?;
|
let crate_dir = crate::cargo::crate_root()?;
|
||||||
let workspace_dir = crate::cargo::workspace_root()?;
|
let meta = crate::cargo::Metadata::get()?;
|
||||||
let target_dir = workspace_dir.join("target");
|
let workspace_dir = meta.workspace_root;
|
||||||
|
let target_dir = meta.target_directory;
|
||||||
|
|
||||||
let out_dir = match dioxus_config.application.out_dir {
|
let out_dir = match dioxus_config.application.out_dir {
|
||||||
Some(ref v) => crate_dir.join(v),
|
Some(ref v) => crate_dir.join(v),
|
||||||
|
|||||||
+2
-2
@@ -23,10 +23,10 @@ pub enum Error {
|
|||||||
#[error("Failed to write error")]
|
#[error("Failed to write error")]
|
||||||
FailedToWrite,
|
FailedToWrite,
|
||||||
|
|
||||||
#[error("Building project failed")]
|
#[error("Build Failed: {0}")]
|
||||||
BuildFailed(String),
|
BuildFailed(String),
|
||||||
|
|
||||||
#[error("Failed to write error")]
|
#[error("Cargo Error: {0}")]
|
||||||
CargoError(String),
|
CargoError(String),
|
||||||
|
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
|
|||||||
Reference in new issue
Block a user