PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / mrclay / minify / min_extras / cli / minify.php

minify.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/mrclay/minify/min_extras/cli/minify.php

82 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 #!/usr/bin/env php
2 <?php
3
4 die('Must be rewritten for new API');
5
6 require __DIR__ . '/../../bootstrap.php';
7
8 $cli = new MrClay\Cli;
9
10 $cli->addOptionalArg('d')->assertDir()->setDescription('Your webserver\'s DOCUMENT_ROOT: Relative paths will be rewritten relative to this path. This is required if you\'re passing in CSS.');
11
12 $cli->addOptionalArg('o')->useAsOutfile()->setDescription('Outfile: If given, output will be placed in this file.');
13
14 $cli->addOptionalArg('t')->mustHaveValue()->setDescription('Type: must be "css", "js", or "html". This must be provided if passing content via STDIN.');
15
16 if (! $cli->validate()) {
17 if ($cli->isHelpRequest) {
18 echo "The Minify CLI tool!\n\n";
19 }
20 echo "USAGE: ./minify.php [-t TYPE] [-d DOC_ROOT] [-o OUTFILE] file ...\n";
21 if ($cli->isHelpRequest) {
22 echo $cli->getArgumentsListing();
23 }
24 echo "EXAMPLE: ./minify.php ../../tests/_test_files/js/*.js\n";
25 echo "EXAMPLE: ./minify.php -d../.. ../../tests/_test_files/css/*.css\n";
26 echo "EXAMPLE: echo \"var js = 'Awesome' && /cool/;\" | ./minify.php -t js\n";
27 echo "EXAMPLE: echo \"sel > ector { prop: 'value '; }\" | ./minify.php -t css\n";
28 echo "\n";
29 exit(0);
30 }
31
32 $outfile = $cli->values['o'];
33 $docRoot = $cli->values['d'];
34 $type = $cli->values['t'];
35
36 if (is_string($type)) {
37 if (! in_array($type, array('js', 'css', 'html'))) {
38 echo "Type argument invalid\n";
39 exit(1);
40 }
41 $type = constant('Minify::TYPE_' . strtoupper($type));
42 }
43
44 $paths = $cli->getPathArgs();
45 $sources = array();
46
47 if ($paths) {
48 foreach ($paths as $path) {
49 if (is_file($path)) {
50 $sources[] = new Minify_Source(array(
51 'filepath' => $path,
52 'minifyOptions' => array('docRoot' => $docRoot),
53 ));
54 } else {
55 $sources[] = new Minify_Source(array(
56 'id' => $path,
57 'content' => "/*** $path not found ***/\n",
58 'minifier' => 'Minify::nullMinifier',
59 ));
60 }
61 }
62 } else {
63 // not paths input, expect STDIN
64 if (! $type) {
65 echo "Type must be specified to use STDIN\n";
66 exit(1);
67 }
68 $in = $cli->openInput();
69 $sources[] = new Minify_Source(array(
70 'id' => 'one',
71 'content' => stream_get_contents($in),
72 'contentType' => $type,
73 ));
74 $cli->closeInput();
75 }
76
77 $combined = Minify::combine($sources) . "\n";
78
79 $fp = $cli->openOutput();
80 fwrite($fp, $combined);
81 $cli->closeOutput();
82