Hotreloading of for/if/body, formatted strings, literals, component props, nested rsx, light CLI rewrite, cli TUI (#2258)
Hotreload the contents of for loops, if chains, component bodies, props, attributes, and any literals discovered in rsx! Add a TUI renderer to the CLI. Improve the CLI build system to be async and parallel. Refactor RSX to allow partial expansion of expressions. Merge autofmt implementations for consistency. Merge the representation of elements and components under the hood. Add a diagnostics system for rsx for improved error messages. Drop interprocess and move to websockets for communication between the CLI and the server. Assign IDs to nodes and attributes in a stable way to be used in non compiler contexts. Add hotreloading to any body of component/for loop/if chain/etc. --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com> Co-authored-by: Liam Mitchell <liamkarlmitchell@gmail.com>
This commit is contained in:
181 files changed
+12755
-10806
No files matched your search
+43
-73
@@ -1,6 +1,5 @@
|
||||
use dioxus_cli_config::DioxusConfig;
|
||||
use std::{env, path::PathBuf};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use std::env;
|
||||
use tracing_subscriber::{prelude::*, EnvFilter, Layer};
|
||||
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
@@ -10,16 +9,11 @@ use Commands::*;
|
||||
|
||||
const LOG_ENV: &str = "DIOXUS_LOG";
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let args = Cli::parse();
|
||||
|
||||
// If {LOG_ENV} is set, default to env, otherwise filter to cli
|
||||
// and manganis warnings and errors from other crates
|
||||
let mut filter = EnvFilter::new("error,dx=info,dioxus-cli=info,manganis-cli-support=info");
|
||||
if env::var(LOG_ENV).is_ok() {
|
||||
filter = EnvFilter::from_env(LOG_ENV);
|
||||
}
|
||||
tracing_subscriber::fmt().with_env_filter(filter).init();
|
||||
build_tracing();
|
||||
|
||||
match args.action {
|
||||
Translate(opts) => opts
|
||||
@@ -32,89 +26,65 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
Init(opts) => opts
|
||||
.init()
|
||||
.context(error_wrapper("Initialising a new project failed")),
|
||||
.context(error_wrapper("Initializing a new project failed")),
|
||||
|
||||
Config(opts) => opts
|
||||
.config()
|
||||
.context(error_wrapper("Configuring new project failed")),
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
Plugin(opts) => opts.plugin().context(error_wrapper("Error with plugin")),
|
||||
|
||||
Autoformat(opts) => opts
|
||||
.autoformat()
|
||||
.context(error_wrapper("Error autoformatting RSX")),
|
||||
|
||||
Check(opts) => opts.check().context(error_wrapper("Error checking RSX")),
|
||||
Check(opts) => opts
|
||||
.check()
|
||||
.await
|
||||
.context(error_wrapper("Error checking RSX")),
|
||||
|
||||
Link(opts) => opts
|
||||
.link()
|
||||
.context(error_wrapper("Error with linker passthrough")),
|
||||
|
||||
action => {
|
||||
let bin = get_bin(args.bin)?;
|
||||
let _dioxus_config = DioxusConfig::load(Some(bin.clone()))
|
||||
.context("Failed to load Dioxus config because")?
|
||||
.unwrap_or_else(|| {
|
||||
tracing::info!("You appear to be creating a Dioxus project from scratch; we will use the default config");
|
||||
DioxusConfig::default()
|
||||
});
|
||||
Build(mut opts) => opts
|
||||
.run()
|
||||
.await
|
||||
.context(error_wrapper("Building project failed")),
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
use dioxus_cli::plugin::PluginManager;
|
||||
Clean(opts) => opts
|
||||
.clean()
|
||||
.context(error_wrapper("Cleaning project failed")),
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
PluginManager::init(_dioxus_config.plugin)
|
||||
.context(error_wrapper("Plugin system initialization failed"))?;
|
||||
Serve(opts) => opts
|
||||
.serve()
|
||||
.await
|
||||
.context(error_wrapper("Serving project failed")),
|
||||
|
||||
match action {
|
||||
Build(opts) => opts
|
||||
.build(Some(bin.clone()), None, None)
|
||||
.context(error_wrapper("Building project failed")),
|
||||
|
||||
Clean(opts) => opts
|
||||
.clean(Some(bin.clone()))
|
||||
.context(error_wrapper("Cleaning project failed")),
|
||||
|
||||
Serve(opts) => opts
|
||||
.serve(Some(bin.clone()))
|
||||
.context(error_wrapper("Serving project failed")),
|
||||
|
||||
Bundle(opts) => opts
|
||||
.bundle(Some(bin.clone()))
|
||||
.context(error_wrapper("Bundling project failed")),
|
||||
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
Bundle(opts) => opts
|
||||
.bundle()
|
||||
.await
|
||||
.context(error_wrapper("Bundling project failed")),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bin(bin: Option<String>) -> Result<PathBuf> {
|
||||
let metadata = cargo_metadata::MetadataCommand::new()
|
||||
.exec()
|
||||
.map_err(Error::CargoMetadata)?;
|
||||
let package = if let Some(bin) = bin {
|
||||
metadata
|
||||
.workspace_packages()
|
||||
.into_iter()
|
||||
.find(|p| p.name == bin)
|
||||
.ok_or(Error::CargoError(format!("no such package: {}", bin)))?
|
||||
} else {
|
||||
metadata
|
||||
.root_package()
|
||||
.ok_or(Error::CargoError("no root package?".to_string()))?
|
||||
};
|
||||
|
||||
let crate_dir = package
|
||||
.manifest_path
|
||||
.parent()
|
||||
.ok_or(Error::CargoError("couldn't take parent dir".to_string()))?;
|
||||
|
||||
Ok(crate_dir.into())
|
||||
}
|
||||
|
||||
/// Simplifies error messages that use the same pattern.
|
||||
fn error_wrapper(message: &str) -> String {
|
||||
format!("🚫 {message}:")
|
||||
}
|
||||
|
||||
fn build_tracing() {
|
||||
// If {LOG_ENV} is set, default to env, otherwise filter to cli
|
||||
// and manganis warnings and errors from other crates
|
||||
let mut filter = EnvFilter::new("error,dx=info,dioxus-cli=info,manganis-cli-support=info");
|
||||
if env::var(LOG_ENV).is_ok() {
|
||||
filter = EnvFilter::from_env(LOG_ENV);
|
||||
}
|
||||
|
||||
let sub =
|
||||
tracing_subscriber::registry().with(tracing_subscriber::fmt::layer().with_filter(filter));
|
||||
|
||||
#[cfg(feature = "tokio-console")]
|
||||
sub.with(console_subscriber::spawn()).init();
|
||||
|
||||
#[cfg(not(feature = "tokio-console"))]
|
||||
sub.init();
|
||||
}
|
||||
Reference in new issue
Block a user