| 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 |
|