From: <ken...@us...> - 2008-08-20 16:34:45
|
Revision: 563 http://andro.svn.sourceforge.net/andro/?rev=563&view=rev Author: kendowns Date: 2008-08-20 16:34:52 +0000 (Wed, 20 Aug 2008) Log Message: ----------- MINIFICATION IN BUILD: Currently the system *copies* a JS file straight over to a new name, "androLib.js.mjs", but does not minify it. This turns out to be actually very fast. Modified Paths: -------------- trunk/andro/application/androBuild.php Modified: trunk/andro/application/androBuild.php =================================================================== --- trunk/andro/application/androBuild.php 2008-08-20 14:46:28 UTC (rev 562) +++ trunk/andro/application/androBuild.php 2008-08-20 16:34:52 UTC (rev 563) @@ -81,8 +81,10 @@ $retval = $retval && $this->LogStart(); $retval = $retval && $this->DB_Connect(); $retval = $retval && $this->FS_Prepare(); + + // If we can read files, minify + $retval = $retval && $this->JSMinify(); - // If we passed most basic, we prepare the database // by loading stored procedures and making the zdd // schema to use during build. @@ -134,6 +136,7 @@ // build scripts may alter configs, so write them out last $retval = $retval && $this->CodeGenerate_config(); + $this->DB_Close(); $this->LogClose($retval,$ts); $GLOBALS['retval']=$retval; @@ -8779,6 +8782,72 @@ } // ========================================================== +// Pre-minify JS Routines +// ========================================================== +function jsMinify() { + $this->logStage("Minifying JS Files in clib"); + + require 'jsmin-1.1.0.php'; + require 'class.JavaScriptPacker.php'; + + #$dirTop = $GLOBALS['parm']['DIR_PUB'].$GLOBALS['parm']['DIR_PUBLIC_APP']; + $dirTop = $GLOBALS['parm']['DIR_PUB']; + $dirCLib= $dirTop.'clib/'; + $dirALib= $dirTop.'appclib/'; + + $this->jsMinifyDir($dirCLib); + $this->jsMinifyDir($dirALib); +} + +function jsMinifyDir($dir) { + $this->logEntry("Examining ".$dir); + $files = scandir($dir); + foreach($files as $file) { + if(substr($file,-3)<>'.js') continue; + $this->logEntry("Examining File: "); + $this->logEntry(" ".$dir.$file); + + $md5 = md5(file_get_contents($dir.$file)); + $fMarker = $dir.$file.".$md5.mjs"; + $fMin = $dir.$file.".mjs"; + if(file_exists($fMarker) && file_exists($fMin)) { + $this->logEntry(' -- Minified File and Marker exist, no action'); + } + else { + $this->logEntry(" -- Will create marker:"); + $this->logEntry(" ".$fMarker); + + # Remove all markers + foreach($files as $filedel) { + if(substr($filedel,0,strlen($file))==$file) { + if(substr($filedel,-4)=='.mjs') { + $this->logEntry(" -- Removing previous marker: "); + $this->logEntry(" ".$dir.$filedel); + unlink($dir.$filedel); + } + } + } + # Create the new marker + file_put_contents($fMarker,'marker'); + + + $this->logEntry(" -- Will create file "); + $this->logEntry(" ".$dir.$fMin); + + # Now minify the file + $script = file_get_contents($dir.$file); + #$packer = new JavaScriptPacker($script, 'Normal', true, false); + #$packed = $packer->pack(); + #$packed.=JSMin::minify($script); + #file_put_contents($fMin, $packed); + copy($dir.$file,$fMin); + + } + } +} + + +// ========================================================== // Database Access Routines // ========================================================== function SQLRead($sqlText,$noReport=false) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |