Skip to content

Commit

Permalink
move tailwind into parent
Browse files Browse the repository at this point in the history
closes #206

Co-authored-by: Auguste Baum <[email protected]>
Co-authored-by: Shahar "Dawn" Or <[email protected]>
  • Loading branch information
3 people committed Oct 24, 2023
1 parent 72a9fb0 commit f273318
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 110 deletions.
27 changes: 24 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ tokio_console = ["dep:console-subscriber"]
[dependencies]
anyhow = { version = "1.0.66", features = ["backtrace"] }
camino = "1.1.4"
builder = { version = "0.0.0", path = "builder" }
chrono = { version = "0.4.19", features = ["serde"] }
clap = { version = "4.1.4", features = ["derive"] }
console-subscriber = { version = "0.1.8", optional = true }
Expand Down
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use clap::{Parser, Subcommand};
use once_cell::sync::Lazy;
use ssg_parent::Parent;

use builder::OUTPUT_DIR;

pub static OUTPUT_DIR: Lazy<Utf8PathBuf> =
Lazy::new(|| Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".vercel/output/static"));

Expand Down Expand Up @@ -46,7 +44,7 @@ async fn main() -> anyhow::Result<()> {

let cli = Cli::parse();

let parent = Parent::new(OUTPUT_DIR.clone());
let parent = Parent::new(OUTPUT_DIR.clone()).post_build(tailwind::execute);

match cli.mode.unwrap_or_default() {
Mode::Build => parent.build().await?,
Expand Down
5 changes: 3 additions & 2 deletions src/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use tokio::process::Command;

use crate::OUTPUT_DIR;

pub(crate) fn execute() -> BoxFuture<'static, Result<(), Box<dyn std::error::Error>>> {
pub(crate) fn execute(
) -> BoxFuture<'static, Result<(), Box<dyn std::error::Error + 'static + Send + Sync>>> {
async {
let output = Command::new("npx")
.args([
Expand Down Expand Up @@ -38,7 +39,7 @@ pub(crate) fn execute() -> BoxFuture<'static, Result<(), Box<dyn std::error::Err

let output = match output {
Ok(output) => output,
Err(error) => return Err(Box::new(error) as Box<dyn std::error::Error>),
Err(error) => return Err(Box::new(error) as Box<dyn std::error::Error + Send + Sync>),
};

if let Err(error) = stdout().write_all(&output.stderr) {
Expand Down
1 change: 1 addition & 0 deletions ssg-parent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
async-trait = "0.1.64"
camino = "1.1.4"
colored = "2.0.0"
derive_more = { version = "1.0.0-beta.3", features = ["debug"] }
futures = "0.3.28"
live-server = "0.6.0"
once_cell = "1.17.1"
Expand Down
94 changes: 0 additions & 94 deletions ssg-parent/src/dev.rs

This file was deleted.

49 changes: 42 additions & 7 deletions ssg-parent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
use colored::Colorize;
use futures::{
channel::mpsc,
future::{self, LocalBoxFuture},
future::{self, BoxFuture, LocalBoxFuture},
stream::{self, LocalBoxStream},
FutureExt, SinkExt, StreamExt,
};
use reactive::driver::Driver;

#[derive(Debug)]
type PostBuildReturn =
BoxFuture<'static, Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>>;

#[derive(derive_more::Debug)]
#[must_use]
pub struct Parent {
output_dir: camino::Utf8PathBuf,
builder: BuilderState,
#[debug("{}", match post_build { None => "None", Some(_) => "Some(function)" })]
post_build: Option<Box<dyn Fn() -> PostBuildReturn>>,
}

const BUILDER_CRATE_NAME: &str = "builder";
Expand Down Expand Up @@ -62,16 +68,24 @@ pub enum BuildError {
ExitCode(i32),
#[error("builder terminated without exit code")]
NoExitCode,
#[error("post_build: {0}")]
PostBuild(#[from] Box<dyn std::error::Error + Send + Sync>),
}

impl Parent {
pub fn new(output_dir: impl Into<camino::Utf8PathBuf>) -> Self {
Self {
output_dir: output_dir.into(),
builder: BuilderState::default(),
post_build: None,
}
}

pub fn post_build(mut self, f: impl Fn() -> PostBuildReturn + 'static) -> Self {
self.post_build = Some(Box::new(f));
self
}

/// Build once
///
/// # Errors
Expand All @@ -80,13 +94,15 @@ impl Parent {
pub async fn build(&self) -> Result<(), BuildError> {
let mut command = self.builder_command();
let status = command.status().await?;
if status.success() {
Ok(())
} else {
Err(status
if !status.success() {
return Err(status
.code()
.map_or(BuildError::NoExitCode, BuildError::ExitCode))
.map_or(BuildError::NoExitCode, BuildError::ExitCode));
}
if let Some(post_build) = &self.post_build {
post_build().await?;
}
Ok(())
}

/// Sets up a development environment that watches the file system,
Expand Down Expand Up @@ -380,3 +396,22 @@ impl Parent {
}
}
}

#[cfg(test)]
mod test {
use crate::{BuilderState, Parent};

#[test]
fn parent_debug() {
let parent_no_post_build = Parent {
output_dir: camino::Utf8PathBuf::from("path/to/there"),
builder: BuilderState::default(),
post_build: None,
};

let actual = format!("{parent_no_post_build:?}");
let expected =
"Parent { output_dir: \"path/to/there\", builder: AwaitingChild, post_build: None }";
assert_eq!(actual, expected);
}
}

0 comments on commit f273318

Please sign in to comment.