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 * @param {String} basedir absolute path to files
71 * @param {Array} list of files (ontop of basedir)
78 function packScript($basedir, $files, $output_url)
80 // this outputs <script tags..>
81 // either for just the original files,
82 // or the compressed version.
83 // first expand files..
87 foreach($files as $f) {
88 if (!file_exists($basedir .'/' .$f)) {
91 if (!is_dir($basedir .'/' .$f)) {
93 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
97 foreach(glob($basedir .'/' .$f.'/*.js') as $fx) {
98 $arfiles[$fx] = filemtime($fx);
99 $ofiles [] = $f . '/'. basename($fx);
103 $output = md5(serialize($arfiles)) .'.js';
105 if (!file_exists($output_path.'/_cache_/'.$output)) {
106 $this->pack($arfiles,$output_path.'/_cache_/'.$output);
109 if (file_exists($output_path.'/_cache_/'.$output)) {
111 echo '<script type="text/javascript" src="'.$output_url.'/_cache_/'. $output.'"></script>';
114 foreach($ofiles as $f) {
115 echo '<script type="text/javascript" src="'.$output_url.'/'.$f.'"></script>';
121 function packCss($basedir, $files, $output_path, $output_url)
123 // this outputs <script tags..>
124 // either for just the original files,
125 // or the compressed version.
126 // first expand files..
131 foreach($files as $f) {
132 if (!file_exists($basedir .'/' .$f)) {
135 if (!is_dir($basedir .'/' .$f)) {
136 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
140 foreach(glob($basedir .'/' .$f.'/*.css') as $fx) {
141 $arfiles[$fx] = filemtime($fx);
142 $ofiles [] = $f . '/'. basename($fx);
146 $output = md5(serialize($arfiles)) .'.css';
148 if (!file_exists($output_path.'/_cache_/'.$output)) {
149 $this->packCssCore($arfiles,$output_path.'/_cache_/'.$output);
151 //var_dump()$output_path. '/_cache_/'.$output);
152 if (file_exists($output_path. '/_cache_/'.$output)) {
153 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url. '/_cache_/'. $output.'" />';
156 foreach($ofiles as $f ) {
157 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url.'/'.$f.'" />'."\n";
164 * wrapper arroudn packer...
165 * @param {Array} map of $files => filemtime the files to pack
166 * @param {String} $output name fo file to output
169 function packCssCore($files, $output)
173 $o = HTML_FlexyFramework::get()->Pman_Core;
175 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
176 echo '<!-- jspacker not set -->';
179 require_once 'System.php';
180 $seed= System::which('seed');
182 echo '<!-- seed not installed -->';
186 $targetm = file_exists($output) ? filemtime($output) : 0;
189 foreach($files as $f => $mt) {
190 $max = max($max,$mt);
191 $ofiles[] = escapeshellarg($f);
193 if ($max < $targetm) {
196 if (!file_exists(dirname($output))) {
197 mkdir(dirname($output), 0755, true);
199 $eoutput = escapeshellarg($output);
200 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
201 //echo "<PRE>$cmd\n"; echo `$cmd`; exit;
205 // we should do more checking.. return val etc..
206 if (file_exists($output) && ($max < filemtime($output) ) ) {
213 * wrapper arroudn packer...
214 * @param {Array} map of $files => filemtime the files to pack
215 * @param {String} $output name fo file to output
218 function pack($files, $output)
222 $o = HTML_FlexyFramework::get()->Pman_Core;
224 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
225 echo '<!-- jspacker not set -->';
229 require_once 'System.php';
230 $seed= System::which('seed');
232 echo '<!-- seed not installed -->';
236 $targetm = file_exists($output) ? filemtime($output) : 0;
239 foreach($files as $f => $mt) {
240 $max = max($max,$mt);
241 $ofiles[] = escapeshellarg($f);
243 if ($max < $targetm) {
247 if (!file_exists(dirname($output))) {
248 mkdir(dirname($output), 0755, true);
251 $eoutput = escapeshellarg($output);
252 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
253 //echo "<PRE>$cmd\n";
258 // we should do more checking.. return val etc..
259 if (file_exists($output) && ($max < filemtime($output) ) ) {
270 * @param {String} $proj name of Pman component to build
271 * runs pack.js -m {proj} -a $src/*.js
276 function build($proj)
278 echo "Building $proj\n";
281 $this->err = "no project";
282 if ($this->cli) echo $this->err;
285 // first item in path is always the app start directory..
286 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
290 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
293 require_once 'System.php';
294 $seed= System::which('seed');
296 $this->err ="no seed installed";
297 if ($this->cli) echo $this->err;
301 $o = HTML_FlexyFramework::get()->Pman_Core;
303 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
304 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
305 introspection documentation directory where pack.js is located.";
306 if ($this->cli) echo $this->err;
310 // should we be more specirfic!??!?!?
312 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
315 // technically we should trash old compiled files..
316 // or we move towards a 'cache in session directory model..'
321 $ret = $tmp . '/'. $proj . '.js';
323 echo "BUILT: $ret \n";
330 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
332 function install($proj)
335 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
339 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
340 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
342 echo "SKIP : no js file $proj\n";
345 if (!file_exists("$base/_compiled_")) {
346 mkdir ("$base/_compiled_", 0755, true);
348 $target = "$base/_compiled_/".$proj .'.js';
349 print_R(array($src,$target));
350 if (file_exists($target)) {
351 return; // already installed.
354 symlink($src, $target);
359 function gatherProjects() {
360 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
363 foreach(scandir($src) as $f) {
364 if (!strlen($f) || $f[0] == '.') {
372 if ($f == 'templates') {