mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 12:52:47 -07:00
fix: check if project contains tuono.config.ts before running dev/build (#420)
This commit is contained in:
@@ -46,7 +46,15 @@ struct Args {
|
|||||||
action: Actions,
|
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> {
|
fn init_tuono_folder(mode: Mode) -> std::io::Result<App> {
|
||||||
|
check_for_tuono_config();
|
||||||
check_tuono_folder()?;
|
check_tuono_folder()?;
|
||||||
let app = bundle_axum_source(mode)?;
|
let app = bundle_axum_source(mode)?;
|
||||||
create_client_entry_files()?;
|
create_client_entry_files()?;
|
||||||
|
|||||||
@@ -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("./src/routes/[...all_routes].rs");
|
||||||
|
|
||||||
temp_tuono_project.add_file_with_content(
|
temp_tuono_project.add_file_with_content("./src/routes/api/[...all_apis].rs", POST_API_FILE);
|
||||||
"./src/routes/api/[...all_apis].rs",
|
|
||||||
&format!("{POST_API_FILE}"),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut test_tuono_build = Command::cargo_bin("tuono").unwrap();
|
let mut test_tuono_build = Command::cargo_bin("tuono").unwrap();
|
||||||
test_tuono_build
|
test_tuono_build
|
||||||
@@ -177,3 +174,29 @@ fn it_fails_without_installed_build_script() {
|
|||||||
.failure()
|
.failure()
|
||||||
.stderr("[CLI] Failed to read tuono.config.ts\n");
|
.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");
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ pub struct TempTuonoProject {
|
|||||||
|
|
||||||
impl TempTuonoProject {
|
impl TempTuonoProject {
|
||||||
pub fn new() -> Self {
|
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 original_dir = env::current_dir().expect("Failed to read current_dir");
|
||||||
let temp_dir = tempdir().expect("Failed to create temp_dir");
|
let temp_dir = tempdir().expect("Failed to create temp_dir");
|
||||||
|
|
||||||
@@ -28,7 +36,7 @@ impl TempTuonoProject {
|
|||||||
self.temp_dir.path()
|
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);
|
let path = PathBuf::from(path);
|
||||||
create_all(
|
create_all(
|
||||||
path.parent().expect("Route path does not have any parent"),
|
path.parent().expect("Route path does not have any parent"),
|
||||||
@@ -55,7 +63,7 @@ impl TempTuonoProject {
|
|||||||
impl Drop for TempTuonoProject {
|
impl Drop for TempTuonoProject {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Set back the current dir in the previous state
|
// 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.");
|
.expect("Failed to restore the original directory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user