예제 #1
0
#!/usr/bin/php
<?php 
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib';
require "{$min_libPath}/Minify/Loader.php";
Minify_Loader::register();
$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    \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' => ''));
    }
예제 #2
0
#!/usr/bin/php
<?php 
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib';
// needed because of dumb require statements in class files :(
set_include_path($pathToLib . PATH_SEPARATOR . get_include_path());
// barebones autoloader
spl_autoload_register(function ($class) use($pathToLib) {
    $file = $pathToLib . '/' . str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class) . '.php';
    return is_file($file) ? (require $file) || true : false;
});
$cli = new MrClay\Cli();
$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.');
$cli->addOptionalArg('o')->useAsOutfile()->setDescription('Outfile: If given, output will be placed in this file.');
$cli->addOptionalArg('t')->mustHaveValue()->setDescription('Type: must be "css", "js", or "html". This must be provided if passing content via STDIN.');
if (!$cli->validate()) {
    if ($cli->isHelpRequest) {
        echo "The Minify CLI tool!\n\n";
    }
    echo "USAGE: ./minify.php [-t TYPE] [-d DOC_ROOT] [-o OUTFILE] file ...\n";
    if ($cli->isHelpRequest) {
        echo $cli->getArgumentsListing();
    }
    echo "EXAMPLE: ./minify.php ../../min_unit_tests/_test_files/js/*.js\n";
    echo "EXAMPLE: ./minify.php -d../.. ../../min_unit_tests/_test_files/css/*.css\n";
    echo "EXAMPLE: echo \"var js = 'Awesome' && /cool/;\" | ./minify.php -t js\n";
    echo "EXAMPLE: echo \"sel > ector { prop: 'value  '; }\" | ./minify.php -t css\n";
    echo "\n";
    exit(0);
}
$outfile = $cli->values['o'];
$docRoot = $cli->values['d'];