diff --git a/src/transpiler.rs b/src/transpiler.rs index e188fe7..ec282c2 100644 --- a/src/transpiler.rs +++ b/src/transpiler.rs @@ -30,7 +30,10 @@ pub fn build() -> (Config, PathBuf) { let elapsed = start.elapsed(); - println!("\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m", elapsed); + println!( + "\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m", + elapsed + ); (config, root) } @@ -69,13 +72,30 @@ fn build_dir(root: &Path, base_src: &Path, current_dir: &Path, out_dir: &Path) { let relative = path.strip_prefix(base_src).unwrap(); + // Handle non-mist files with a cache check if path.extension().and_then(|e| e.to_str()) != Some("mist") { - fs::copy(&path, out_dir.join(relative)).expect("Failed to copy non-mist file"); + let dest_path = out_dir.join(relative); + + // Create parent directories for static assets if needed + if let Some(parent) = dest_path.parent() { + let _ = fs::create_dir_all(parent); + } + + if should_skip(&path, &dest_path) { + continue; + } + + fs::copy(&path, dest_path).expect("Failed to copy non-mist file"); continue; } let output_path = out_dir.join(relative).with_extension("rs"); + // Cache layer: Skip if the generated .rs file is newer than the .mist source + if should_skip(&path, &output_path) { + continue; + } + // create parent directories if let Some(parent) = output_path.parent() { if let Err(e) = fs::create_dir_all(parent) { @@ -145,6 +165,15 @@ fn build_dir(root: &Path, base_src: &Path, current_dir: &Path, out_dir: &Path) { } } +fn should_skip(source: &Path, output: &Path) -> bool { + if let (Ok(src_meta), Ok(out_meta)) = (fs::metadata(source), fs::metadata(output)) { + if let (Ok(src_time), Ok(out_time)) = (src_meta.modified(), out_meta.modified()) { + return out_time >= src_time; + } + } + false +} + pub fn find_project_root() -> Option { let mut dir = std::env::current_dir().ok()?;