From b288ef7dc7ff57c4c162f129a57cff023a56b40b Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Tue, 12 Jan 2016 14:45:28 +0800 Subject: [PATCH] JsCompile.php --- JsCompile.php | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/JsCompile.php b/JsCompile.php index ab10786b..7e9f8e3e 100644 --- a/JsCompile.php +++ b/JsCompile.php @@ -252,10 +252,90 @@ class Pman_Core_JsCompile extends Pman * @param {String} $output name fo file to output * */ + function pack($files, $output, $translation_base=false) { + $o = HTML_FlexyFramework::get()->Pman_Core; + + + require_once 'System.php'; + $packer = System::which('roojspacker'); + + + if (!$packer) { + echo ''; + return false; + + } + $targetm = file_exists($output) && filesize($output) ? filemtime($output) : 0; + $max = 0; + $ofiles = array(); + foreach($files as $f => $mt) { + $max = max($max,$mt); + $ofiles[] = escapeshellarg($f); + } + if ($max < $targetm) { + echo ''; + return true; + } + //var_dump($output); + if (!file_exists(dirname($output))) { + mkdir(dirname($output), 0755, true); + } + $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;'); + usort($ofiles, $lsort); + + //$eoutput = " -k -o " . escapeshellarg($output) ; // with whitespace.. + $eoutput = " -o " . escapeshellarg($output) ; + + if ( $translation_base) { + $toutput = " -t ". escapeshellarg(preg_replace('/\.js$/', '.__translation__.js', $output)) . + " -p " . escapeshellarg($translation_base) ;//." -k "; // this kills the compression. + + } + + + $cmd = ($seed ? + "$seed {$o['jspacker']}/pack.js " : + "$gjs -I {$o['jspacker']} -I {$o['jspacker']}/JSDOC {$o['jspacker']}/pack.js -- -- " + + ) . " $eoutput $toutput " . implode($ofiles, ' ') . ' 2>&1'; + //echo "
$cmd\n";
+        //echo `$cmd`;
+        
+         echo "";
+            
+       // return false;
+        
+        $res = `$cmd`;
+        //exit;
+        file_put_contents($output.'.log', $cmd."\n\n". $res);
+        // since this only appears when we change.. it's ok to dump it out..
+        echo "";
+            
+        // we should do more checking.. return val etc..
+        if (file_exists($output) && ($max < filemtime($output) ) ) {
+            
+            return true;
+        }
+        echo "";
+        return false;
+        
+    }
+    
+    // depricated verison using seed.
+    function packSeed($files, $output, $translation_base=false)
+    {
+        
+         
         $o = HTML_FlexyFramework::get()->Pman_Core;
         
         if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
-- 
2.39.2