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 (!is_dir($basedir .'/' .$f)) {
81 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
84 foreach(glob($basedir .'/' .$f.'/*.js') as $fx) {
85 $arfiles[$fx] = filemtime($fx);
89 $output = md5(serialize($arfiles)) .'.js';
91 if (!file_exists($output_path.'/_cache_/'.$output)) {
92 $this->pack($arfiles,$output_path.'/_cache_/'.$output);
95 if (file_exists($output_path.'/'.$output)) {
97 echo '<script type="text/javascript" src="'.$output_url.'/_cache_/'. $output.'"></script>';
100 foreach($arfiles as $f=>$t) {
101 echo '<script type="text/javascript" src="'.$output_url.'/'.$f.'"></script>';
107 function packCss($basedir, $files, $output_path, $output_url)
109 // this outputs <script tags..>
110 // either for just the original files,
111 // or the compressed version.
112 // first expand files..
116 foreach($files as $f) {
117 if (!is_dir($basedir .'/' .$f)) {
118 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
122 foreach(glob($basedir .'/' .$f.'/*.css') as $fx) {
123 $arfiles[$fx] = filemtime($fx);
127 $output = md5(serialize($arfiles)) .'.css';
129 if (!file_exists($output_path.'/_cache_/'.$output)) {
130 $this->packCssCore($arfiles,$output_path.'/_cache_/'.$output);
133 if (file_exists($output_path.'/'.$output)) {
134 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url. '/_cache_/'. $output.'" />';
137 foreach($arfiles as $f=>$t) {
138 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url.'/'.$f.'" />'."\n";
145 * wrapper arroudn packer...
146 * @param {Array} map of $files => filemtime the files to pack
147 * @param {String} $output name fo file to output
150 function packCssCore($files, $output)
154 $o = HTML_FlexyFramework::get()->Pman_Core;
156 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
157 echo '<!-- jspacker not set -->';
160 require_once 'System.php';
161 $seed= System::which('seed');
163 echo '<!-- seed not installed -->';
167 $targetm = file_exists($output) ? filemtime($output) : 0;
170 foreach($files as $f => $mt) {
171 $max = max($max,$mt);
172 $ofiles[] = escapeshellarg($f);
174 if ($max < $targetm) {
177 if (!file_exists(dirname($output))) {
178 mkdir(dirname($output), 0755, true);
180 $eoutput = escapeshellarg($output);
181 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
182 //echo "<PRE>$cmd\n";
187 // we should do more checking.. return val etc..
188 if (file_exists($output) && ($max < filemtime($output) ) ) {
195 * wrapper arroudn packer...
196 * @param {Array} map of $files => filemtime the files to pack
197 * @param {String} $output name fo file to output
200 function pack($files, $output)
204 $o = HTML_FlexyFramework::get()->Pman_Core;
206 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
207 echo '<!-- jspacker not set -->';
211 require_once 'System.php';
212 $seed= System::which('seed');
214 echo '<!-- seed not installed -->';
218 $targetm = file_exists($output) ? filemtime($output) : 0;
221 foreach($files as $f => $mt) {
222 $max = max($max,$mt);
223 $ofiles[] = escapeshellarg($f);
225 if ($max < $targetm) {
229 if (!file_exists(dirname($output))) {
230 mkdir(dirname($output), 0755, true);
232 $eoutput = escapeshellarg($output);
233 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
234 //echo "<PRE>$cmd\n";
239 // we should do more checking.. return val etc..
240 if (file_exists($output) && ($max < filemtime($output) ) ) {
251 * @param {String} $proj name of Pman component to build
252 * runs pack.js -m {proj} -a $src/*.js
257 function build($proj)
259 echo "Building $proj\n";
262 $this->err = "no project";
263 if ($this->cli) echo $this->err;
266 // first item in path is always the app start directory..
267 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
271 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
274 require_once 'System.php';
275 $seed= System::which('seed');
277 $this->err ="no seed installed";
278 if ($this->cli) echo $this->err;
282 $o = HTML_FlexyFramework::get()->Pman_Core;
284 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
285 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
286 introspection documentation directory where pack.js is located.";
287 if ($this->cli) echo $this->err;
291 // should we be more specirfic!??!?!?
293 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
296 // technically we should trash old compiled files..
297 // or we move towards a 'cache in session directory model..'
302 $ret = $tmp . '/'. $proj . '.js';
304 echo "BUILT: $ret \n";
311 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
313 function install($proj)
316 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
320 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
321 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
323 echo "SKIP : no js file $proj\n";
326 if (!file_exists("$base/_compiled_")) {
327 mkdir ("$base/_compiled_", 0755, true);
329 $target = "$base/_compiled_/".$proj .'.js';
330 print_R(array($src,$target));
331 if (file_exists($target)) {
332 return; // already installed.
335 symlink($src, $target);
340 function gatherProjects() {
341 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
344 foreach(scandir($src) as $f) {
345 if (!strlen($f) || $f[0] == '.') {
353 if ($f == 'templates') {