Skip to content

Instantly share code, notes, and snippets.

@volkan
Created December 26, 2011 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volkan/1521248 to your computer and use it in GitHub Desktop.
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.
<?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