Fix the CLI and log files as they are processed (#90)
* fix: use rayon instead of handwritten thread pool * style: add newline before a new section * fix: bring back single file mode * feat: add log * chore: only print file name
This commit is contained in:
parent
7c97affa9d
commit
9d5d1bb0f3
|
@ -8,9 +8,8 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
minify-html = { path = "../rust/main" }
|
||||
num_cpus = "1.13.1"
|
||||
spmc = "0.3.0"
|
||||
structopt = "0.3"
|
||||
rayon = "1.5"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use std::fs::File;
|
||||
use std::io::{stdin, stdout, Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use minify_html::{minify, Cfg};
|
||||
|
@ -98,12 +97,13 @@ fn main() {
|
|||
remove_processing_instructions: args.remove_processing_instructions,
|
||||
});
|
||||
|
||||
if args.inputs.len() < 1 {
|
||||
if args.inputs.len() <= 1 {
|
||||
// single file mode or stdin mode
|
||||
let input_name = args
|
||||
.inputs
|
||||
.get(0)
|
||||
.map(|p| p.to_string_lossy().into_owned())
|
||||
.unwrap_or("stdin".to_string());
|
||||
.unwrap_or_else(|| "stdin".to_string());
|
||||
let mut src_file: Box<dyn Read> = match args.inputs.get(0) {
|
||||
Some(p) => Box::new(io_expect!(
|
||||
input_name,
|
||||
|
@ -133,13 +133,7 @@ fn main() {
|
|||
"Could not save minified code"
|
||||
);
|
||||
} else {
|
||||
let (mut tx, rx) = spmc::channel::<PathBuf>();
|
||||
let mut handles = Vec::new();
|
||||
for _ in 0..num_cpus::get() {
|
||||
let rx = rx.clone();
|
||||
let cfg = cfg.clone();
|
||||
handles.push(thread::spawn(move || {
|
||||
let input = rx.recv().unwrap();
|
||||
args.inputs.par_iter().for_each(|input| {
|
||||
let input_name = input.to_string_lossy().into_owned();
|
||||
|
||||
let mut src_file =
|
||||
|
@ -161,15 +155,7 @@ fn main() {
|
|||
out_file.write_all(&out_code),
|
||||
"Could not save minified code"
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
for i in args.inputs {
|
||||
tx.send(i).unwrap();
|
||||
}
|
||||
|
||||
for handle in handles {
|
||||
handle.join().unwrap();
|
||||
}
|
||||
println!("{}", input_name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue