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($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..
122 foreach($files as $f) {
123 if (!file_exists($f)) {
126 if (!is_dir($basedir .'/' .$f)) {
127 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
131 foreach(glob($basedir .'/' .$f.'/*.css') as $fx) {
132 $arfiles[$fx] = filemtime($fx);
133 $ofiles [] = $f . '/'. basename($fx);
137 $output = md5(serialize($arfiles)) .'.css';
139 if (!file_exists($output_path.'/_cache_/'.$output)) {
140 $this->packCssCore($arfiles,$output_path.'/_cache_/'.$output);
143 if (file_exists($output_path.'/'.$output)) {
144 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url. '/_cache_/'. $output.'" />';
147 foreach($ofiles as $f ) {
148 echo '<link type="text/css" rel="stylesheet" media="screen" href="'.$output_url.'/'.$f.'" />'."\n";
155 * wrapper arroudn packer...
156 * @param {Array} map of $files => filemtime the files to pack
157 * @param {String} $output name fo file to output
160 function packCssCore($files, $output)
164 $o = HTML_FlexyFramework::get()->Pman_Core;
166 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
167 echo '<!-- jspacker not set -->';
170 require_once 'System.php';
171 $seed= System::which('seed');
173 echo '<!-- seed not installed -->';
177 $targetm = file_exists($output) ? filemtime($output) : 0;
180 foreach($files as $f => $mt) {
181 $max = max($max,$mt);
182 $ofiles[] = escapeshellarg($f);
184 if ($max < $targetm) {
187 if (!file_exists(dirname($output))) {
188 mkdir(dirname($output), 0755, true);
190 $eoutput = escapeshellarg($output);
191 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
192 //echo "<PRE>$cmd\n";
197 // we should do more checking.. return val etc..
198 if (file_exists($output) && ($max < filemtime($output) ) ) {
205 * wrapper arroudn packer...
206 * @param {Array} map of $files => filemtime the files to pack
207 * @param {String} $output name fo file to output
210 function pack($files, $output)
214 $o = HTML_FlexyFramework::get()->Pman_Core;
216 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
217 echo '<!-- jspacker not set -->';
221 require_once 'System.php';
222 $seed= System::which('seed');
224 echo '<!-- seed not installed -->';
228 $targetm = file_exists($output) ? filemtime($output) : 0;
231 foreach($files as $f => $mt) {
232 $max = max($max,$mt);
233 $ofiles[] = escapeshellarg($f);
235 if ($max < $targetm) {
239 if (!file_exists(dirname($output))) {
240 mkdir(dirname($output), 0755, true);
242 $eoutput = escapeshellarg($output);
243 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
244 //echo "<PRE>$cmd\n";
249 // we should do more checking.. return val etc..
250 if (file_exists($output) && ($max < filemtime($output) ) ) {
261 * @param {String} $proj name of Pman component to build
262 * runs pack.js -m {proj} -a $src/*.js
267 function build($proj)
269 echo "Building $proj\n";
272 $this->err = "no project";
273 if ($this->cli) echo $this->err;
276 // first item in path is always the app start directory..
277 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
281 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
284 require_once 'System.php';
285 $seed= System::which('seed');
287 $this->err ="no seed installed";
288 if ($this->cli) echo $this->err;
292 $o = HTML_FlexyFramework::get()->Pman_Core;
294 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
295 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
296 introspection documentation directory where pack.js is located.";
297 if ($this->cli) echo $this->err;
301 // should we be more specirfic!??!?!?
303 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
306 // technically we should trash old compiled files..
307 // or we move towards a 'cache in session directory model..'
312 $ret = $tmp . '/'. $proj . '.js';
314 echo "BUILT: $ret \n";
321 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
323 function install($proj)
326 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
330 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
331 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
333 echo "SKIP : no js file $proj\n";
336 if (!file_exists("$base/_compiled_")) {
337 mkdir ("$base/_compiled_", 0755, true);
339 $target = "$base/_compiled_/".$proj .'.js';
340 print_R(array($src,$target));
341 if (file_exists($target)) {
342 return; // already installed.
345 symlink($src, $target);
350 function gatherProjects() {
351 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
354 foreach(scandir($src) as $f) {
355 if (!strlen($f) || $f[0] == '.') {
363 if ($f == 'templates') {