Skip to content

Commit

Permalink
convert only if the matcha file has been modified
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygeo committed Dec 2, 2023
1 parent 21e35af commit 0914462
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ fn color_choice() -> ColorChoice {
}
}

fn requires_update(matcha_path: &std::path::Path) -> bool {
let matcha_meta = std::fs::metadata(matcha_path).unwrap();
let matcha_time = matcha_meta.modified().unwrap();

let gleam_path = matcha_path.with_extension("gleam");
let gleam_meta = std::fs::metadata(gleam_path).unwrap();
let gleam_time = gleam_meta.modified().unwrap();

if let Ok(_duration) = matcha_time.duration_since(gleam_time) {
true
} else {
false
}
}

#[derive(Debug, StructOpt)]
#[structopt(name = "matcha", about = "Compiles templates into Gleam modules")]
struct Opt {
Expand Down Expand Up @@ -86,10 +101,17 @@ fn main() {
let path = entry.path();

if path.extension() == Some(std::ffi::OsStr::new("matcha")) {
if opt.verbose {
println!("Converting {}", path.display());
if requires_update(path) {
if opt.verbose {
println!("Converting {}", path.display());
}
Some(convert(NAME, path))
} else {
if opt.verbose {
println!("Skipping {}, not modified", path.display());
}
None
}
Some(convert(NAME, path))
} else {
None
}
Expand Down

0 comments on commit 0914462

Please sign in to comment.