Skip to content

Commit

Permalink
Tailwind to file avoid read stdout bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Nov 19, 2023
1 parent 6b4defe commit 726852e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde = { workspace = true, features = ["derive"] }
anyhow = { workspace = true }
log = "0.4"
flexi_logger = "0.27"
lightningcss = { version = "1.0.0-alpha.47", features = ["browserslist"] }
lightningcss = { version = "1.0.0-alpha.51", features = ["browserslist"] }
salvo = { workspace = true, features = ["websocket"] }
tokio = { version = "1.4", default-features = false, features = ["full"] }
# not using notify 5.0 because it uses Crossbeam which has an issue with tokio
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/compile/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn browser_lists(query: &str) -> Result<Option<Browsers>> {
async fn process_css(proj: &Project, css: String) -> Result<Product> {
let browsers = browser_lists(&proj.style.browser_query).context("glory.style.browser_query")?;

let mut stylesheet = StyleSheet::parse(&css, ParserOptions::default()).map_err(|e| anyhow!("{e}"))?;
let mut stylesheet = StyleSheet::parse(&css, ParserOptions::default()).map_err(|e| anyhow!("lightingcss: {e}"))?;

if proj.release {
stylesheet.minify(MinifyOptions::default())?;
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/compile/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub async fn compile_tailwind(_proj: &Project, tw_conf: &TailwindConfig) -> Resu

if done {
log::info!("Tailwind finished {}", GRAY.paint(line));
Ok(Outcome::Success(output.stdout()))
let css = std::fs::read_to_string(&tw_conf.output_file).context("read tailwind output")?;
Ok(Outcome::Success(css))
} else {
log::warn!("Tailwind failed {}", GRAY.paint(line));
println!("{}\n{}", output.stdout(), output.stderr());
Expand Down Expand Up @@ -64,7 +65,7 @@ async fn create_default_tailwind_config(tw_conf: &TailwindConfig) -> Result<()>
pub async fn tailwind_process(cmd: &str, tw_conf: &TailwindConfig) -> Result<(String, Command)> {
let tailwind = Exe::Tailwind.get().await.dot()?;

let args: Vec<&str> = vec!["--input", tw_conf.input_file.as_str(), "--config", tw_conf.config_file.as_str()];
let args: Vec<&str> = vec!["--input", tw_conf.input_file.as_str(), "--output", tw_conf.output_file.as_str(), "--config", tw_conf.config_file.as_str()];
let line = format!("{} {}", cmd, args.join(" "));
let mut command = Command::new(tailwind);
command.args(args);
Expand Down
11 changes: 10 additions & 1 deletion crates/cli/src/config/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::{bail, Result};
#[derive(Clone, Debug)]
pub struct TailwindConfig {
pub input_file: Utf8PathBuf,
pub output_file: Utf8PathBuf,
pub config_file: Utf8PathBuf,
}

Expand All @@ -20,12 +21,20 @@ impl TailwindConfig {
return Ok(None);
};

let mut output_file = Utf8PathBuf::new();
output_file.push("target/front/");
output_file.push(&input_file);

let config_file = conf.config_dir.join(
conf.tailwind_config_file
.clone()
.unwrap_or_else(|| Utf8PathBuf::from("tailwind.config.js")),
);

Ok(Some(Self { input_file, config_file }))
Ok(Some(Self {
input_file,
output_file,
config_file,
}))
}
}
5 changes: 5 additions & 0 deletions crates/core/src/web/events/csr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ impl<E: FromWasmAbi> Custom<E> {
}
}
}

/// Creates a custom event type, this is equal to [`Custom::new`].
pub fn custom<E: FromWasmAbi + 'static>(name: impl Into<Cow<'static, str>>) -> Custom<E> {
Custom::new(name)
}
5 changes: 5 additions & 0 deletions crates/core/src/web/events/ssr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ impl<E> Custom<E> {
}
}
}

/// Creates a custom event type, this is equal to [`Custom::new`].
pub fn custom<E: 'static>(name: impl Into<Cow<'static, str>>) -> Custom<E> {
Custom::new(name)
}

0 comments on commit 726852e

Please sign in to comment.