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: propagate build error and check if js files exist #297

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion crates/tuono/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::{hash_map::Entry, HashMap};
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::Path;
use std::path::PathBuf;
use std::process::Child;
use std::process::Command;
Expand Down Expand Up @@ -138,9 +139,18 @@ impl App {
}

pub fn build_react_prod(&self) {
Command::new(BUILD_JS_SCRIPT)
if !Path::new(BUILD_JS_SCRIPT).exists() {
eprintln!("Failed to find the build script. Please run `npm install`");
std::process::exit(1);
}
let output = Command::new(BUILD_JS_SCRIPT)
.output()
.expect("Failed to build the react source");
if !output.status.success() {
eprintln!("Failed to build the react source");
eprintln!("Error: {}", String::from_utf8_lossy(&output.stderr));
std::process::exit(1);
}
}

pub fn run_rust_server(&self) -> Child {
Expand All @@ -154,6 +164,10 @@ impl App {
}

pub fn build_tuono_config(&self) -> Result<std::process::Output, std::io::Error> {
if !Path::new(BUILD_TUONO_CONFIG).exists() {
eprintln!("Failed to find the build script. Please run `npm install`");
std::process::exit(1);
}
Command::new(BUILD_TUONO_CONFIG)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
Expand Down
9 changes: 9 additions & 0 deletions crates/tuono/src/watch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::Path;
use std::sync::Arc;
use watchexec_supervisor::command::{Command, Program};

Expand All @@ -20,6 +21,10 @@ const DEV_WATCH_BIN_SRC: &str = "node_modules/.bin/tuono-dev-watch";
const DEV_SSR_BIN_SRC: &str = "node_modules/.bin/tuono-dev-ssr";

fn watch_react_src() -> Job {
if !Path::new(DEV_SSR_BIN_SRC).exists() {
eprintln!("Failed to find script to run dev watch. Please run `npm install`");
std::process::exit(1);
}
start_job(Arc::new(Command {
program: Program::Exec {
prog: DEV_WATCH_BIN_SRC.into(),
Expand All @@ -42,6 +47,10 @@ fn build_rust_src() -> Job {
}

fn build_react_ssr_src() -> Job {
if !Path::new(DEV_SSR_BIN_SRC).exists() {
eprintln!("Failed to find script to run dev ssr. Please run `npm install`");
std::process::exit(1);
}
start_job(Arc::new(Command {
program: Program::Exec {
prog: DEV_SSR_BIN_SRC.into(),
Expand Down
Loading