Created
December 26, 2011 14:24
-
-
Save volkan/1521248 to your computer and use it in GitHub Desktop.
Verilen js,css dosyalarını tek bir dosyaya dönüştürüp sonra bunları sıkıştırmaya yarar. Bu iş için YUI Compressor kullanır.
This file contains hidden or 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
<?php | |
/** | |
* Kullanımı: php53 compress.php -f abc.js,jsonrpc.js -o all.js | |
* Çıktı olarak all-min.js veya all-min.css isimli bir dosya çıkaracaktır. | |
* Gereksinim: pear install Console_CommandLine | |
*/ | |
/** | |
* YUI compress path | |
*/ | |
$yuic = 'java -jar ~/Development/Tools/yuicompressor-2.4.7/build/yuicompressor-2.4.7.jar '; | |
require_once 'Console/CommandLine.php'; | |
$parser = new Console_CommandLine(); | |
$parser->description = 'Yüm dosysları teke indirip YUI Compress ile sıkıştırma.'; | |
$parser->version = '1.5.0'; | |
$parser->addOption('filelist', array( | |
'short_name' => '-f', | |
'long_name' => '--file', | |
'description' => 'Dosysların listesi "," ile ayrılırak yazılmalı. 1.js,2.js', | |
'help_name' => 'FILE', | |
'action' => 'StoreString' | |
)); | |
$parser->addOption('outputname', array( | |
'short_name' => '-o', | |
'long_name' => '--output', | |
'description' => "Yeni dosya adı", | |
'action' => 'StoreString' | |
)); | |
try { | |
$result = $parser->parse(); | |
$outN = $result->options['outputname']; | |
$path_parts = pathinfo($outN); | |
$extension = $path_parts['extension']; | |
$fileName = $path_parts['filename']; | |
fileAppend($result->options['filelist'], $outN); | |
shell_exec($yuic . $outN .' -o '. $fileName .'-min.'.$extension); | |
} catch (Exception $exc) { | |
$parser->displayError($exc->getMessage()); | |
} | |
function fileAppend($files,$outputFile) | |
{ | |
$current = ''; | |
//$outputFile = 'all.js'; | |
//$files = 'abc.js,jsonrpc.js'; | |
$args = explode(',',$files); | |
foreach($args as $key => $file){ | |
try { | |
$current = file_get_contents($file); | |
$current .= PHP_EOL; | |
if ($key>0){ | |
$flag = FILE_APPEND; | |
} else { | |
$flag = null; | |
} | |
file_put_contents($outputFile, $current, $flag); | |
} catch (Exception $e){ | |
echo $e . PHP_EOL; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment