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

Fix tailwind with plugins by using a temporary file #200

Merged
merged 3 commits into from
Oct 13, 2023
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
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").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,
}))
}
}
Loading