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)
72 * @param {String} output url (path to basedir basically), or false
79 function packScript($basedir, $files, $output_url, $compile=true)
81 // this outputs <script tags..>
82 // either for just the original files,
83 // or the compressed version.
84 // first expand files..
88 foreach($files as $f) {
89 if (!file_exists($basedir .'/' .$f)) {
92 if (!is_dir($basedir .'/' .$f)) {
94 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
98 foreach(glob($basedir .'/' .$f.'/*.js') as $fx) {
99 $arfiles[$fx] = filemtime($fx);
100 $ofiles [] = $f . '/'. basename($fx);
104 $output = md5(serialize($arfiles)) .'.js';
106 if ( $compile && !file_exists($basedir.'/_cache_/'.$output)) {
107 $this->pack($arfiles,$basedir.'/_cache_/'.$output);
110 if ($compile && file_exists($basedir.'/_cache_/'.$output)) {
112 echo '<script type="text/javascript" src="'.$output_url.'/_cache_/'. $output.'"></script>';
115 foreach($ofiles as $f) {
116 echo '<script type="text/javascript" src="'.$output_url.'/'.$f.'"></script>'."\n";
122 function packCss($basedir, $files, $output_url)
124 // this outputs <script tags..>
125 // either for just the original files,
126 // or the compressed version.
127 // first expand files..
132 foreach($files as $f) {
133 if (!file_exists($basedir .'/' .$f)) {
136 if (!is_dir($basedir .'/' .$f)) {
137 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
141 foreach(glob($basedir .'/' .$f.'/*.css') as $fx) {
142 $arfiles[$fx] = filemtime($fx);
143 $ofiles [] = $f . '/'. basename($fx);
147 $output = md5(serialize($arfiles)) .'.css';
149 if (!file_exists($basedir.'/_cache_/'.$output)) {
150 $this->packCssCore($arfiles,$basedir.'/_cache_/'.$output);
152 //var_dump()$basedir. '/_cache_/'.$output);
153 if (file_exists($basedir. '/_cache_/'.$output)) {
154 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url. '/_cache_/'. $output.'" />';
157 foreach($ofiles as $f ) {
158 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url.'/'.$f.'" />'."\n";
165 * wrapper arroudn packer...
166 * @param {Array} map of $files => filemtime the files to pack
167 * @param {String} $output name fo file to output
170 function packCssCore($files, $output)
174 $o = HTML_FlexyFramework::get()->Pman_Core;
176 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
177 echo '<!-- jspacker not set -->';
180 require_once 'System.php';
181 $seed= System::which('seed');
183 echo '<!-- seed not installed -->';
187 $targetm = file_exists($output) ? filemtime($output) : 0;
190 foreach($files as $f => $mt) {
191 $max = max($max,$mt);
192 $ofiles[] = escapeshellarg($f);
194 if ($max < $targetm) {
197 if (!file_exists(dirname($output))) {
198 mkdir(dirname($output), 0755, true);
200 $eoutput = escapeshellarg($output);
201 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
202 //echo "<PRE>$cmd\n"; echo `$cmd`; exit;
206 // we should do more checking.. return val etc..
207 if (file_exists($output) && ($max < filemtime($output) ) ) {
214 * wrapper arroudn packer...
215 * @param {Array} map of $files => filemtime the files to pack
216 * @param {String} $output name fo file to output
219 function pack($files, $output)
223 $o = HTML_FlexyFramework::get()->Pman_Core;
225 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
226 echo '<!-- JS COMPILE ERROR: option: Pman_Core[jspacker] not set -->';
230 require_once 'System.php';
231 $seed= System::which('seed');
233 echo '<!-- JS COMPILE ERROR: seed not installed -->';
237 $targetm = file_exists($output) ? filemtime($output) : 0;
240 foreach($files as $f => $mt) {
241 $max = max($max,$mt);
242 $ofiles[] = escapeshellarg($f);
244 if ($max < $targetm) {
248 if (!file_exists(dirname($output))) {
249 mkdir(dirname($output), 0755, true);
252 $eoutput = escapeshellarg($output);
253 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ') . ' 2>&1';
254 //echo "<PRE>$cmd\n";
259 // since this only appears when we change.. it's ok to dump it out..
260 echo "<!-- Compiled javascript
262 " . htmlspecialchars($cmd) . "
264 " . htmlspecialchars($res) . "
268 // we should do more checking.. return val etc..
269 if (file_exists($output) && ($max < filemtime($output) ) ) {
273 echo "<!-- JS COMPILE ERROR: packed file did not exist -->";
282 * @param {String} $proj name of Pman component to build
283 * runs pack.js -m {proj} -a $src/*.js
288 function build($proj)
290 echo "Building $proj\n";
293 $this->err = "no project";
294 if ($this->cli) echo $this->err;
297 // first item in path is always the app start directory..
298 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
302 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
305 require_once 'System.php';
306 $seed= System::which('seed');
308 $this->err ="no seed installed";
309 if ($this->cli) echo $this->err;
313 $o = HTML_FlexyFramework::get()->Pman_Core;
315 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
316 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
317 introspection documentation directory where pack.js is located.";
318 if ($this->cli) echo $this->err;
322 // should we be more specirfic!??!?!?
324 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
327 // technically we should trash old compiled files..
328 // or we move towards a 'cache in session directory model..'
333 $ret = $tmp . '/'. $proj . '.js';
335 echo "BUILT: $ret \n";
342 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
344 function install($proj)
347 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
351 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
352 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
354 echo "SKIP : no js file $proj\n";
357 if (!file_exists("$base/_compiled_")) {
358 mkdir ("$base/_compiled_", 0755, true);
360 $target = "$base/_compiled_/".$proj .'.js';
361 print_R(array($src,$target));
362 if (file_exists($target)) {
363 return; // already installed.
366 symlink($src, $target);
371 function gatherProjects() {
372 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
375 foreach(scandir($src) as $f) {
376 if (!strlen($f) || $f[0] == '.') {
384 if ($f == 'templates') {