#!/usr/bin/php , Qiang Xue * @link http://www.pradosoft.com/ * @copyright Copyright © 2005 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Revision: $ $Date: $ * @package Tools */ /** * The root directory for storing all source js files */ define('SOURCE_DIR',realpath(dirname(__FILE__).'/../../framework/Web/JavaScripts')); /** * The directory for storing compressed js files */ define('TARGET_DIR',realpath(dirname(__FILE__).'/../../framework/Web/JavaScripts/js')); if(SOURCE_DIR===false || TARGET_DIR===false) die('Unable to determine the build path.'); if(!is_writable(TARGET_DIR)) die('Unable to create files under '.TARGET_DIR.'.'); /** * list of js library files to be compressed and built */ $libraries = array( 'prado.js' => array( //base javascript functions 'prototype/prototype.js', 'prototype/base.js', 'extended/base.js', 'prototype/string.js', 'extended/string.js', 'prototype/enumerable.js', 'prototype/array.js', 'prototype/hash.js', 'prototype/range.js', //dom functions 'prototype/dom.js', 'prototype/form.js', 'prototype/event.js', 'extended/event.js', 'prototype/position.js', //element selectors 'prototype/selector.js', //build dom elements with DIV, A, UL, etc functions 'effects/builder.js', 'extended/builder.js', // 'extra/getElementsBySelector.js', // 'extra/behaviour.js', 'extended/date.js', //prado core 'prado/prado.js', 'prado/form.js', 'prado/element.js', //controls 'prado/controls.js', 'ratings/ratings.js' ), //effects 'effects.js' => array( 'effects/effects.js' ), //active controls 'ajax.js' => array( 'prototype/ajax.js', 'prado/ajax.js', 'extra/json.js', 'effects/controls.js', 'effects/dragdrop.js', 'effects/slider.js', 'prado/activecontrols.js' ), //logging 'logger.js' => array( 'extra/logger.js', ), //rico 'rico.js' => array( 'rico/rico.js', 'rico/extension.js' ), //validator 'validator.js' => array( 'prado/validation3.js' //'prado/validators.js' ), //date picker 'datepicker.js' => array( 'datepicker/datepicker.js' ), //color picker 'colorpicker.js' => array( 'rico/colors.js', 'colorpicker/colorpicker.js' ) ); /** * Collect specific libraries to be built from command line */ $requestedLibs=array(); for($i=1;$i<$argc;++$i) $requestedLibs[]=$argv[$i].'.js'; $builds = 0; /** * loop through all target files and build them one by one */ foreach($libraries as $libFile => $sourceFiles) { if(!empty($requestedLibs) && !in_array($libFile,$requestedLibs)) continue; $libFile=TARGET_DIR.'/'.$libFile; echo "\nBuilding $libFile...\n"; $contents=''; foreach($sourceFiles as $sourceFile) { $sourceFile=SOURCE_DIR.'/'.$sourceFile; if(!is_file($sourceFile)) echo "Source file not found: $sourceFile\n"; echo "...adding $sourceFile\n"; $contents.=file_get_contents($sourceFile)."\n\n"; } file_put_contents($libFile,compress_js($contents)); echo "Saving file {$libFile}\n"; $builds++; } if($builds > 0) echo "\nJavascript build complete, {$builds} file(s) compressed."; else echo "No files to build."; //remove comments from javascript files. function compress_js($string) { $string = preg_replace('/\/\/[^\n\r]*[\n\r]/', ' ', $string); $string = preg_replace('/\/\*[^*]*\*+([^\/][^*]*\*+)*\//', ' ', $string); $string = preg_replace('/ |\t|\r/', '', $string); $string = preg_replace('/(\n[ \t]*){2,}/', "\n", $string); return $string; } ?>