Include sub crates #86

This commit is contained in:
2026-06-30 19:14:12 +02:00
parent c1d7152992
commit 4e1bcf36fc
2 changed files with 31 additions and 5 deletions
+27 -3
View File
@@ -26,6 +26,7 @@ pub struct MistConfig
{ {
pub PathBuf package, pub PathBuf package,
pub Vec<PathBuf> packages, pub Vec<PathBuf> packages,
pub Vec<PathBuf> include,
pub mist_parser::MistFmtConfig fmt, pub mist_parser::MistFmtConfig fmt,
} }
@@ -52,6 +53,7 @@ impl Default for MistConfig
Self { Self {
package: PathBuf::from("main.mist"), package: PathBuf::from("main.mist"),
packages: Vec::new(), packages: Vec::new(),
include: Vec::new(),
fmt: mist_parser::MistFmtConfig { fmt: mist_parser::MistFmtConfig {
allman_bracket_style: true, 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 start = time::Instant::now();
let root = env::current_dir().expect("Unable to find project root");
let toml_path = root.join("Mist.toml"); let toml_path = root.join("Mist.toml");
let src = root.join("src"); let src = root.join("src");
let out = root.join(".mist/src"); let out = root.join(".mist/src");
@@ -77,7 +78,30 @@ pub PathBuf transpile()
let elapsed = start.elapsed(); let elapsed = start.elapsed();
println!("\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m", println!("\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m",
elapsed); 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 impl modules::Module
+4 -2
View File
@@ -17,7 +17,8 @@ void main()
} }
match args[1].as_str() { match args[1].as_str() {
"run" | "build" | "check" | "r" | "b" | "c" => { "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!(""); println!("");
if builder::build(args, root) { if builder::build(args, root) {
println!("\x1b[32m\nBuild successful\x1b[0m"); println!("\x1b[32m\nBuild successful\x1b[0m");
@@ -26,7 +27,8 @@ void main()
} }
} }
"transpile" | "t" => { "transpile" | "t" => {
transpiler::transpile(); let root = env::current_dir().expect("Unable to find project root");
transpiler::transpile(&root);
} }
"init" => { "init" => {
init_project(args); init_project(args);