crossbundle_tools/commands/common/gen_minimal_project/
gen_min_project.rs

1use super::*;
2use crate::error::*;
3use std::{
4    fs::{create_dir, File},
5    io::Write,
6};
7
8// TODO: Fix this file logic.
9
10/// Generates a new minimal project in given path.
11pub fn gen_minimal_project(out_dir: &std::path::Path, macroquad_project: bool) -> Result<String> {
12    // Create Cargo.toml file
13    let file_path = out_dir.join("Cargo.toml");
14    let mut file = File::create(file_path)?;
15    if macroquad_project {
16        file.write_all(MINIMAL_MQ_CARGO_TOML_VALUE.as_bytes())?;
17    } else {
18        file.write_all(MINIMAL_BEVY_CARGO_TOML_VALUE.as_bytes())?;
19    }
20    // Create src folder
21    let src_path = out_dir.join("src");
22    create_dir(&src_path)?;
23    // Create main.rs
24    let main_rs_path = src_path.join("main.rs");
25    let mut main_rs = File::create(main_rs_path)?;
26    if macroquad_project {
27        main_rs.write_all(MQ_MAIN_RS_VALUE.as_bytes())?;
28    } else {
29        main_rs.write_all(BEVY_MAIN_RS_VALUE.as_bytes())?;
30    }
31    create_res_folder(out_dir)?;
32    Ok("example".to_owned())
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn test_command_run() {
41        let dir = tempfile::tempdir().unwrap();
42        gen_minimal_project(dir.path(), true).unwrap();
43    }
44}