Skip to content

Commit

Permalink
fix: check if project contains tuono.config.ts before running dev/b…
Browse files Browse the repository at this point in the history
…uild (#420)
  • Loading branch information
jacobhq authored Jan 27, 2025
1 parent 2e141be commit b6fa448
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
8 changes: 8 additions & 0 deletions crates/tuono/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ struct Args {
action: Actions,
}

fn check_for_tuono_config() {
if !PathBuf::from("tuono.config.ts").exists() {
eprintln!("Cannot find tuono.config.ts - is this a tuono project?");
std::process::exit(1);
}
}

fn init_tuono_folder(mode: Mode) -> std::io::Result<App> {
check_for_tuono_config();
check_tuono_folder()?;
let app = bundle_axum_source(mode)?;
create_client_entry_files()?;
Expand Down
31 changes: 27 additions & 4 deletions crates/tuono/tests/cli_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ fn it_successfully_create_catch_all_routes() {

temp_tuono_project.add_file("./src/routes/[...all_routes].rs");

temp_tuono_project.add_file_with_content(
"./src/routes/api/[...all_apis].rs",
&format!("{POST_API_FILE}"),
);
temp_tuono_project.add_file_with_content("./src/routes/api/[...all_apis].rs", POST_API_FILE);

let mut test_tuono_build = Command::cargo_bin("tuono").unwrap();
test_tuono_build
Expand Down Expand Up @@ -177,3 +174,29 @@ fn it_fails_without_installed_build_script() {
.failure()
.stderr("[CLI] Failed to read tuono.config.ts\n");
}

#[test]
#[serial]
fn dev_fails_with_no_config() {
let _temp_tuono_project = TempTuonoProject::new_with_no_config();

let mut test_tuono_build = Command::cargo_bin("tuono").unwrap();
test_tuono_build
.arg("dev")
.assert()
.failure()
.stderr("Cannot find tuono.config.ts - is this a tuono project?\n");
}

#[test]
#[serial]
fn build_fails_with_no_config() {
let _temp_tuono_project = TempTuonoProject::new_with_no_config();

let mut test_tuono_build = Command::cargo_bin("tuono").unwrap();
test_tuono_build
.arg("dev")
.assert()
.failure()
.stderr("Cannot find tuono.config.ts - is this a tuono project?\n");
}
12 changes: 10 additions & 2 deletions crates/tuono/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ pub struct TempTuonoProject {

impl TempTuonoProject {
pub fn new() -> Self {
let project = TempTuonoProject::new_with_no_config();

project.add_file("./tuono.config.ts");

project
}

pub fn new_with_no_config() -> Self {
let original_dir = env::current_dir().expect("Failed to read current_dir");
let temp_dir = tempdir().expect("Failed to create temp_dir");

Expand All @@ -28,7 +36,7 @@ impl TempTuonoProject {
self.temp_dir.path()
}

pub fn add_file<'a>(&self, path: &'a str) -> File {
pub fn add_file(&self, path: &str) -> File {
let path = PathBuf::from(path);
create_all(
path.parent().expect("Route path does not have any parent"),
Expand All @@ -55,7 +63,7 @@ impl TempTuonoProject {
impl Drop for TempTuonoProject {
fn drop(&mut self) {
// Set back the current dir in the previous state
env::set_current_dir(self.original_dir.to_owned())
env::set_current_dir(&self.original_dir)
.expect("Failed to restore the original directory.");
}
}

0 comments on commit b6fa448

Please sign in to comment.