Add liveview support to the CLI and make fullstack runnable from dist (#2759)

* add liveview cli support
* Fix TUI fullstack deadlock
* look for fullstack assets in the public directory
* Fix fullstack with the CLI
* Fix static generation server
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-08-01 17:46:35 -07:00
1 parent 9dbdf74a1e
commit e5e578d27b
14 files changed
+428 -272

No files matched your search

+42 -9
View File
@@ -1,9 +1,12 @@
use crate::builder::{Stage, UpdateBuildProgress, UpdateStage};
use std::future::{poll_fn, Future, IntoFuture};
use std::task::Poll;
use crate::builder::{Stage, TargetPlatform, UpdateBuildProgress, UpdateStage};
use crate::cli::serve::Serve;
use crate::dioxus_crate::DioxusCrate;
use crate::tracer::CLILogControl;
use crate::Result;
use dioxus_cli_config::Platform;
use futures_util::FutureExt;
use tokio::task::yield_now;
mod builder;
@@ -103,7 +106,7 @@ pub async fn serve_all(
// Run the server in the background
// Waiting for updates here lets us tap into when clients are added/removed
if let Some(msg) = msg {
screen.new_ws_message(Platform::Web, msg);
screen.new_ws_message(TargetPlatform::Web, msg);
}
}
@@ -135,8 +138,11 @@ pub async fn serve_all(
for build_result in results.iter() {
let child = build_result.open(&serve.server_arguments, server.fullstack_address(), &dioxus_crate.workspace_dir());
match child {
Ok(Some(child_proc)) => builder.children.push((build_result.platform,child_proc)),
Err(_e) => break,
Ok(Some(child_proc)) => builder.children.push((build_result.target_platform, child_proc)),
Err(e) => {
tracing::error!("Failed to open build result: {e}");
break;
},
_ => {}
}
}
@@ -150,10 +156,20 @@ pub async fn serve_all(
},
// If the process exited *cleanly*, we can exit
Ok(BuilderUpdate::ProcessExited { status, ..}) => {
if let Some(status) = status {
if status.success() {
break;
Ok(BuilderUpdate::ProcessExited { status, target_platform }) => {
// Then remove the child process
builder.children.retain(|(platform, _)| *platform != target_platform);
match status {
Ok(status) => {
if status.success() {
break;
}
else {
tracing::error!("Application exited with status: {status}");
}
},
Err(e) => {
tracing::error!("Application exited with error: {e}");
}
}
}
@@ -187,3 +203,20 @@ pub async fn serve_all(
Ok(())
}
// Grab the output of a future that returns an option or wait forever
pub(crate) fn next_or_pending<F, T>(f: F) -> impl Future<Output = T>
where
F: IntoFuture<Output = Option<T>>,
{
let pinned = f.into_future().fuse();
let mut pinned = Box::pin(pinned);
poll_fn(move |cx| {
let next = pinned.as_mut().poll(cx);
match next {
Poll::Ready(Some(next)) => Poll::Ready(next),
_ => Poll::Pending,
}
})
.fuse()
}