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 (!file_exists($basedir .'/' .$f)) {
84 if (!is_dir($basedir .'/' .$f)) {
86 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
90 foreach(glob($basedir .'/' .$f.'/*.js') as $fx) {
91 $arfiles[$fx] = filemtime($fx);
92 $ofiles [] = $f . '/'. basename($fx);
96 $output = md5(serialize($arfiles)) .'.js';
98 if (!file_exists($output_path.'/_cache_/'.$output)) {
99 $this->pack($arfiles,$output_path.'/_cache_/'.$output);
102 if (file_exists($output_path.'/'.$output)) {
104 echo '<script type="text/javascript" src="'.$output_url.'/_cache_/'. $output.'"></script>';
107 foreach($ofiles as $f) {
108 echo '<script type="text/javascript" src="'.$output_url.'/'.$f.'"></script>';
114 function packCss($basedir, $files, $output_path, $output_url)
116 // this outputs <script tags..>
117 // either for just the original files,
118 // or the compressed version.
119 // first expand files..
124 foreach($files as $f) {
125 if (!file_exists(basedir .'/' .$f)) {
128 if (!is_dir($basedir .'/' .$f)) {
129 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
133 foreach(glob($basedir .'/' .$f.'/*.css') as $fx) {
134 $arfiles[$fx] = filemtime($fx);
135 $ofiles [] = $f . '/'. basename($fx);
139 $output = md5(serialize($arfiles)) .'.css';
141 if (!file_exists($output_path.'/_cache_/'.$output)) {
142 $this->packCssCore($arfiles,$output_path.'/_cache_/'.$output);
145 if (file_exists($output_path.'/'.$output)) {
146 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url. '/_cache_/'. $output.'" />';
149 foreach($ofiles as $f ) {
150 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url.'/'.$f.'" />'."\n";
157 * wrapper arroudn packer...
158 * @param {Array} map of $files => filemtime the files to pack
159 * @param {String} $output name fo file to output
162 function packCssCore($files, $output)
166 $o = HTML_FlexyFramework::get()->Pman_Core;
168 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
169 echo '<!-- jspacker not set -->';
172 require_once 'System.php';
173 $seed= System::which('seed');
175 echo '<!-- seed not installed -->';
179 $targetm = file_exists($output) ? filemtime($output) : 0;
182 foreach($files as $f => $mt) {
183 $max = max($max,$mt);
184 $ofiles[] = escapeshellarg($f);
186 if ($max < $targetm) {
189 if (!file_exists(dirname($output))) {
190 mkdir(dirname($output), 0755, true);
192 $eoutput = escapeshellarg($output);
193 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
194 //echo "<PRE>$cmd\n";
199 // we should do more checking.. return val etc..
200 if (file_exists($output) && ($max < filemtime($output) ) ) {
207 * wrapper arroudn packer...
208 * @param {Array} map of $files => filemtime the files to pack
209 * @param {String} $output name fo file to output
212 function pack($files, $output)
216 $o = HTML_FlexyFramework::get()->Pman_Core;
218 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
219 echo '<!-- jspacker not set -->';
223 require_once 'System.php';
224 $seed= System::which('seed');
226 echo '<!-- seed not installed -->';
230 $targetm = file_exists($output) ? filemtime($output) : 0;
233 foreach($files as $f => $mt) {
234 $max = max($max,$mt);
235 $ofiles[] = escapeshellarg($f);
237 if ($max < $targetm) {
241 if (!file_exists(dirname($output))) {
242 mkdir(dirname($output), 0755, true);
244 $eoutput = escapeshellarg($output);
245 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
246 //echo "<PRE>$cmd\n";
251 // we should do more checking.. return val etc..
252 if (file_exists($output) && ($max < filemtime($output) ) ) {
263 * @param {String} $proj name of Pman component to build
264 * runs pack.js -m {proj} -a $src/*.js
269 function build($proj)
271 echo "Building $proj\n";
274 $this->err = "no project";
275 if ($this->cli) echo $this->err;
278 // first item in path is always the app start directory..
279 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
283 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
286 require_once 'System.php';
287 $seed= System::which('seed');
289 $this->err ="no seed installed";
290 if ($this->cli) echo $this->err;
294 $o = HTML_FlexyFramework::get()->Pman_Core;
296 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
297 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
298 introspection documentation directory where pack.js is located.";
299 if ($this->cli) echo $this->err;
303 // should we be more specirfic!??!?!?
305 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
308 // technically we should trash old compiled files..
309 // or we move towards a 'cache in session directory model..'
314 $ret = $tmp . '/'. $proj . '.js';
316 echo "BUILT: $ret \n";
323 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
325 function install($proj)
328 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
332 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
333 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
335 echo "SKIP : no js file $proj\n";
338 if (!file_exists("$base/_compiled_")) {
339 mkdir ("$base/_compiled_", 0755, true);
341 $target = "$base/_compiled_/".$proj .'.js';
342 print_R(array($src,$target));
343 if (file_exists($target)) {
344 return; // already installed.
347 symlink($src, $target);
352 function gatherProjects() {
353 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
356 foreach(scandir($src) as $f) {
357 if (!strlen($f) || $f[0] == '.') {
365 if ($f == 'templates') {