From 4e1bcf36fce6d5be6a6cc8b10173baf90a1ae809 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 30 Jun 2026 19:14:12 +0200 Subject: [PATCH] Include sub crates #86 --- crates/mist-api/src/transpiler.mist | 30 ++++++++++++++++++++++++++--- src/main.mist | 6 ++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index 0a10669..1001f91 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -26,6 +26,7 @@ pub struct MistConfig { pub PathBuf package, pub Vec packages, + pub Vec include, pub mist_parser::MistFmtConfig fmt, } @@ -52,6 +53,7 @@ impl Default for MistConfig Self { package: PathBuf::from("main.mist"), packages: Vec::new(), + include: Vec::new(), fmt: mist_parser::MistFmtConfig { allman_bracket_style: true, }, @@ -59,10 +61,9 @@ impl Default for MistConfig } } -pub PathBuf transpile() +pub void transpile(Path& root) { let start = time::Instant::now(); - let root = env::current_dir().expect("Unable to find project root"); let toml_path = root.join("Mist.toml"); let src = root.join("src"); let out = root.join(".mist/src"); @@ -77,7 +78,30 @@ pub PathBuf transpile() let elapsed = start.elapsed(); println!("\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m", elapsed); - root + for incl in &config.include { + if ends_with_star(&incl) { + let sub_crates = incl.parent().expect("Failed to get parent"); + let entries = match fs::read_dir(sub_crates) { + Ok(entries) => entries, + Err(e) => { + eprintln!("error: failed to read directory {}\n {}", sub_crates.display(), e); + process::exit(1); + } + }; + for sub_crate in entries { + if let Ok(sub_crate) = sub_crate { + transpile(&sub_crate.path()); + } + } + } else { + transpile(incl); + } + } +} + +bool ends_with_star(Path& path) +{ + path.file_name().and_then((name) => name.to_str()).is_some_and((name) => name.ends_with("*")) } impl modules::Module diff --git a/src/main.mist b/src/main.mist index 3994119..3f28e86 100644 --- a/src/main.mist +++ b/src/main.mist @@ -17,7 +17,8 @@ void main() } match args[1].as_str() { "run" | "build" | "check" | "r" | "b" | "c" => { - let root = transpiler::transpile(); + let root = env::current_dir().expect("Unable to find project root"); + transpiler::transpile(&root); println!(""); if builder::build(args, root) { println!("\x1b[32m\nBuild successful\x1b[0m"); @@ -26,7 +27,8 @@ void main() } } "transpile" | "t" => { - transpiler::transpile(); + let root = env::current_dir().expect("Unable to find project root"); + transpiler::transpile(&root); } "init" => { init_project(args);