Merge pull request #139 from Sol-Ell/make-clone-repo-err-clear

Make git clone repo err clear
This commit is contained in:
YuKun Liu authored and GitHub committed 2023-05-23 13:48:34 -07:00
commit 2bbf69e6b6
10 files changed
+46 -44

No files matched your search

+8 -14
View File
@@ -49,7 +49,8 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
// [1] Build the .wasm module // [1] Build the .wasm module
log::info!("🚅 Running build command..."); log::info!("🚅 Running build command...");
let cmd = subprocess::Exec::cmd("cargo"); let cmd = subprocess::Exec::cmd("cargo");
let cmd = cmd.cwd(&crate_dir) let cmd = cmd
.cwd(&crate_dir)
.arg("build") .arg("build")
.arg("--target") .arg("--target")
.arg("wasm32-unknown-unknown") .arg("wasm32-unknown-unknown")
@@ -66,25 +67,18 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
cmd cmd
}; };
let cmd = if quiet { let cmd = if quiet { cmd.arg("--quiet") } else { cmd };
cmd.arg("--quiet")
} else {
cmd
};
let cmd = if config.custom_profile.is_some() { let cmd = if config.custom_profile.is_some() {
let custom_profile = config.custom_profile.as_ref().unwrap(); let custom_profile = config.custom_profile.as_ref().unwrap();
cmd cmd.arg("--profile").arg(custom_profile)
.arg("--profile")
.arg(custom_profile)
} else { } else {
cmd cmd
}; };
let cmd = if config.features.is_some() { let cmd = if config.features.is_some() {
let features_str = config.features.as_ref().unwrap().join(" "); let features_str = config.features.as_ref().unwrap().join(" ");
cmd.arg("--features") cmd.arg("--features").arg(features_str)
.arg(features_str)
} else { } else {
cmd cmd
}; };
@@ -394,9 +388,9 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
let message = msg.message; let message = msg.message;
match message.level { match message.level {
cargo_metadata::diagnostic::DiagnosticLevel::Error => { cargo_metadata::diagnostic::DiagnosticLevel::Error => {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(message
message.rendered.unwrap_or("Unknown".into()) .rendered
)); .unwrap_or("Unknown".into())));
} }
cargo_metadata::diagnostic::DiagnosticLevel::Warning => { cargo_metadata::diagnostic::DiagnosticLevel::Warning => {
warning_messages.push(message.clone()); warning_messages.push(message.clone());
+3 -1
View File
@@ -34,7 +34,9 @@ pub fn crate_root() -> Result<PathBuf> {
} }
None None
}) })
.ok_or_else(|| Error::CargoError("Failed to find directory containing Cargo.toml".to_string())) .ok_or_else(|| {
Error::CargoError("Failed to find directory containing Cargo.toml".to_string())
})
} }
/// Checks if the directory contains `Cargo.toml` /// Checks if the directory contains `Cargo.toml`
+1 -1
View File
@@ -78,7 +78,7 @@ pub struct ConfigOptsServe {
pub hot_reload: bool, pub hot_reload: bool,
/// Set cross-origin-policy to same-origin [default: false] /// Set cross-origin-policy to same-origin [default: false]
#[clap(name="cross-origin-policy")] #[clap(name = "cross-origin-policy")]
#[clap(long)] #[clap(long)]
#[serde(default)] #[serde(default)]
pub cross_origin_policy: bool, pub cross_origin_policy: bool,
+2 -1
View File
@@ -21,7 +21,8 @@ impl Plugin {
} }
} }
Plugin::AppPath {} => { Plugin::AppPath {} => {
if let Some(v) = crate::plugin::PluginManager::init_plugin_dir().to_str() { let plugin_dir = crate::plugin::PluginManager::init_plugin_dir();
if let Some(v) = plugin_dir.to_str() {
println!("{}", v); println!("{}", v);
} else { } else {
log::error!("Plugin path get failed."); log::error!("Plugin path get failed.");
+1 -1
View File
@@ -31,7 +31,7 @@ impl Serve {
if self.serve.profile.is_some() { if self.serve.profile.is_some() {
crate_config.set_profile(self.serve.profile.unwrap()); crate_config.set_profile(self.serve.profile.unwrap());
} }
if self.serve.features.is_some() { if self.serve.features.is_some() {
crate_config.set_features(self.serve.features.unwrap()); crate_config.set_features(self.serve.features.unwrap());
} }
+1 -3
View File
@@ -1,8 +1,6 @@
use std::process::exit; use std::process::exit;
use dioxus_rsx::{BodyNode, CallBody, Component}; use dioxus_rsx::{BodyNode, CallBody};
use proc_macro2::{Ident, Span};
use syn::punctuated::Punctuated;
use super::*; use super::*;
+1 -1
View File
@@ -236,7 +236,7 @@ impl CrateConfig {
self self
} }
pub fn with_cross_origin_policy(&mut self, cross_origin_policy: bool) -> &mut Self { pub fn with_cross_origin_policy(&mut self, cross_origin_policy: bool) -> &mut Self {
self.cross_origin_policy = cross_origin_policy; self.cross_origin_policy = cross_origin_policy;
self self
} }
+3 -1
View File
@@ -294,7 +294,9 @@ impl PluginManager {
if !plugin_path.is_dir() { if !plugin_path.is_dir() {
log::info!("📖 Start to init plugin library ..."); log::info!("📖 Start to init plugin library ...");
let url = "https://github.com/DioxusLabs/cli-plugin-library"; let url = "https://github.com/DioxusLabs/cli-plugin-library";
clone_repo(&plugin_path, url).unwrap(); if let Err(err) = clone_repo(&plugin_path, url) {
log::error!("Failed to init plugin dir, error caused by {}. ", err);
}
} }
plugin_path plugin_path
} }
+18 -19
View File
@@ -136,7 +136,12 @@ pub async fn hot_reload_handler(
} }
#[allow(unused_assignments)] #[allow(unused_assignments)]
pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig, start_browser: bool) -> Result<()> { pub async fn startup_hot_reload(
ip: String,
port: u16,
config: CrateConfig,
start_browser: bool,
) -> Result<()> {
let first_build_result = crate::builder::build(&config, false)?; let first_build_result = crate::builder::build(&config, false)?;
log::info!("🚀 Starting development server..."); log::info!("🚀 Starting development server...");
@@ -272,11 +277,11 @@ pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig, star
); );
let cors = CorsLayer::new() let cors = CorsLayer::new()
// allow `GET` and `POST` when accessing the resource // allow `GET` and `POST` when accessing the resource
.allow_methods([Method::GET, Method::POST]) .allow_methods([Method::GET, Method::POST])
// allow requests from any origin // allow requests from any origin
.allow_origin(Any) .allow_origin(Any)
.allow_headers(Any); .allow_headers(Any);
let (coep, coop) = if config.cross_origin_policy { let (coep, coop) = if config.cross_origin_policy {
( (
@@ -296,10 +301,7 @@ pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig, star
HeaderName::from_static("cross-origin-embedder-policy"), HeaderName::from_static("cross-origin-embedder-policy"),
coep, coep,
) )
.override_response_header( .override_response_header(HeaderName::from_static("cross-origin-opener-policy"), coop)
HeaderName::from_static("cross-origin-opener-policy"),
coop,
)
.and_then( .and_then(
move |response: Response<ServeFileSystemResponseBody>| async move { move |response: Response<ServeFileSystemResponseBody>| async move {
let response = if file_service_config let response = if file_service_config
@@ -456,11 +458,11 @@ pub async fn startup_default(
PluginManager::on_serve_start(&config)?; PluginManager::on_serve_start(&config)?;
let cors = CorsLayer::new() let cors = CorsLayer::new()
// allow `GET` and `POST` when accessing the resource // allow `GET` and `POST` when accessing the resource
.allow_methods([Method::GET, Method::POST]) .allow_methods([Method::GET, Method::POST])
// allow requests from any origin // allow requests from any origin
.allow_origin(Any) .allow_origin(Any)
.allow_headers(Any); .allow_headers(Any);
let (coep, coop) = if config.cross_origin_policy { let (coep, coop) = if config.cross_origin_policy {
( (
@@ -480,10 +482,7 @@ pub async fn startup_default(
HeaderName::from_static("cross-origin-embedder-policy"), HeaderName::from_static("cross-origin-embedder-policy"),
coep, coep,
) )
.override_response_header( .override_response_header(HeaderName::from_static("cross-origin-opener-policy"), coop)
HeaderName::from_static("cross-origin-opener-policy"),
coop,
)
.and_then( .and_then(
move |response: Response<ServeFileSystemResponseBody>| async move { move |response: Response<ServeFileSystemResponseBody>| async move {
let response = if file_service_config let response = if file_service_config
+8 -2
View File
@@ -1,6 +1,6 @@
use std::{ use std::{
fs::{create_dir_all, File}, fs::{create_dir_all, File},
io::{Read, Write}, io::{ErrorKind, Read, Write},
path::{Path, PathBuf}, path::{Path, PathBuf},
process::Command, process::Command,
}; };
@@ -46,7 +46,13 @@ pub fn clone_repo(dir: &Path, url: &str) -> anyhow::Result<()> {
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
let cmd = cmd.current_dir(target_dir); let cmd = cmd.current_dir(target_dir);
let _res = cmd.arg("clone").arg(url).arg(dir_name).output()?; let res = cmd.arg("clone").arg(url).arg(dir_name).output();
if let Err(err) = res {
if ErrorKind::NotFound == err.kind() {
log::warn!("Git program not found. Hint: Install git or check $PATH.");
return Err(err.into());
}
}
Ok(()) Ok(())
} }