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)) {
83 if (!is_dir($basedir .'/' .$f)) {
85 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
89 foreach(glob($basedir .'/' .$f.'/*.js') as $fx) {
90 $arfiles[$fx] = filemtime($fx);
91 $ofiles [] = $f . '/'. basename($fx);
95 $output = md5(serialize($arfiles)) .'.js';
97 if (!file_exists($output_path.'/_cache_/'.$output)) {
98 $this->pack($arfiles,$output_path.'/_cache_/'.$output);
101 if (file_exists($output_path.'/'.$output)) {
103 echo '<script type="text/javascript" src="'.$output_url.'/_cache_/'. $output.'"></script>';
106 foreach($ofiles as $f) {
107 echo '<script type="text/javascript" src="'.$output_url.'/'.$f.'"></script>';
113 function packCss($basedir, $files, $output_path, $output_url)
115 // this outputs <script tags..>
116 // either for just the original files,
117 // or the compressed version.
118 // first expand files..
123 foreach($files as $f) {
124 if (!file_exists($basedir .'/' .$f)) {
127 if (!is_dir($basedir .'/' .$f)) {
128 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
132 foreach(glob($basedir .'/' .$f.'/*.css') as $fx) {
133 $arfiles[$fx] = filemtime($fx);
134 $ofiles [] = $f . '/'. basename($fx);
138 $output = md5(serialize($arfiles)) .'.css';
140 if (!file_exists($output_path.'/_cache_/'.$output)) {
141 $this->packCssCore($arfiles,$output_path.'/_cache_/'.$output);
144 if (file_exists($output_path.'/'.$output)) {
145 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url. '/_cache_/'. $output.'" />';
148 foreach($ofiles as $f ) {
149 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url.'/'.$f.'" />'."\n";
156 * wrapper arroudn packer...
157 * @param {Array} map of $files => filemtime the files to pack
158 * @param {String} $output name fo file to output
161 function packCssCore($files, $output)
165 $o = HTML_FlexyFramework::get()->Pman_Core;
167 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
168 echo '<!-- jspacker not set -->';
171 require_once 'System.php';
172 $seed= System::which('seed');
174 echo '<!-- seed not installed -->';
178 $targetm = file_exists($output) ? filemtime($output) : 0;
181 foreach($files as $f => $mt) {
182 $max = max($max,$mt);
183 $ofiles[] = escapeshellarg($f);
185 if ($max < $targetm) {
188 if (!file_exists(dirname($output))) {
189 mkdir(dirname($output), 0755, true);
191 $eoutput = escapeshellarg($output);
192 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
193 //echo "<PRE>$cmd\n";
198 // we should do more checking.. return val etc..
199 if (file_exists($output) && ($max < filemtime($output) ) ) {
206 * wrapper arroudn packer...
207 * @param {Array} map of $files => filemtime the files to pack
208 * @param {String} $output name fo file to output
211 function pack($files, $output)
215 $o = HTML_FlexyFramework::get()->Pman_Core;
217 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
218 echo '<!-- jspacker not set -->';
222 require_once 'System.php';
223 $seed= System::which('seed');
225 echo '<!-- seed not installed -->';
229 $targetm = file_exists($output) ? filemtime($output) : 0;
232 foreach($files as $f => $mt) {
233 $max = max($max,$mt);
234 $ofiles[] = escapeshellarg($f);
236 if ($max < $targetm) {
240 if (!file_exists(dirname($output))) {
241 mkdir(dirname($output), 0755, true);
243 $eoutput = escapeshellarg($output);
244 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
245 //echo "<PRE>$cmd\n";
250 // we should do more checking.. return val etc..
251 if (file_exists($output) && ($max < filemtime($output) ) ) {
262 * @param {String} $proj name of Pman component to build
263 * runs pack.js -m {proj} -a $src/*.js
268 function build($proj)
270 echo "Building $proj\n";
273 $this->err = "no project";
274 if ($this->cli) echo $this->err;
277 // first item in path is always the app start directory..
278 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
282 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
285 require_once 'System.php';
286 $seed= System::which('seed');
288 $this->err ="no seed installed";
289 if ($this->cli) echo $this->err;
293 $o = HTML_FlexyFramework::get()->Pman_Core;
295 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
296 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
297 introspection documentation directory where pack.js is located.";
298 if ($this->cli) echo $this->err;
302 // should we be more specirfic!??!?!?
304 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
307 // technically we should trash old compiled files..
308 // or we move towards a 'cache in session directory model..'
313 $ret = $tmp . '/'. $proj . '.js';
315 echo "BUILT: $ret \n";
322 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
324 function install($proj)
327 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
331 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
332 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
334 echo "SKIP : no js file $proj\n";
337 if (!file_exists("$base/_compiled_")) {
338 mkdir ("$base/_compiled_", 0755, true);
340 $target = "$base/_compiled_/".$proj .'.js';
341 print_R(array($src,$target));
342 if (file_exists($target)) {
343 return; // already installed.
346 symlink($src, $target);
351 function gatherProjects() {
352 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
355 foreach(scandir($src) as $f) {
356 if (!strlen($f) || $f[0] == '.') {
364 if ($f == 'templates') {