Better logging for tailwind subprocess
This commit is contained in:
parent
888359fead
commit
7b79205148
2 changed files with 30 additions and 4 deletions
33
src/main.rs
33
src/main.rs
|
@ -4,13 +4,15 @@ use axum::routing::get;
|
|||
use axum::{http::StatusCode, response::Html, serve, Router};
|
||||
use minijinja::{context, Environment};
|
||||
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
|
||||
use std::process::Stdio;
|
||||
use std::sync::Arc;
|
||||
use std::{path::PathBuf, str::FromStr, sync::OnceLock};
|
||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||
use tokio::sync::mpsc::channel;
|
||||
use tokio::sync::Mutex;
|
||||
use tower_http::services::ServeDir;
|
||||
use tower_livereload::{LiveReloadLayer, Reloader};
|
||||
pub use tracing::{debug, error, info, warn};
|
||||
pub use tracing::{debug, error, event, info, span, warn, Level};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Berr(Box<dyn std::error::Error>);
|
||||
|
@ -48,10 +50,33 @@ async fn main() -> Besult<()> {
|
|||
// TODO: only start tailwind if in dev mode?
|
||||
tokio::spawn(async move {
|
||||
info!("Starting tailwind...");
|
||||
let tw = tokio::process::Command::new("tailwindcss")
|
||||
match tokio::process::Command::new("tailwindcss")
|
||||
.args(["-i", "src/style.css", "-o", "static/style.css", "--watch"])
|
||||
.spawn();
|
||||
info!("Tailwind spawned. {tw:#?}");
|
||||
.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}"),
|
||||
}
|
||||
});
|
||||
|
||||
let templates = Arc::new(Mutex::new(Environment::new()));
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
</head>
|
||||
|
||||
<body class="bg-base text-text">
|
||||
Page Template
|
||||
{% block body %}{% endblock %}
|
||||
</body>
|
||||
|
||||
|
|
Loading…
Reference in a new issue