Kaynağa Gözat

feat: some simple UI tweaks to CLI (#3301)

Jonathan Kelley 6 ay önce
ebeveyn
işleme
995a529b2f

+ 2 - 0
packages/cli/src/build/bundle.rs

@@ -777,6 +777,8 @@ impl AppBundle {
     /// Run any final tools to produce apks or other artifacts we might need.
     async fn assemble(&self) -> Result<()> {
         if let Platform::Android = self.build.build.platform() {
+            self.build.status_running_gradle();
+
             // make sure we can execute the gradlew script
             #[cfg(unix)]
             {

+ 6 - 0
packages/cli/src/build/progress.rs

@@ -29,6 +29,12 @@ impl BuildRequest {
         });
     }
 
+    pub(crate) fn status_running_gradle(&self) {
+        _ = self.progress.unbounded_send(BuildUpdate::Progress {
+            stage: BuildStage::RunningGradle,
+        })
+    }
+
     pub(crate) fn status_build_diagnostic(&self, message: CompilerMessage) {
         _ = self
             .progress

+ 1 - 0
packages/cli/src/cli/create.rs

@@ -211,6 +211,7 @@ pub(crate) fn post_create(path: &Path) -> Result<()> {
     file.write_all(new_readme.as_bytes())?;
 
     tracing::info!(dx_src = ?TraceSrc::Dev, "Generated project at {}", path.display());
+    tracing::info!(dx_src = ?TraceSrc::Dev, "`cd` to your project and run `dx serve` to start developing. Build cool things! ✌️");
 
     Ok(())
 }

+ 11 - 16
packages/cli/src/dioxus_crate.rs

@@ -5,9 +5,9 @@ use anyhow::Context;
 use itertools::Itertools;
 use krates::{cm::Target, KrateDetails};
 use krates::{cm::TargetKind, Cmd, Krates, NodeId};
+use std::path::Path;
 use std::path::PathBuf;
 use std::sync::Arc;
-use std::{io::Write, path::Path};
 use toml_edit::Item;
 
 // Contains information about the crate we are currently in and the dioxus config for that crate
@@ -20,9 +20,9 @@ pub(crate) struct DioxusCrate {
     pub(crate) settings: CliSettings,
 }
 
-pub(crate) static PROFILE_WASM: &str = "dioxus-wasm";
-pub(crate) static PROFILE_ANDROID: &str = "dioxus-android";
-pub(crate) static PROFILE_SERVER: &str = "dioxus-server";
+pub(crate) static PROFILE_WASM: &str = "wasm-dev";
+pub(crate) static PROFILE_ANDROID: &str = "android-dev";
+pub(crate) static PROFILE_SERVER: &str = "server-dev";
 
 impl DioxusCrate {
     pub(crate) fn new(target: &TargetArgs) -> Result<Self> {
@@ -291,18 +291,19 @@ impl DioxusCrate {
         self.config.web.pre_compress && release
     }
 
-    // The `opt-level=2` increases build times, but can noticeably decrease time
+    // The `opt-level=1` increases build times, but can noticeably decrease time
     // between saving changes and being able to interact with an app (for wasm/web). The "overall"
     // time difference (between having and not having the optimization) can be
     // almost imperceptible (~1 s) but also can be very noticeable (~6 s) — depends
     // on setup (hardware, OS, browser, idle load).
     //
-    // Find or create the client and server profiles in the .cargo/config.toml file
+    // Find or create the client and server profiles in the top-level Cargo.toml file
+    // todo(jon): we should/could make these optional by placing some defaults somewhere
     pub(crate) fn initialize_profiles(&self) -> crate::Result<()> {
-        let config_path = self.workspace_dir().join(".cargo/config.toml");
+        let config_path = self.workspace_dir().join("Cargo.toml");
         let mut config = match std::fs::read_to_string(&config_path) {
             Ok(config) => config.parse::<toml_edit::DocumentMut>().map_err(|e| {
-                crate::Error::Other(anyhow::anyhow!("Failed to parse .cargo/config.toml: {}", e))
+                crate::Error::Other(anyhow::anyhow!("Failed to parse Cargo.toml: {}", e))
             })?,
             Err(_) => Default::default(),
         };
@@ -322,7 +323,6 @@ impl DioxusCrate {
             if let toml_edit::Entry::Vacant(entry) = table.entry(PROFILE_SERVER) {
                 let mut server = toml_edit::Table::new();
                 server.insert("inherits", Item::Value("dev".into()));
-                // server.insert("opt-level", Item::Value(2.into()));
                 entry.insert(Item::Table(server));
             }
 
@@ -333,13 +333,8 @@ impl DioxusCrate {
             }
         }
 
-        // Write the config back to the file
-        if let Some(parent) = config_path.parent() {
-            std::fs::create_dir_all(parent)?;
-        }
-        let file = std::fs::File::create(config_path)?;
-        let mut buf_writer = std::io::BufWriter::new(file);
-        write!(buf_writer, "{}", config)?;
+        std::fs::write(config_path, config.to_string())
+            .context("Failed to write profiles to Cargo.toml")?;
 
         Ok(())
     }

+ 4 - 0
packages/cli/src/logging.rs

@@ -95,6 +95,10 @@ impl TraceController {
                         return Ok(());
                     }
 
+                    if field.name() == "dx_src" && !args.verbosity.verbose {
+                        return Ok(());
+                    }
+
                     write!(writer, "{}", format_field(field.name(), value))
                 })
                 .delimited(" "),

+ 1 - 0
packages/cli/src/serve/output.rs

@@ -488,6 +488,7 @@ impl Output {
             }
             BuildStage::OptimizingWasm {} => lines.push("Optimizing wasm".yellow()),
             BuildStage::RunningBindgen {} => lines.push("Running wasm-bindgen".yellow()),
+            BuildStage::RunningGradle {} => lines.push("Running gradle assemble".yellow()),
             BuildStage::Bundling {} => lines.push("Bundling app".yellow()),
             BuildStage::CopyingAssets {
                 current,

+ 1 - 1
packages/desktop/src/app.rs

@@ -66,7 +66,7 @@ impl App {
             webviews: HashMap::new(),
             control_flow: ControlFlow::Wait,
             unmounted_dom: Cell::new(Some(virtual_dom)),
-            float_all: !cfg!(debug_assertions),
+            float_all: false,
             show_devtools: false,
             cfg: Cell::new(Some(cfg)),
             shared: Rc::new(SharedContext {

+ 1 - 0
packages/dx-wire-format/src/lib.rs

@@ -63,6 +63,7 @@ pub enum BuildStage {
         path: PathBuf,
     },
     Bundling,
+    RunningGradle,
     Success,
     Failed,
     Aborted,