mirror of
https://github.com/mrclay/minify.git
synced 2025-08-18 11:51:27 +02:00
Added test-run option in place of verbose
This commit is contained in:
@@ -9,54 +9,62 @@ set_include_path($pathToLib . PATH_SEPARATOR . get_include_path());
|
|||||||
// barebones autoloader
|
// barebones autoloader
|
||||||
spl_autoload_register(function ($class) use ($pathToLib) {
|
spl_autoload_register(function ($class) use ($pathToLib) {
|
||||||
$file = $pathToLib . '/' . str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class) . '.php';
|
$file = $pathToLib . '/' . str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class) . '.php';
|
||||||
if (is_file($file)) {
|
return is_file($file) ? ((require $file) || true) : false;
|
||||||
require $file;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$cli = new MrClay\Cli;
|
$cli = new MrClay\Cli;
|
||||||
|
|
||||||
$cli->addRequiredArg('d')->assertDir()->setDescription('Path of your webserver\'s DOCUMENT_ROOT. Relative paths will be rewritten relative to this path.');
|
$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('o')->useAsOutfile()->setDescription('Outfile: If given, output will be placed in this file.');
|
||||||
|
|
||||||
$cli->addOptionalArg('v')->setDescription('Verbose: show rewriting algorithm. This is ignored if you don\'t use an outfile.');
|
$cli->addOptionalArg('t')->setDescription('Test run: Return output followed by rewriting algorithm.');
|
||||||
|
|
||||||
if (! $cli->validate()) {
|
if (! $cli->validate()) {
|
||||||
echo "USAGE: ./rewrite-uris.php -d DOC_ROOT [-o OUTFILE [-v]] file ...\n";
|
echo "USAGE: ./rewrite-uris.php [-t] -d DOC_ROOT [-o OUTFILE] file ...\n";
|
||||||
if ($cli->isHelpRequest) {
|
if ($cli->isHelpRequest) {
|
||||||
echo $cli->getArgumentsListing();
|
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
|
echo "EXAMPLE: ./rewrite-uris.php -t -d../.. ../../min_unit_tests/_test_files/css/paths_rewrite.css ../../min_unit_tests/_test_files/css/comments.css
|
||||||
\n";
|
\n";
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$outfile = $cli->values['o'];
|
$outfile = $cli->values['o'];
|
||||||
$verbose = $cli->values['v'];
|
$testRun = $cli->values['t'];
|
||||||
$docRoot = $cli->values['d'];
|
$docRoot = $cli->values['d'];
|
||||||
|
|
||||||
$pathRewriter = function($css, $options) {
|
$pathRewriter = function($css, $options) {
|
||||||
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $options['docRoot']);
|
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $options['docRoot']);
|
||||||
};
|
};
|
||||||
|
|
||||||
$fp = $cli->openOutput();
|
|
||||||
|
|
||||||
$paths = $cli->getPathArgs();
|
$paths = $cli->getPathArgs();
|
||||||
|
var_export($paths);
|
||||||
|
|
||||||
$sources = array();
|
$sources = array();
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
$sources[] = new Minify_Source(array(
|
if (is_file($path)) {
|
||||||
'filepath' => $path,
|
$sources[] = new Minify_Source(array(
|
||||||
'minifier' => $pathRewriter,
|
'filepath' => $path,
|
||||||
'minifyOptions' => array('docRoot' => $docRoot),
|
'minifier' => $pathRewriter,
|
||||||
));
|
'minifyOptions' => array('docRoot' => $docRoot),
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$sources[] = new Minify_Source(array(
|
||||||
|
'id' => $path,
|
||||||
|
'content' => "/* $path not found */\n",
|
||||||
|
'minifier' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fwrite($fp, Minify::combine($sources) . "\n");
|
$combined = Minify::combine($sources) . "\n";
|
||||||
|
|
||||||
if ($outfile && $verbose) {
|
if ($testRun) {
|
||||||
|
echo $combined;
|
||||||
echo Minify_CSS_UriRewriter::$debugText . "\n";
|
echo Minify_CSS_UriRewriter::$debugText . "\n";
|
||||||
|
} else {
|
||||||
|
$fp = $cli->openOutput();
|
||||||
|
fwrite($fp, $combined);
|
||||||
|
$cli->closeOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
$cli->closeOutput();
|
|
||||||
|
Reference in New Issue
Block a user