Add default main.shu file to init command

This commit is contained in:
Moritz Hölting 2024-04-01 19:30:56 +02:00
parent b7617a1675
commit d7a3f19967
2 changed files with 20 additions and 0 deletions

5
assets/default-main.shu Normal file
View File

@ -0,0 +1,5 @@
#[tick]
fn main() {
// Change this
/say Hello World!
}

View File

@ -40,6 +40,9 @@ pub fn init(
let src_path = path.join("src"); let src_path = path.join("src");
create_dir(&src_path, verbose)?; create_dir(&src_path, verbose)?;
// Create the main.shu file
create_main_file(path, verbose)?;
print_success("Project initialized successfully."); print_success("Project initialized successfully.");
Ok(()) Ok(())
@ -116,3 +119,15 @@ fn create_pack_png(path: &Path, verbose: bool) -> std::io::Result<()> {
} }
Ok(()) Ok(())
} }
fn create_main_file(path: &Path, verbose: bool) -> std::io::Result<()> {
let main_file = path.join("src").join("main.shu");
fs::write(&main_file, include_str!("../../assets/default-main.shu"))?;
if verbose {
print_info(&format!(
"Created main.shu file at {}.",
to_absolute_path(&main_file)?
));
}
Ok(())
}