Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mincss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
mincss
Commits
64d75979
Commit
64d75979
authored
Jul 31, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed command-line usage
parent
5fcf5957
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
71 deletions
+92
-71
main.ml
main.ml
+74
-51
util.ml
util.ml
+18
-20
No files found.
main.ml
View file @
64d75979
...
...
@@ -4,10 +4,10 @@ open Types
type
args
=
{
mutable
infiles
:
string
list
;
mutable
outfile
:
string
option
;
mutable
verbose
:
int
;
mutable
echo
:
bool
;
mutable
pretty
:
bool
;
mutable
verbose
:
bool
;
mutable
prune
:
bool
;
mutable
unfold
:
bool
;
mutable
upto
:
int
option
;
}
(* Parse command-line arguments *)
...
...
@@ -15,35 +15,46 @@ let parse_args () =
let
args
=
{
infiles
=
[]
;
outfile
=
None
;
verbose
=
1
;
echo
=
fals
e
;
pretty
=
fals
e
;
u
nfold
=
fals
e
;
verbose
=
false
;
prune
=
tru
e
;
unfold
=
tru
e
;
u
pto
=
Non
e
;
}
in
let
args_spec
=
[
(
"<file> ..."
,
Arg
.
Rest
(
fun
_
->
()
)
,
"
Optional i
nput files (default is to read from stdin)"
);
"
I
nput files (default is to read from stdin)"
);
(
"-o"
,
Arg
.
String
(
fun
s
->
args
.
outfile
<-
Some
s
)
,
"<file> Output file (defaults to stdout)"
);
(
"-v"
,
Arg
.
Int
(
fun
i
->
args
.
verbose
<-
i
)
,
"<num> Set verbosity (0: nothing, 1: errors (default), \
2: compression rate, 3: debug)"
);
(
"--echo"
,
Arg
.
Unit
(
fun
_
->
args
.
echo
<-
true
)
,
" Don't minify, just pretty-print the parsed CSS"
);
(
"--pretty"
,
Arg
.
Unit
(
fun
_
->
args
.
pretty
<-
true
)
,
" Minify, but pretty-print the parsed CSS (for debugging)"
);
(
"--unfold"
,
Arg
.
Unit
(
fun
_
->
args
.
unfold
<-
true
)
,
" Only unfold shorthands (for debugging)"
);
(
"-v"
,
Arg
.
Unit
(
fun
_
->
args
.
verbose
<-
true
)
,
" Verbose mode: show compression rate"
);
(
"-no-prune"
,
Arg
.
Unit
(
fun
_
->
args
.
prune
<-
false
)
,
" Don't prune duplicate properties (skip step 5 below)"
);
(
"-no-unfold"
,
Arg
.
Unit
(
fun
_
->
args
.
unfold
<-
false
)
,
" Only minify whitespace, colors and shorthands \
(skip steps 2-7 below)"
);
(
"-upto"
,
Arg
.
Int
(
fun
i
->
args
.
upto
<-
Some
i
)
,
"<step> Stop after the specified step (for debugging): \
\n
\
1: parse
\n
\
2: unfold shorthands
\n
\
3: unfold selectors
\n
\
4: unfold blocks
\n
\
5: prune duplicates
\n
\
6: combine selectors
\n
\
7: concatenate blocks
\n
\
8: optimize blocks
\n
\
9: minify"
);
]
in
let
usage
=
"Usage: "
^
Sys
.
argv
.
(
0
)
^
" [-o <file>] [-v
<verbosity>] [<file> ...] "
^
"[--pretty | --echo]
"
"Usage: "
^
Sys
.
argv
.
(
0
)
^
" [-o <file>] [-v
] [-no-prune] [-upto <step>] \
[<file> ...]
"
in
Arg
.
parse
args_spec
(
fun
f
->
args
.
infiles
<-
args
.
infiles
@
[
f
])
usage
;
...
...
@@ -65,7 +76,20 @@ let parse_files = function
(
String
.
concat
""
inputs
,
List
.
concat
stylesheets
)
let
handle_args
args
=
let
input
,
stylesheet
=
parse_files
args
.
infiles
in
let
steps
=
(*let switch flag fn = if flag then fn else fun s -> s in*)
[
(*
switch args.unfold Unfold.unfold_shorthands;
switch args.unfold Unfold.unfold_selectors;
switch args.unfold Unfold.unfold_blocks;
switch (args.unfold && args.prune) Unfold.prune_duplicates;
switch args.unfold Combine.combine_selectors;
switch args.unfold Concat.concat_blocks;
Optimize.optimize_blocks;
*)
]
in
let
write_output
=
match
args
.
outfile
with
...
...
@@ -74,42 +98,41 @@ let handle_args args =
fun
css
->
let
f
=
open_out
name
in
output_string
f
css
;
close_out
f
in
match
args
with
|
{
echo
=
true
}
->
write_output
(
Stringify
.
string_of_stylesheet
stylesheet
)
|
{
unfold
=
true
}
->
let
stylesheet
=
Shorthand
.
unfold_stylesheet
stylesheet
in
let
upto
=
match
args
.
upto
with
Some
i
->
i
|
None
->
0
in
let
input
,
stylesheet
=
parse_files
args
.
infiles
in
let
rec
do_steps
i
stylesheet
=
function
|
_
when
i
=
upto
->
write_output
(
Stringify
.
string_of_stylesheet
stylesheet
)
|
_
->
let
stylesheet
=
Color
.
compress
stylesheet
in
let
stylesheet
=
Shorthand
.
compress
stylesheet
in
let
stringify
=
if
args
.
pretty
then
Stringify
.
string_of_stylesheet
else
Stringify
.
minify_stylesheet
in
let
output
=
stringify
stylesheet
in
|
[]
->
let
output
=
Stringify
.
minify_stylesheet
stylesheet
in
write_output
output
;
if
args
.
verbose
>=
2
then
begin
if
args
.
verbose
then
begin
let
il
=
String
.
length
input
in
let
ol
=
String
.
length
output
in
Printf
.
fprintf
stderr
"compression: %d -> %d bytes (%d%% of original)
\n
"
il
ol
(
int_of_float
(
float_of_int
ol
/.
float_of_int
il
*.
100
.
))
end
|
step
::
tl
->
do_steps
(
i
+
1
)
(
step
stylesheet
)
tl
in
do_steps
1
stylesheet
steps
(* Main function, returns exit status *)
let
main
()
=
let
args
=
parse_args
()
in
begin
try
handle_args
args
;
handle_args
(
parse_args
()
)
;
exit
0
with
|
Loc_error
(
loc
,
msg
)
->
Util
.
prerr_loc_msg
(
args
.
verbose
>=
1
)
loc
(
"Error: "
^
msg
);
Util
.
prerr_loc_msg
loc
(
"Error: "
^
msg
);
|
Box_error
(
box
,
msg
)
->
prerr_endline
(
"Error: "
^
msg
^
": "
^
Stringify
.
string_of_box
box
);
|
Failure
msg
->
...
...
util.ml
View file @
64d75979
...
...
@@ -78,8 +78,7 @@ let prerr_loc (fname, ystart, yend, xstart, xend) =
end
done
let
prerr_loc_msg
verbose
loc
msg
=
if
verbose
then
begin
let
prerr_loc_msg
loc
msg
=
let
(
fname
,
ystart
,
yend
,
xstart
,
xend
)
=
loc
in
if
loc
!=
noloc
then
begin
let
line_s
=
if
yend
!=
ystart
...
...
@@ -94,10 +93,9 @@ let prerr_loc_msg verbose loc msg =
end
;
eprintf
"%s
\n
"
msg
;
if
verbose
&&
loc
!=
noloc
then
if
loc
!=
noloc
then
try
prerr_loc
loc
with
Sys_error
_
->
()
end
(** AST traversal *)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment