Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add spinner to 'tuono dev' #550

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/tuono/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ serde_json = "1.0"
fs_extra = "1.3.0"
http = "1.1.0"
tuono_internal = {path = "../tuono_internal", version = "0.17.7"}
spinners = "4.1.1"
console = "0.15.10"

[dev-dependencies]
tempfile = "3.14.0"
Expand Down
36 changes: 30 additions & 6 deletions crates/tuono/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use watchexec_supervisor::job::{start_job, Job};

use crate::mode::Mode;
use crate::source_builder::bundle_axum_source;
use console::Term;
use spinners::{Spinner, Spinners};

#[cfg(target_os = "windows")]
const DEV_WATCH_BIN_SRC: &str = "node_modules\\.bin\\tuono-dev-watch.cmd";
Expand All @@ -35,7 +37,7 @@ fn watch_react_src() -> Job {
.0
}

fn build_rust_src() -> Job {
fn run_rust_dev_server() -> Job {
start_job(Arc::new(Command {
program: Program::Exec {
prog: "cargo".into(),
Expand All @@ -46,6 +48,17 @@ fn build_rust_src() -> Job {
.0
}

fn build_rust_src() -> Job {
start_job(Arc::new(Command {
program: Program::Exec {
prog: "cargo".into(),
args: vec!["build".to_string(), "-q".to_string()],
},
options: Default::default(),
}))
.0
}

fn build_react_ssr_src() -> Job {
if !Path::new(DEV_SSR_BIN_SRC).exists() {
eprintln!("Failed to find script to run dev ssr. Please run `npm install`");
Expand All @@ -63,17 +76,28 @@ fn build_react_ssr_src() -> Job {

#[tokio::main]
pub async fn watch() -> Result<()> {
let term = Term::stdout();
let mut sp = Spinner::new(Spinners::Dots, "Starting dev server...".into());

watch_react_src().start().await;

let run_server = build_rust_src();
let rust_server = run_rust_dev_server();
let build_rust_src = build_rust_src();

let build_ssr_bundle = build_react_ssr_src();

build_ssr_bundle.start().await;
build_rust_src.start().await;

run_server.start().await;

// Wait vite and rust builds
build_ssr_bundle.to_wait().await;
build_rust_src.to_wait().await;

rust_server.start().await;

// Remove the spinner
sp.stop();
term.clear_line().unwrap();

let wx = Watchexec::new(move |mut action| {
let mut should_reload_ssr_bundle = false;
Expand All @@ -95,9 +119,9 @@ pub async fn watch() -> Result<()> {

if should_reload_rust_server {
println!(" Reloading...");
run_server.stop();
rust_server.stop();
bundle_axum_source(Mode::Dev).expect("Failed to bundle rust source");
run_server.start();
rust_server.start();
}

if should_reload_ssr_bundle {
Expand Down
Loading