mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 12:52:47 -07:00
feat: prevent empty .tuono folder
This commit is contained in:
+16
-6
@@ -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,5 +1,5 @@
|
||||
use tuono::cli;
|
||||
|
||||
fn main() {
|
||||
cli();
|
||||
cli().unwrap();
|
||||
}
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user