2011-07-21 14:18:10 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Combine.php
|
|
|
|
*
|
|
|
|
* This script combines modules into one continuous source file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//The name of the source folder
|
|
|
|
$folder = "src";
|
2011-10-24 19:18:22 -04:00
|
|
|
$src_folder = "{$folder}/modules";
|
2011-07-21 14:18:10 -04:00
|
|
|
|
|
|
|
$files = array();
|
|
|
|
|
|
|
|
//Get all the source files
|
2011-10-24 19:18:22 -04:00
|
|
|
if($dir = opendir($src_folder))
|
2011-07-21 14:18:10 -04:00
|
|
|
{
|
|
|
|
while(($file = readdir($dir)) !== FALSE)
|
|
|
|
{
|
|
|
|
//Don't grab . and ..
|
|
|
|
if($file !== "." && $file !== "..")
|
|
|
|
{
|
|
|
|
$files[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir($dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Start with the core
|
2011-11-01 18:56:27 -04:00
|
|
|
$new_file = file_get_contents("{$folder}/core.js") . "\n";
|
2011-07-21 14:18:10 -04:00
|
|
|
|
2011-11-02 12:10:58 -04:00
|
|
|
//Add polyfills
|
|
|
|
$new_file .= "\n// --------------------------------------------------------------------------\n\n";
|
|
|
|
$new_file .= file_get_contents("{$folder}/polyfill.js") . "\n";
|
|
|
|
|
2011-07-21 14:18:10 -04:00
|
|
|
|
|
|
|
//Add the modules
|
2011-10-24 19:18:22 -04:00
|
|
|
foreach($files as $f)
|
2011-07-21 14:18:10 -04:00
|
|
|
{
|
2011-10-24 19:18:22 -04:00
|
|
|
$farray = file($src_folder."/".$f, FILE_IGNORE_NEW_LINES);
|
2011-07-21 14:18:10 -04:00
|
|
|
|
|
|
|
$flen = count($farray);
|
|
|
|
|
|
|
|
$module = implode("\n", $farray);
|
|
|
|
|
2011-10-24 19:18:22 -04:00
|
|
|
$new_file .= "\n// --------------------------------------------------------------------------\n\n".$module."\n";
|
2011-07-21 14:18:10 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Output the full file
|
|
|
|
file_put_contents("kis-custom.js", $new_file);
|
|
|
|
|
2011-08-10 16:30:36 -04:00
|
|
|
//Get a much-minified version from Google's closure compiler
|
2011-12-06 11:47:22 -05:00
|
|
|
$ch = curl_init('http://closure-compiler.appspot.com/compile');
|
2011-08-10 16:30:36 -04:00
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=text&compilation_level=SIMPLE_OPTIMIZATIONS&js_code=' . urlencode($new_file));
|
|
|
|
$output = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
|
2011-12-06 11:47:22 -05:00
|
|
|
file_put_contents("kis-custom-min.js", $output);
|
2011-08-10 16:30:36 -04:00
|
|
|
|
|
|
|
|
2011-07-21 14:18:10 -04:00
|
|
|
//Display the output on-screen too
|
2011-10-24 19:18:22 -04:00
|
|
|
echo '<pre style="-moz-tab-size:4;">'.htmlspecialchars($new_file).'</pre>';
|