lyrs/src/tailwind.rs

38 lines
1.3 KiB
Rust
Raw Normal View History

use std::process::Stdio;
use tokio::{
io::{AsyncBufReadExt, BufReader},
process::Command,
};
use tracing::{error, event, info, Level};
pub fn start_watcher() {
info!("Starting tailwind...");
match Command::new("tailwindcss")
.args(["-i", "src/style.css", "-o", "static/style.css", "--watch"])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
{
Ok(mut tw) => {
info!("Tailwind spawned!");
let mut stdout_reader = BufReader::new(tw.stdout.take().unwrap()).lines();
tokio::spawn(async move {
while let Ok(Some(l)) = stdout_reader.next_line().await {
if l.trim().len() > 0 {
event!(target: "tailwind::stdout", Level::INFO, "{l}");
}
}
});
let mut stderr_reader = BufReader::new(tw.stderr.take().unwrap()).lines();
tokio::spawn(async move {
while let Ok(Some(l)) = stderr_reader.next_line().await {
if l.trim().len() > 0 {
event!(target: "tailwind::stderr", Level::INFO, "{l}");
}
}
});
}
Err(e) => error!("Failed to spawn Tailwind: {e}"),
}
}