added minify flag

This commit is contained in:
Logan 2024-09-07 19:35:13 -05:00
parent 54fa2098ea
commit 129d404a29

View file

@ -8,11 +8,14 @@ use std::{
fn main() { fn main() {
let mut src_path = String::from("./src"); let mut src_path = String::from("./src");
let mut dist_path = String::from("./dist"); let mut dist_path = String::from("./dist");
let mut min = false;
for arg in std::env::args() { for arg in std::env::args() {
if let Some(s) = arg.strip_prefix("--path=") { if let Some(s) = arg.strip_prefix("--path=") {
src_path = String::from(s); src_path = String::from(s);
} else if let Some(s) = arg.strip_prefix("--target=") { } else if let Some(s) = arg.strip_prefix("--target=") {
dist_path = String::from(s); 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 dist_path = PathBuf::from(dist_path);
let _ = std::fs::create_dir_all(&dist_path); let _ = std::fs::create_dir_all(&dist_path);
let dist_path = dist_path.canonicalize().unwrap(); let dist_path = dist_path.canonicalize().unwrap();
convert_all(&src_path, &dist_path) convert_all(&src_path, &dist_path, min)
} }
fn opts() -> Options { 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_path = src_path.join(".head");
let head = std::fs::read_to_string(head_path).unwrap_or_default(); let head = std::fs::read_to_string(head_path).unwrap_or_default();
for entry in ignore::Walk::new(src_path) { for entry in ignore::Walk::new(src_path) {
@ -56,9 +59,9 @@ fn convert_all(src_path: &Path, dist_path: &Path) {
.unwrap_or_default(); .unwrap_or_default();
match extension { match extension {
"md" => convert_md(file, src_path, dist_path, &head), "md" => convert_md(file, src_path, dist_path, &head),
"css" => convert_css(file, src_path, dist_path), "css" if minimize => convert_css(file, src_path, dist_path),
"js" => convert_js(file, src_path, dist_path), "js" if minimize => convert_js(file, src_path, dist_path),
"json" => convert_json(file, src_path, dist_path), "json" if minimize => convert_json(file, src_path, dist_path),
_ => copy(file, src_path, dist_path), _ => copy(file, src_path, dist_path),
} }
.unwrap(); .unwrap();