feat: prevent empty .tuono folder

This commit is contained in:
Valerio Ageno
2024-05-26 18:43:38 +02:00
parent 73e142a5d7
commit 0780a6ec79
3 changed files with 33 additions and 10 deletions
+16 -6
View File
@@ -3,6 +3,8 @@ use std::process::Command;
mod source_builder;
use source_builder::{bundle_axum_source, create_client_entry_files};
use self::source_builder::check_tuono_folder;
mod watch;
#[derive(Subcommand, Debug)]
@@ -22,23 +24,31 @@ struct Args {
action: Actions,
}
pub fn cli() {
fn init_tuono_folder() -> std::io::Result<()> {
check_tuono_folder()?;
bundle_axum_source()?;
create_client_entry_files()?;
Ok(())
}
pub fn cli() -> std::io::Result<()> {
let args = Args::parse();
match args.action {
Actions::Dev => {
bundle_axum_source();
create_client_entry_files().unwrap();
init_tuono_folder()?;
watch::watch().unwrap();
}
Actions::Build => {
bundle_axum_source();
create_client_entry_files().unwrap();
init_tuono_folder()?;
let mut vite_build = Command::new("./node_modules/.bin/tuono-build-prod");
let _ = &vite_build.output().unwrap();
let _ = &vite_build.output()?;
}
Actions::New => {
println!("Scaffold new project")
}
}
Ok(())
}
+1 -1
View File
@@ -1,5 +1,5 @@
use tuono::cli;
fn main() {
cli();
cli().unwrap();
}
+16 -3
View File
@@ -165,7 +165,7 @@ mod {route};
route_declarations
}
pub fn bundle_axum_source() {
pub fn bundle_axum_source() -> io::Result<()> {
println!("Axum project bundling");
let base_path = std::env::current_dir().unwrap();
@@ -177,15 +177,28 @@ pub fn bundle_axum_source() {
.replace("// MODULE_IMPORTS\n", &create_modules_declaration(&mods));
create_main_file(&base_path, &bundled_file);
Ok(())
}
pub fn check_tuono_folder() -> io::Result<()> {
let dev_folder = Path::new(DEV_FOLDER);
if !&dev_folder.is_dir() {
println!("exists");
fs::create_dir(dev_folder)?;
}
Ok(())
}
pub fn create_client_entry_files() -> io::Result<()> {
let dev_folder = Path::new(DEV_FOLDER);
let mut server_entry = fs::File::create(&dev_folder.join("server-main.tsx"))?;
let mut client_entry = fs::File::create(&dev_folder.join("client-main.tsx"))?;
server_entry.write(SERVER_ENTRY_DATA.as_bytes())?;
client_entry.write(CLIENT_ENTRY_DATA.as_bytes())?;
server_entry.write(&SERVER_ENTRY_DATA.as_bytes())?;
client_entry.write(&CLIENT_ENTRY_DATA.as_bytes())?;
Ok(())
}