kis-js/combine.php

66 lines
1.6 KiB
PHP
Raw Normal View History

<?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";
$files = array();
//Get all the source files
2011-10-24 19:18:22 -04:00
if($dir = opendir($src_folder))
{
while(($file = readdir($dir)) !== FALSE)
{
//Don't grab . and ..
if($file !== "." && $file !== "..")
{
$files[] = $file;
}
}
closedir($dir);
}
//Start with the core
$new_file = file_get_contents("{$folder}/core.js") . "\n";
2011-11-02 12:10:58 -04:00
//Add polyfills
$new_file .= "\n// --------------------------------------------------------------------------\n\n";
$new_file .= file_get_contents("{$folder}/polyfill.js") . "\n";
//Add the modules
2011-10-24 19:18:22 -04:00
foreach($files as $f)
{
2011-10-24 19:18:22 -04:00
$farray = file($src_folder."/".$f, FILE_IGNORE_NEW_LINES);
$flen = count($farray);
$module = implode("\n", $farray);
2011-10-24 19:18:22 -04:00
$new_file .= "\n// --------------------------------------------------------------------------\n\n".$module."\n";
}
//Output the full file
file_put_contents("kis-custom.js", $new_file);
//Get a much-minified version from Google's closure compiler
/*$ch = curl_init('http://closure-compiler.appspot.com/compile');
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);
file_put_contents("kis-custom-min.js", $output);*/
//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>';