Skip to content

Commit

Permalink
Fix tailwind with plugins by using a temporary file (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
crapStone authored Oct 13, 2023
1 parent 3bdaa8d commit f57c006
Show file tree
Hide file tree
Showing 4 changed files with 17 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,

#[serde(default)]
pub separate_front_target_dir: bool,
Expand All @@ -200,6 +202,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").unbase(&cargo_metadata.workspace_root).unwrap();
let dotenvs = load_dotenvs(dir)?;
overlay_env(&mut conf, dotenvs)?;
if conf.site_root == "/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Config {
TailwindConfig {
input_file: "style/tailwind.css",
config_file: "tailwind.config.js",
tmp_file: "target/tmp/tailwind.css",
},
),
site_file: SiteFile {
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 f57c006

Please sign in to comment.