Feat: add dx as a package and move plugin to feature

This commit is contained in:
Jonathan Kelley committed 2023-07-07 18:17:42 -07:00
1 parent 7eeb72b929
commit 3f74b10e7c
8 files changed
+52 -22

No files matched your search

+3
View File
@@ -1,3 +1,4 @@
#[cfg(feature = "plugin")]
use crate::plugin::PluginManager;
use super::*;
@@ -38,6 +39,7 @@ impl Build {
.clone()
});
#[cfg(feature = "plugin")]
let _ = PluginManager::on_build_start(&crate_config, &platform);
match platform.as_str() {
@@ -69,6 +71,7 @@ impl Build {
)?;
file.write_all(temp.as_bytes())?;
#[cfg(feature = "plugin")]
let _ = PluginManager::on_build_finish(&crate_config, &platform);
Ok(())
+4 -1
View File
@@ -68,6 +68,7 @@ pub enum Commands {
Config(config::Config),
/// Manage plugins for dioxus cli
#[cfg(feature = "plugin")]
#[clap(subcommand)]
Plugin(plugin::Plugin),
}
@@ -81,9 +82,11 @@ impl Display for Commands {
Commands::Create(_) => write!(f, "create"),
Commands::Clean(_) => write!(f, "clean"),
Commands::Config(_) => write!(f, "config"),
Commands::Plugin(_) => write!(f, "plugin"),
Commands::Version(_) => write!(f, "version"),
Commands::Autoformat(_) => write!(f, "fmt"),
#[cfg(feature = "plugin")]
Commands::Plugin(_) => write!(f, "plugin"),
}
}
}
+2
View File
@@ -1,3 +1,5 @@
#![cfg(feature = "plugin")]
use super::*;
/// Build the Rust WASM app and all of its assets.
+1
View File
@@ -21,4 +21,5 @@ pub use error::*;
pub mod logging;
pub use logging::*;
#[cfg(feature = "plugin")]
pub mod plugin;
+9 -3
View File
@@ -1,6 +1,10 @@
use anyhow::anyhow;
use clap::Parser;
use dioxus_cli::{plugin::PluginManager, *};
use dioxus_cli::*;
#[cfg(feature = "plugin")]
use dioxus_cli::plugin::PluginManager;
use Commands::*;
#[tokio::main]
@@ -9,14 +13,15 @@ async fn main() -> anyhow::Result<()> {
set_up_logging();
let dioxus_config = DioxusConfig::load()
let _dioxus_config = DioxusConfig::load()
.map_err(|e| anyhow!("Failed to load `Dioxus.toml` because: {e}"))?
.unwrap_or_else(|| {
log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config");
DioxusConfig::default()
});
PluginManager::init(dioxus_config.plugin)
#[cfg(feature = "plugin")]
PluginManager::init(_dioxus_config.plugin)
.map_err(|e| anyhow!("🚫 Plugin system initialization failed: {e}"))?;
match args.action {
@@ -45,6 +50,7 @@ async fn main() -> anyhow::Result<()> {
.config()
.map_err(|e| anyhow!("🚫 Configuring new project failed: {}", e)),
#[cfg(feature = "plugin")]
Plugin(opts) => opts
.plugin()
.await
+12 -3
View File
@@ -1,4 +1,4 @@
use crate::{builder, plugin::PluginManager, serve::Serve, BuildResult, CrateConfig, Result};
use crate::{builder, serve::Serve, BuildResult, CrateConfig, Result};
use axum::{
body::{Full, HttpBody},
extract::{ws::Message, Extension, TypedHeader, WebSocketUpgrade},
@@ -29,6 +29,10 @@ use tower_http::{
cors::{Any, CorsLayer},
ServiceBuilderExt,
};
#[cfg(feature = "plugin")]
use plugin::PluginManager;
mod proxy;
pub struct BuildManager {
@@ -63,9 +67,10 @@ struct WsReloadState {
pub async fn startup(port: u16, config: CrateConfig, start_browser: bool) -> Result<()> {
// ctrl-c shutdown checker
let crate_config = config.clone();
let _crate_config = config.clone();
let _ = ctrlc::set_handler(move || {
let _ = PluginManager::on_serve_shutdown(&crate_config);
#[cfg(feature = "plugin")]
let _ = PluginManager::on_serve_shutdown(&_crate_config);
std::process::exit(0);
});
@@ -146,6 +151,7 @@ pub async fn startup_hot_reload(
log::info!("🚀 Starting development server...");
#[cfg(feature = "plugin")]
PluginManager::on_serve_start(&config)?;
let dist_path = config.out_dir.clone();
@@ -426,6 +432,8 @@ pub async fn startup_default(
elapsed_time: res.elapsed_time,
},
);
#[cfg(feature = "plugin")]
let _ = PluginManager::on_serve_rebuild(
chrono::Local::now().timestamp(),
e.paths,
@@ -459,6 +467,7 @@ pub async fn startup_default(
},
);
#[cfg(feature = "plugin")]
PluginManager::on_serve_start(&config)?;
let cors = CorsLayer::new()