1
0
mirror of https://github.com/mrclay/minify.git synced 2025-02-23 08:25:12 +01:00
minify/min_extras/cli/rewrite-uris.php
Elan Ruusamäe 0e9e1237c6 make composer dependency required
NOTE: this changes required minimum PHP version to 5.3.3
2014-10-16 00:04:51 +03:00

61 lines
1.8 KiB
PHP
Executable File

#!/usr/bin/php
<?php
require dirname(dirname(__DIR__)) . '/vendor/bootstrap.php';
$cli = new MrClay\Cli;
$cli->addRequiredArg('d')->assertDir()->setDescription('Your webserver\'s DOCUMENT_ROOT: Relative paths will be rewritten relative to this path.');
$cli->addOptionalArg('o')->useAsOutfile()->setDescription('Outfile: If given, output will be placed in this file.');
$cli->addOptionalArg('t')->setDescription('Test run: Return output followed by rewriting algorithm.');
if (! $cli->validate()) {
echo "USAGE: ./rewrite-uris.php [-t] -d DOC_ROOT [-o OUTFILE] file ...\n";
if ($cli->isHelpRequest) {
echo $cli->getArgumentsListing();
}
echo "EXAMPLE: ./rewrite-uris.php -v -d../.. ../../min_unit_tests/_test_files/css/paths_rewrite.css ../../min_unit_tests/_test_files/css/comments.css
\n";
exit(0);
}
$outfile = $cli->values['o'];
$testRun = $cli->values['t'];
$docRoot = $cli->values['d'];
$pathRewriter = function($css, $options) {
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $options['docRoot']);
};
$paths = $cli->getPathArgs();
$sources = array();
foreach ($paths as $path) {
if (is_file($path)) {
$sources[] = new Minify_Source(array(
'filepath' => $path,
'minifier' => $pathRewriter,
'minifyOptions' => array('docRoot' => $docRoot),
));
} else {
$sources[] = new Minify_Source(array(
'id' => $path,
'content' => "/*** $path not found ***/\n",
'minifier' => '',
));
}
}
$combined = Minify::combine($sources) . "\n";
if ($testRun) {
echo $combined;
echo Minify_CSS_UriRewriter::$debugText . "\n";
} else {
$fp = $cli->openOutput();
fwrite($fp, $combined);
$cli->closeOutput();
}