Init project

This commit is contained in:
2026-05-21 05:43:10 +02:00
parent d408d01002
commit da819c22f6
2 changed files with 21 additions and 17 deletions
+18
View File
@@ -1,5 +1,6 @@
use <std::process>; use <std::process>;
use <std::env>; use <std::env>;
use <std::fs>;
pub mod builder; pub mod builder;
pub mod codegen; pub mod codegen;
@@ -29,6 +30,9 @@ void main() {
"transpile" | "t" => { "transpile" | "t" => {
transpiler::build(); transpiler::build();
} }
"init" => {
init_project();
}
"version" | "--version" | "-v" => { "version" | "--version" | "-v" => {
println!("mist {}", env!("CARGO_PKG_VERSION")); println!("mist {}", env!("CARGO_PKG_VERSION"));
} }
@@ -61,3 +65,17 @@ void print_usage() {
println!(" \x1b[36m mist version \x1b[0m print the compiler version\n"); println!(" \x1b[36m mist version \x1b[0m print the compiler version\n");
println!(" \x1b[36m mist help\x1b[0m print this message\n"); println!(" \x1b[36m mist help\x1b[0m print this message\n");
} }
void init_project(Vec<String> args) {
new process::Command("cargo")
.args(args)
.stdout(process::Stdio::piped())
.stderr(process::Stdio::piped())
.stdin(process::Stdio::piped())
.spawn()
.expect("Failed to run cargo");
fs::remove("src/main.rs").expect("Failed to remove src/main.rs");
fs::write("src/main.mist", "void main() {\n println!(\"Hello, World!\")\n}").expect("Failed to create src/main.mist");
}
+3 -17
View File
@@ -10,9 +10,9 @@ use mist_parser::error::ParseError;
pub fn build() -> PathBuf { pub fn build() -> PathBuf {
let start = Instant::now(); let start = Instant::now();
let root = find_project_root().unwrap_or_else(|| { let root = std::env::current_dir()
panic!("error: could not find project root (mist.json)"); .ok()
}); .expect("Unable to find project root");
let src_dir = root.join("src"); let src_dir = root.join("src");
let out_dir = root.join(".mist/src"); let out_dir = root.join(".mist/src");
@@ -164,17 +164,3 @@ fn should_skip(source: &Path, output: &Path) -> bool {
} }
false false
} }
pub fn find_project_root() -> Option<PathBuf> {
let mut dir = std::env::current_dir().ok()?;
loop {
if dir.join("mist.json").exists() {
return Some(dir);
}
if !dir.pop() {
return None;
}
}
}