Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Milo123459 committed Jan 16, 2025
1 parent c7b752f commit 66e51cc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/providers/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl Provider for NodeProvider {

let mut phases = vec![setup, install, build];
if let Some(caddy) = SpaProvider::caddy_phase(app, env) {
phases.push(caddy); // insert after setup and before build
phases.push(caddy);
}
let is_spa = SpaProvider::is_spa(app);

Expand Down Expand Up @@ -337,6 +337,10 @@ impl NodeProvider {
)));
}

if let Some(start) = SpaProvider::start_command(app, env) {
return Ok(Some(start));
}

let package_manager = NodeProvider::get_package_manager(app);
if NodeProvider::has_script(app, "start")? {
return Ok(Some(format!("{package_manager} run start")));
Expand Down
15 changes: 14 additions & 1 deletion src/providers/node/spa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::nixpacks::{

pub mod vite;

const NIX_ARCHIVE: &str = "ba913eda2df8eb72147259189d55932012df6301";

pub struct SpaProvider {}

impl SpaProvider {
Expand All @@ -26,7 +28,7 @@ impl SpaProvider {
|| env.get_config_variable("SPA_OUT_DIR").is_some())
{
let mut caddy = Phase::new("caddy");
caddy.set_nix_archive(String::from("ba913eda2df8eb72147259189d55932012df6301")); // caddy 2.0.4
caddy.set_nix_archive(String::from(NIX_ARCHIVE)); // caddy 2.0.4
caddy.add_nix_pkgs(&[Pkg::new("caddy")]);
caddy.add_cmd(format!(
"caddy fmt --overwrite {}",
Expand All @@ -48,4 +50,15 @@ impl SpaProvider {
// other ones will be implemented here
vite::ViteSpaProvider::get_output_directory(app)
}

pub fn start_command(app: &App, env: &Environment) -> Option<String> {
if Self::caddy_phase(app, env).is_some() {
Some(format!(
"exec caddy run --config {} --adapter caddyfile 2>&1",
app.asset_path("Caddyfile")
))
} else {
None
}
}
}
14 changes: 14 additions & 0 deletions src/providers/node/spa/vite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,18 @@ mod tests {
let app = crate::nixpacks::app::App::new("examples/node-vite-solid-ts").unwrap();
assert_eq!(ViteSpaProvider::get_output_directory(&app), "out");
}

#[test]
fn test_not_match() {
// should not match
let app = crate::nixpacks::app::App::new("examples/node-bun-web-server").unwrap();
assert!(!ViteSpaProvider::is_vite(&app));
}

#[test]
fn test_not_match_2() {
// should not match
let app = crate::nixpacks::app::App::new("examples/node").unwrap();
assert!(!ViteSpaProvider::is_vite(&app));
}
}

0 comments on commit 66e51cc

Please sign in to comment.