Created
March 4, 2010 14:54
-
-
Save meeech/321761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
/** | |
* YUI Compress CLI Util | |
* | |
* usage: (assuming the script is in your path, executable, and you are in the root directory of the files.) | |
* | |
* yuicompress.php javascript.js rollover.js links.js tabber/tabber-minimized.js utility_effects.js | |
* | |
* or | |
* | |
* yuicompress.php foo.css bar.css zee/alpha.css | |
* | |
* Infers CSS or JS based on file type passed in (the first one in list) | |
* | |
* @author Mitchell Amihod | |
*/ | |
array_shift($argv);//Drop first arg | |
$files = $argv;//assume rest is files list | |
$yuiCompressor = '/Users/mitch/Sites/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar'; | |
if(empty($files)) { | |
die( 'No files passed in.'); | |
} | |
//Infer from first file type, since no mixin and matching | |
$mode = (strpos($files[0], '.js') > -1 ) ? 'js' : 'css' ; | |
$currentdir = getcwd(); | |
$collector = array(); | |
foreach ($files as $fileName) { | |
$filepath = $currentdir . '/' . $fileName; | |
if(!file_exists($filepath)) { | |
echo $filepath." no exist \n"; | |
continue; | |
} | |
echo "adding $filepath\n"; | |
$collector[] = file_get_contents($filepath); | |
} | |
$tempconcat = $currentdir . '/yuitocompresstemp.'.$mode; | |
$fliesListComment = "/*!\n" . implode(',', $files) . "\n*/\n" ; | |
file_put_contents($tempconcat, $fliesListComment . implode("\n\r", $collector)); | |
$outfile = $currentdir . '/yui-compressed.'.$mode; | |
$command = 'java -jar %3$s --type js --preserve-semi -o %1$s %2$s'; | |
if('css' == $mode) { | |
$command = 'java -jar %3$s --type css --line-break 0 -o %1$s %2$s'; | |
} | |
exec(sprintf($command, $outfile, $tempconcat, $yuiCompressor)); | |
//Clean up | |
unlink($tempconcat); | |
echo "\n{$outfile} is ready.\n\r"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment