-
Notifications
You must be signed in to change notification settings - Fork 0
/
minifier.php
83 lines (63 loc) · 1.69 KB
/
minifier.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
function help() {
echo "Compress a single javascript or stylesheet file or a whole folder.\n";
echo "\n";
echo "Usage:\n";
echo " php minifier.php /public [options]\n";
echo " php minifier.php /stylesheets/common.css [options]\n";
echo "\n";
echo "Options are:\n";
echo str_pad(" -q, --quiet", 26, " ") . "no output\n";
echo str_pad(" -p, --pretend", 26, " ") . "no changes are made\n";
echo str_pad(" -r, --recursive", 26, " ") . "execute the action on all subdirectories\n";
echo str_pad(" -js, --javascripts", 26, " ") . "compress only javascript files\n";
echo str_pad(" -css, --stylesheets", 26, " ") . "compress only stylesheets files\n";
echo str_pad(" -c, --combine", 26, " ") . "combines all files in one\n";
echo str_pad(" -h, --help", 26, " ") . "show this\n";
exit;
}
if ($_SERVER['argc'] == 1)
help();
require_once 'minify.php';
$options = array();
$path = false;
$arguments = array_splice($_SERVER['argv'], 1);
foreach ($arguments as $arg) {
$is_option = preg_match('/^-/', $arg);
if ($is_option && !$path)
help();
switch ($arg) {
case '--combine':
case '-c':
$options[] = 'combine';
break;
case '--quiet':
case '-q':
$options[] = 'quiet';
break;
case '--pretend':
case '-p':
$options[] = 'pretend';
break;
case '--recursive':
case '-r':
$options[] = 'recursive';
break;
case '--javascripts':
case '-js':
if (in_array('stylesheets', $options))
help();
$options[] = 'javascripts';
case '--stylesheets':
case '-css':
if (in_array('javascripts', $options))
help();
$options[] = 'stylesheets';
default:
if ($is_option || $path)
help();
$path = $arg;
}
}
minify::it($path, $options);
?>