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..
78 foreach($files as $f) {
79 if (!is_dir($basedir .'/' .$f)) {
80 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
83 foreach(glob($basedir .'/' .$f.'/*.js') as $fx) {
84 $arfiles[$fx] = filemtime($fx);
88 $output = md5(serialize($arfiles)) .'.js';
90 if (!file_exists($output_path.'/_cached_/'.$output)) {
91 $this->pack($arfiles,$output_path.'/_cached_/'.$output);
94 if (file_exists($output_path.'/'.$output)) {
96 echo '<script type="text/javascript" src="'.$output_url.'/_cached_/'. $output.'"></script>';
99 foreach($files as $f=>$t) {
100 echo '<script type="text/javascript" src="'.$output_url.'/'.$f.'"></script>';
106 function packCss($basedir, $files, $output_path, $output_url)
108 // this outputs <script tags..>
109 // either for just the original files,
110 // or the compressed version.
111 // first expand files..
114 foreach($files as $f) {
115 if (!is_dir($basedir .'/' .$f)) {
116 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
119 foreach(glob($basedir .'/' .$f.'/*.css') as $fx) {
120 $arfiles[$fx] = filemtime($fx);
124 $output = md5(serialize($arfiles)) .'.css';
126 if (!file_exists($output_path.'/_cached_/'.$output)) {
127 $this->packCssCore($arfiles,$output_path.'/_cached_/'.$output);
130 if (file_exists($output_path.'/'.$output)) {
131 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url. '/_cached_/'. $output.'" />';
134 foreach($files as $f=>$t) {
135 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url.'/'.$f.'" />'."\n";
143 * wrapper arroudn packer...
144 * @param {Array} map of $files => filemtime the files to pack
145 * @param {String} $output name fo file to output
148 function packCssCore($files, $output)
152 $o = HTML_FlexyFramework::get()->Pman_Core;
154 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
155 echo '<!-- jspacker not set -->';
158 require_once 'System.php';
159 $seed= System::which('seed');
161 echo '<!-- seed not installed -->';
165 $targetm = file_exists($output) ? filemtime($output) : 0;
168 foreach($files as $f => $mt) {
169 $max = max($max,$mt);
170 $ofiles[] = escapeshellarg($f);
172 if ($max < $targetm) {
175 if (!file_exists(dirname($output))) {
176 mkdir(dirname($output), 0755, true);
178 $eoutput = escapeshellarg($output);
179 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
180 //echo "<PRE>$cmd\n";
185 // we should do more checking.. return val etc..
186 if (file_exists($output) && ($max < filemtime($output) ) ) {
193 * wrapper arroudn packer...
194 * @param {Array} map of $files => filemtime the files to pack
195 * @param {String} $output name fo file to output
198 function pack($files, $output)
202 $o = HTML_FlexyFramework::get()->Pman_Core;
204 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
205 echo '<!-- jspacker not set -->';
209 require_once 'System.php';
210 $seed= System::which('seed');
212 echo '<!-- seed not installed -->';
216 $targetm = file_exists($output) ? filemtime($output) : 0;
219 foreach($files as $f => $mt) {
220 $max = max($max,$mt);
221 $ofiles[] = escapeshellarg($f);
223 if ($max < $targetm) {
227 if (!file_exists(dirname($output))) {
228 mkdir(dirname($output), 0755, true);
230 $eoutput = escapeshellarg($output);
231 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
232 //echo "<PRE>$cmd\n";
237 // we should do more checking.. return val etc..
238 if (file_exists($output) && ($max < filemtime($output) ) ) {
249 * @param {String} $proj name of Pman component to build
250 * runs pack.js -m {proj} -a $src/*.js
255 function build($proj)
257 echo "Building $proj\n";
260 $this->err = "no project";
261 if ($this->cli) echo $this->err;
264 // first item in path is always the app start directory..
265 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
269 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
272 require_once 'System.php';
273 $seed= System::which('seed');
275 $this->err ="no seed installed";
276 if ($this->cli) echo $this->err;
280 $o = HTML_FlexyFramework::get()->Pman_Core;
282 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
283 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
284 introspection documentation directory where pack.js is located.";
285 if ($this->cli) echo $this->err;
289 // should we be more specirfic!??!?!?
291 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
294 // technically we should trash old compiled files..
295 // or we move towards a 'cache in session directory model..'
300 $ret = $tmp . '/'. $proj . '.js';
302 echo "BUILT: $ret \n";
309 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
311 function install($proj)
314 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
318 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
319 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
321 echo "SKIP : no js file $proj\n";
324 if (!file_exists("$base/_compiled_")) {
325 mkdir ("$base/_compiled_", 0755, true);
327 $target = "$base/_compiled_/".$proj .'.js';
328 print_R(array($src,$target));
329 if (file_exists($target)) {
330 return; // already installed.
333 symlink($src, $target);
338 function gatherProjects() {
339 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
342 foreach(scandir($src) as $f) {
343 if (!strlen($f) || $f[0] == '.') {
351 if ($f == 'templates') {