Skip to content

Commit

Permalink
let tailwind output to a temporary file
Browse files Browse the repository at this point in the history
and read it afterwards instead of returning the stdout of the tailwind command
  • Loading branch information
crapStone committed Oct 6, 2023
1 parent eef2090 commit 08214e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/compile/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ pub async fn compile_tailwind(

if done {
log::info!("Tailwind finished {}", GRAY.paint(line));
Ok(Outcome::Success(output.stdout()))
match fs::read_to_string(&tw_conf.tmp_file).await {
Ok(content) => Ok(Outcome::Success(content)),
Err(e) => {
log::error!("Failed to read tailwind result: {e}");
Ok(Outcome::Failed)
}
}
} else {
log::warn!("Tailwind failed {}", GRAY.paint(line));
println!("{}\n{}", output.stdout(), output.stderr());
Expand Down Expand Up @@ -77,6 +83,8 @@ pub async fn tailwind_process(cmd: &str, tw_conf: &TailwindConfig) -> Result<(St
tw_conf.input_file.as_str(),
"--config",
tw_conf.config_file.as_str(),
"--output",
tw_conf.tmp_file.as_str(),
];
let line = format!("{} {}", cmd, args.join(" "));
let mut command = Command::new(tailwind);
Expand Down
3 changes: 3 additions & 0 deletions src/config/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ pub struct ProjectConfig {

#[serde(skip)]
pub config_dir: Utf8PathBuf,
#[serde(skip)]
pub tmp_dir: Utf8PathBuf,

// Profiles
pub lib_profile_dev: Option<String>,
Expand All @@ -197,6 +199,7 @@ impl ProjectConfig {
fn parse(dir: &Utf8Path, metadata: &serde_json::Value, cargo_metadata: &Metadata) -> Result<Self> {
let mut conf: ProjectConfig = serde_json::from_value(metadata.clone())?;
conf.config_dir = dir.to_path_buf();
conf.tmp_dir = cargo_metadata.target_directory.join("tmp");
let dotenvs = load_dotenvs(dir)?;
overlay_env(&mut conf, dotenvs)?;
if conf.site_root == "/"
Expand Down
4 changes: 4 additions & 0 deletions src/config/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::{bail, Result};
pub struct TailwindConfig {
pub input_file: Utf8PathBuf,
pub config_file: Utf8PathBuf,
pub tmp_file: Utf8PathBuf,
}

impl TailwindConfig {
Expand All @@ -26,9 +27,12 @@ impl TailwindConfig {
.unwrap_or_else(|| Utf8PathBuf::from("tailwind.config.js")),
);

let tmp_file = conf.tmp_dir.join("tailwind.css");

Ok(Some(Self {
input_file,
config_file,
tmp_file,
}))
}
}

0 comments on commit 08214e5

Please sign in to comment.