From eb23ff1e5a927d50626ff5e7a5b3263b3f4bee3a Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Thu, 2 Jul 2026 20:51:02 +0200 Subject: [PATCH] Gitignore, and mist new --- src/main.mist | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main.mist b/src/main.mist index 7846b44..481cd81 100644 --- a/src/main.mist +++ b/src/main.mist @@ -35,6 +35,9 @@ void main() "init" => { init_project(args); } + "new" => { + new_project(args); + } "version" | "--version" | "-v" => { println!("mist {}", env!("CARGO_PKG_VERSION")); } @@ -75,6 +78,7 @@ void print_usage() println!(" \x1b[36m mist transpile\x1b[0m,\x1b[36m t\x1b[0m transpile the project in the current directory\n"); println!(" \x1b[36m mist check\x1b[0m,\x1b[36m c\x1b[0m check the project in the current directory\n"); println!(" \x1b[36m mist init\x1b[0m initialize a project in the current folder\n"); + println!(" \x1b[36m mist new\x1b[0m create a new project\n"); println!(" \x1b[36m mist version \x1b[0m print the compiler version\n"); println!(" \x1b[36m mist help\x1b[0m print this message\n"); } @@ -96,6 +100,36 @@ void init_project(Vec mut args) } inject_mist_target(is_lib); add_mist_toml(is_lib); + add_gitignore(); + println!("Thank you for using Mist!\n"); +} + +void new_project(Vec mut args) +{ + args.remove(0); + if args.len() < 2 { + eprintln!("error: missing project name\n"); + print_usage(); + process::exit(1); + } + String project_name = args[1].clone(); + let status = process::Command::new("cargo").args(args).stdout(process::Stdio::inherit()).stderr(process::Stdio::inherit()).stdin(process::Stdio::inherit()).spawn().expect("Failed to run cargo").wait().expect("Unable to wait"); + if !status.success() { + return; + } + std::path::PathBuf project_path = env::current_dir().expect("Unable to find project root").join(&project_name); + env::set_current_dir(&project_path).expect("Failed to change to project directory"); + bool is_lib = fs::metadata("src/lib.rs").is_ok(); + if is_lib { + fs::remove_file("src/lib.rs").expect("Failed to remove src/lib.rs"); + fs::write("src/lib.mist", "void test() {\n}").expect("Failed to create src/lib.mist"); + } else { + fs::remove_file("src/main.rs").expect("Failed to remove src/main.rs"); + fs::write("src/main.mist", "void main() {\n println!(\"Hello, World!\");\n}\n").expect("Failed to create src/main.mist"); + } + inject_mist_target(is_lib); + add_mist_toml(is_lib); + add_gitignore(); println!("Thank you for using Mist!\n"); } @@ -121,3 +155,13 @@ void add_mist_toml(bool is_lib) }; fs::write("Mist.toml", content).expect("Failed to add Mist.toml"); } + +void add_gitignore() +{ + if fs::metadata(".gitignore").is_ok() { + String content = fs::read_to_string(".gitignore").expect("Failed to read .gitignore"); + if !content.contains(".mist") { + fs::write(".gitignore", content + "\n.mist\n").expect("Failed to write .gitignore"); + } + } +}