Working package ignore

This commit is contained in:
2026-06-11 19:34:37 +02:00
parent 74d53fff97
commit a5a3d6566b
2 changed files with 18 additions and 20 deletions
+11 -16
View File
@@ -3,13 +3,15 @@ use std::path::PathBuf;
use std::fs; use std::fs;
use std::process; use std::process;
use crate::transpiler::MistConfig;
#[derive(Debug)] #[derive(Debug)]
pub class Module { pub class Module {
pub name String; pub name String;
pub path PathBuf; pub path PathBuf;
pub children Vec<Box<Module>>; pub children Vec<Box<Module>>;
pub constructor(mist_path PathBuf) { pub constructor(mist_path PathBuf, config *MistConfig) {
self.children = Vec::new(); self.children = Vec::new();
self.name = mist_path.file_stem() self.name = mist_path.file_stem()
.and_then(fn(s) -> s.to_str()) .and_then(fn(s) -> s.to_str())
@@ -25,11 +27,15 @@ pub class Module {
self.path = pkg_gate; self.path = pkg_gate;
} }
self.scan_directory(&dir); self.scan_directory(&dir, config);
} else if (config.is_package(&self.path)) {
let dir = self.path.parent().expect("Failed to get parent directory to scan").to_path_buf();
self.scan_directory(&dir, config);
} }
} }
fn scan_directory(*mut self, search_dir *Path) { fn scan_directory(*mut self, search_dir *Path, config *MistConfig) {
let entries = match (fs::read_dir(search_dir)) { let entries = match (fs::read_dir(search_dir)) {
Ok[entries] => entries; Ok[entries] => entries;
Err[e] => { Err[e] => {
@@ -49,11 +55,11 @@ pub class Module {
let child_path = entry.path(); let child_path = entry.path();
if (child_path == self.path) { if (child_path == self.path || child_path == config.packages[0]) {
continue; continue;
} }
self.children.push(Module::new(child_path)); self.children.push(Module::new(child_path, config));
} }
} }
@@ -73,14 +79,3 @@ pub class Module {
} }
} }
} }
pub fn master_package(mist_path PathBuf) Box<Module> {
let mut root_mod = Module::new(mist_path.clone());
let parent_dir = mist_path.parent()
.expect("Failed to get parent directory of root file");
root_mod.scan_directory(parent_dir);
root_mod
}
+7 -4
View File
@@ -13,7 +13,7 @@ use serde::Deserialize;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct MistConfig { pub struct MistConfig {
packages Vec<PathBuf>, pub packages Vec<PathBuf>,
} }
impl MistConfig { impl MistConfig {
pub fn is_package(*self, path *Path) bool { pub fn is_package(*self, path *Path) bool {
@@ -46,10 +46,11 @@ pub fn transpile() PathBuf {
*pkg = src.join(&*pkg); *pkg = src.join(&*pkg);
} }
let master = modules::master_package( let master = modules::Module::new(
config.packages.get(0) config.packages.get(0)
.unwrap_or_else(fn() -> panic!("Mist.toml packages must contain at least one element, eg, 'src/main.mist'")) .unwrap_or_else(fn() -> panic!("Mist.toml packages must contain at least one element, eg, 'src/main.mist'"))
.to_path_buf() .to_path_buf(),
&config
); );
master.transpile(&out, &config); master.transpile(&out, &config);
@@ -84,7 +85,9 @@ impl modules::Module {
let mut output = String::new(); let mut output = String::new();
for (child : &self.children) { for (child : &self.children) {
output.push_str(&child.transpile(&dir, config)); if (!config.is_package(&child.path)) {
output.push_str(&child.transpile(&dir, config));
}
} }
if (self.path.is_dir()) { if (self.path.is_dir()) {