feat: rebuild supported
This commit is contained in:
1 parent
1aaedab752
commit
9f20337e5e
4 files changed
+84
-11
No files matched your search
+23
-9
@@ -16,7 +16,7 @@ use std::{net::UdpSocket, path::PathBuf, process::Command, sync::Arc};
|
||||
use tower::ServiceBuilder;
|
||||
use tower_http::services::fs::{ServeDir, ServeFileSystemResponseBody};
|
||||
|
||||
use crate::{builder, serve::Serve, BuildResult, CrateConfig, Result};
|
||||
use crate::{builder, plugin::PluginManager, serve::Serve, BuildResult, CrateConfig, Result};
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
mod hot_reload;
|
||||
@@ -52,20 +52,26 @@ struct WsReloadState {
|
||||
update: broadcast::Sender<()>,
|
||||
}
|
||||
|
||||
pub async fn startup(port: u16, config: CrateConfig) -> Result<()> {
|
||||
pub async fn startup(port: u16, config: CrateConfig, plugin_manager: PluginManager) -> Result<()> {
|
||||
if config.hot_reload {
|
||||
startup_hot_reload(port, config).await?
|
||||
startup_hot_reload(port, config, plugin_manager).await?
|
||||
} else {
|
||||
startup_default(port, config).await?
|
||||
startup_default(port, config, plugin_manager).await?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
|
||||
pub async fn startup_hot_reload(
|
||||
port: u16,
|
||||
config: CrateConfig,
|
||||
plugin_manager: PluginManager,
|
||||
) -> Result<()> {
|
||||
let first_build_result = crate::builder::build(&config, false)?;
|
||||
|
||||
log::info!("🚀 Starting development server...");
|
||||
|
||||
plugin_manager.on_serve_start(&config)?;
|
||||
|
||||
let dist_path = config.out_dir.clone();
|
||||
let (reload_tx, _) = broadcast::channel(100);
|
||||
let last_file_rebuild = Arc::new(Mutex::new(FileMap::new(config.crate_dir.clone())));
|
||||
@@ -274,11 +280,17 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn startup_default(port: u16, config: CrateConfig) -> Result<()> {
|
||||
pub async fn startup_default(
|
||||
port: u16,
|
||||
config: CrateConfig,
|
||||
plugin_manager: PluginManager,
|
||||
) -> Result<()> {
|
||||
let first_build_result = crate::builder::build(&config, false)?;
|
||||
|
||||
log::info!("🚀 Starting development server...");
|
||||
|
||||
plugin_manager.on_serve_start(&config)?;
|
||||
|
||||
let dist_path = config.out_dir.clone();
|
||||
|
||||
let (reload_tx, _) = broadcast::channel(100);
|
||||
@@ -306,7 +318,7 @@ pub async fn startup_default(port: u16, config: CrateConfig) -> Result<()> {
|
||||
let watcher_config = config.clone();
|
||||
let mut watcher = notify::recommended_watcher(move |info: notify::Result<notify::Event>| {
|
||||
let config = watcher_config.clone();
|
||||
if info.is_ok() {
|
||||
if let Ok(e) = info {
|
||||
if chrono::Local::now().timestamp() > last_update_time {
|
||||
match build_manager.rebuild() {
|
||||
Ok(res) => {
|
||||
@@ -315,11 +327,13 @@ pub async fn startup_default(port: u16, config: CrateConfig) -> Result<()> {
|
||||
port,
|
||||
&config,
|
||||
PrettierOptions {
|
||||
changed: info.unwrap().paths,
|
||||
changed: e.paths.clone(),
|
||||
warnings: res.warnings,
|
||||
elapsed_time: res.elapsed_time,
|
||||
},
|
||||
);
|
||||
let _ = plugin_manager
|
||||
.on_serve_rebuild(chrono::Local::now().timestamp(), e.paths);
|
||||
}
|
||||
Err(e) => log::error!("{}", e),
|
||||
}
|
||||
@@ -599,4 +613,4 @@ async fn ws_handler(
|
||||
|
||||
reload_watcher.await.unwrap();
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user