4 * wrapper code around js builder...
6 * -- we will use this later to compile on the fly...
10 * $x = new Pman_Core_JsCompile();
11 * $x->pack('/path/to/files/', 'destination')
14 require_once 'Pman.php';
17 class Pman_Core_JsCompile extends Pman
22 // command line only ATM
23 $this->cli = HTML_FlexyFramework::get()->cli;
24 // var_dump($this->cli);
32 function get($proj, $args)
35 die("missing action : eg. build or install");
38 if (empty($args[1])) {
40 $ar = $this->gatherProjects();
41 echo "SELECT Component to build\n";
45 $ar = array($args[1]);
58 case 'install' : // needed for install on remote sites..
70 function packScript($basedir, $files, $output_path, $output_url)
72 // this outputs <script tags..>
73 // either for just the original files,
74 // or the compressed version.
75 // first expand files..
79 foreach($files as $f) {
80 if (!is_dir($basedir .'/' .$f)) {
81 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
85 foreach(glob($basedir .'/' .$f.'/*.js') as $fx) {
86 $arfiles[$fx] = filemtime($fx);
87 $ofiles [] = $f . '/'. basename($fx);
91 $output = md5(serialize($arfiles)) .'.js';
93 if (!file_exists($output_path.'/_cache_/'.$output)) {
94 $this->pack($arfiles,$output_path.'/_cache_/'.$output);
97 if (file_exists($output_path.'/'.$output)) {
99 echo '<script type="text/javascript" src="'.$output_url.'/_cache_/'. $output.'"></script>';
102 foreach($ofiles as $f) {
103 echo '<script type="text/javascript" src="'.$output_url.'/'.$f.'"></script>';
109 function packCss($basedir, $files, $output_path, $output_url)
111 // this outputs <script tags..>
112 // either for just the original files,
113 // or the compressed version.
114 // first expand files..
118 foreach($files as $f) {
119 if (!is_dir($basedir .'/' .$f)) {
120 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
124 foreach(glob($basedir .'/' .$f.'/*.css') as $fx) {
125 $arfiles[$fx] = filemtime($fx);
126 $ofiles [] = $f . '/'. basename($fx);
130 $output = md5(serialize($arfiles)) .'.css';
132 if (!file_exists($output_path.'/_cache_/'.$output)) {
133 $this->packCssCore($arfiles,$output_path.'/_cache_/'.$output);
136 if (file_exists($output_path.'/'.$output)) {
137 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url. '/_cache_/'. $output.'" />';
140 foreach($ofiles as $f=>$t) {
141 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url.'/'.$f.'" />'."\n";
148 * wrapper arroudn packer...
149 * @param {Array} map of $files => filemtime the files to pack
150 * @param {String} $output name fo file to output
153 function packCssCore($files, $output)
157 $o = HTML_FlexyFramework::get()->Pman_Core;
159 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
160 echo '<!-- jspacker not set -->';
163 require_once 'System.php';
164 $seed= System::which('seed');
166 echo '<!-- seed not installed -->';
170 $targetm = file_exists($output) ? filemtime($output) : 0;
173 foreach($files as $f => $mt) {
174 $max = max($max,$mt);
175 $ofiles[] = escapeshellarg($f);
177 if ($max < $targetm) {
180 if (!file_exists(dirname($output))) {
181 mkdir(dirname($output), 0755, true);
183 $eoutput = escapeshellarg($output);
184 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
185 //echo "<PRE>$cmd\n";
190 // we should do more checking.. return val etc..
191 if (file_exists($output) && ($max < filemtime($output) ) ) {
198 * wrapper arroudn packer...
199 * @param {Array} map of $files => filemtime the files to pack
200 * @param {String} $output name fo file to output
203 function pack($files, $output)
207 $o = HTML_FlexyFramework::get()->Pman_Core;
209 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
210 echo '<!-- jspacker not set -->';
214 require_once 'System.php';
215 $seed= System::which('seed');
217 echo '<!-- seed not installed -->';
221 $targetm = file_exists($output) ? filemtime($output) : 0;
224 foreach($files as $f => $mt) {
225 $max = max($max,$mt);
226 $ofiles[] = escapeshellarg($f);
228 if ($max < $targetm) {
232 if (!file_exists(dirname($output))) {
233 mkdir(dirname($output), 0755, true);
235 $eoutput = escapeshellarg($output);
236 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
237 //echo "<PRE>$cmd\n";
242 // we should do more checking.. return val etc..
243 if (file_exists($output) && ($max < filemtime($output) ) ) {
254 * @param {String} $proj name of Pman component to build
255 * runs pack.js -m {proj} -a $src/*.js
260 function build($proj)
262 echo "Building $proj\n";
265 $this->err = "no project";
266 if ($this->cli) echo $this->err;
269 // first item in path is always the app start directory..
270 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
274 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
277 require_once 'System.php';
278 $seed= System::which('seed');
280 $this->err ="no seed installed";
281 if ($this->cli) echo $this->err;
285 $o = HTML_FlexyFramework::get()->Pman_Core;
287 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
288 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
289 introspection documentation directory where pack.js is located.";
290 if ($this->cli) echo $this->err;
294 // should we be more specirfic!??!?!?
296 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
299 // technically we should trash old compiled files..
300 // or we move towards a 'cache in session directory model..'
305 $ret = $tmp . '/'. $proj . '.js';
307 echo "BUILT: $ret \n";
314 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
316 function install($proj)
319 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
323 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
324 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
326 echo "SKIP : no js file $proj\n";
329 if (!file_exists("$base/_compiled_")) {
330 mkdir ("$base/_compiled_", 0755, true);
332 $target = "$base/_compiled_/".$proj .'.js';
333 print_R(array($src,$target));
334 if (file_exists($target)) {
335 return; // already installed.
338 symlink($src, $target);
343 function gatherProjects() {
344 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
347 foreach(scandir($src) as $f) {
348 if (!strlen($f) || $f[0] == '.') {
356 if ($f == 'templates') {