Improve CLI; fix Ruby integration

This commit is contained in:
Wilson Lin 2021-01-08 01:58:31 +11:00
parent ae0740d9c4
commit 9b2a348fd4
4 changed files with 15 additions and 5 deletions

View File

@ -31,7 +31,7 @@ Precompiled binaries are available for x86-64 Linux, macOS, and Windows.
Use the `--help` argument for more details.
```bash
minify-html --src /path/to/src.html --out /path/to/output.min.html
minify-html --src /path/to/src.html --out /path/to/output.min.html --css --js
```
### API

View File

@ -1,6 +1,7 @@
[package]
publish = false
name = "minify-html-cli"
description = "Extremely fast and smart HTML + JS + CSS minifier"
version = "0.4.0"
authors = ["Wilson Lin <code@wilsonl.in>"]
edition = "2018"

View File

@ -6,13 +6,18 @@ use structopt::StructOpt;
use minify_html::{Cfg, FriendlyError, with_friendly_error};
#[derive(StructOpt)]
#[structopt(name = "minify-html", about = "Extremely fast and smart HTML + JS + CSS minifier")]
struct Cli {
/// File to minify; omit for stdin.
#[structopt(short, long, parse(from_os_str))]
src: Option<std::path::PathBuf>,
/// Output destination; omit for stdout.
#[structopt(short, long, parse(from_os_str))]
out: Option<std::path::PathBuf>,
/// Enables JS minification.
#[structopt(long)]
js: bool,
/// Enables CSS minification.
#[structopt(long)]
css: bool,
}

View File

@ -15,14 +15,18 @@ methods! {
.to_string()
.into_bytes();
let cfg_hash = cfg_hash
.map_err(|e| VM::raise_ex(e) )
.unwrap();
let cfg = &Cfg {
minify_js: cfg_hash
.map(|h| h.at(&Symbol::new("minify_js")))
.and_then(|e| e.try_convert_to::<Boolean>())
.at(&Symbol::new("minify_js"))
.try_convert_to::<Boolean>()
.map_or(false, |v| v.to_bool()),
minify_css: cfg_hash
.map(|h| h.at(&Symbol::new("minify_css")))
.and_then(|e| e.try_convert_to::<Boolean>())
.at(&Symbol::new("minify_css"))
.try_convert_to::<Boolean>()
.map_or(false, |v| v.to_bool()),
};