diff --git a/src/main.rs b/src/main.rs index ff7984f..2a67a7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,11 +8,14 @@ use std::{ fn main() { let mut src_path = String::from("./src"); let mut dist_path = String::from("./dist"); + let mut min = false; for arg in std::env::args() { if let Some(s) = arg.strip_prefix("--path=") { src_path = String::from(s); } else if let Some(s) = arg.strip_prefix("--target=") { dist_path = String::from(s); + } else if arg == "-min" { + min = true; } } @@ -21,7 +24,7 @@ fn main() { let dist_path = PathBuf::from(dist_path); let _ = std::fs::create_dir_all(&dist_path); let dist_path = dist_path.canonicalize().unwrap(); - convert_all(&src_path, &dist_path) + convert_all(&src_path, &dist_path, min) } fn opts() -> Options { @@ -37,7 +40,7 @@ fn opts() -> Options { } } -fn convert_all(src_path: &Path, dist_path: &Path) { +fn convert_all(src_path: &Path, dist_path: &Path, minimize: bool) { let head_path = src_path.join(".head"); let head = std::fs::read_to_string(head_path).unwrap_or_default(); for entry in ignore::Walk::new(src_path) { @@ -56,9 +59,9 @@ fn convert_all(src_path: &Path, dist_path: &Path) { .unwrap_or_default(); match extension { "md" => convert_md(file, src_path, dist_path, &head), - "css" => convert_css(file, src_path, dist_path), - "js" => convert_js(file, src_path, dist_path), - "json" => convert_json(file, src_path, dist_path), + "css" if minimize => convert_css(file, src_path, dist_path), + "js" if minimize => convert_js(file, src_path, dist_path), + "json" if minimize => convert_json(file, src_path, dist_path), _ => copy(file, src_path, dist_path), } .unwrap();