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";
146 * wrapper arroudn packer...
147 * @param {Array} map of $files => filemtime the files to pack
148 * @param {String} $output name fo file to output
151 function packCssCore($files, $output)
155 $o = HTML_FlexyFramework::get()->Pman_Core;
157 if (empty($o['cssminify']) || !file_exists($o['cssminify'])) {
158 echo '<!-- jspacker not set -->';
161 require_once 'System.php';
162 $seed= System::which('seed');
164 echo '<!-- seed not installed -->';
168 $targetm = file_exists($output) ? filemtime($output) : 0;
171 foreach($files as $f => $mt) {
172 $max = max($max,$mt);
173 $ofiles[] = escapeshellarg($f);
175 if ($max < $targetm) {
178 if (!file_exists(dirname($output))) {
179 mkdir(dirname($output), 0755, true);
181 $eoutput = escapeshellarg($output);
182 $cmd = "$seed {$o['cssminify']} $eoutput " . implode($ofiles, ' ');
183 //echo "<PRE>$cmd\n";
188 // we should do more checking.. return val etc..
189 if (file_exists($output) && ($max < filemtime($output) ) ) {
196 * wrapper arroudn packer...
197 * @param {Array} map of $files => filemtime the files to pack
198 * @param {String} $output name fo file to output
201 function pack($files, $output)
205 $o = HTML_FlexyFramework::get()->Pman_Core;
207 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
208 echo '<!-- jspacker not set -->';
212 require_once 'System.php';
213 $seed= System::which('seed');
215 echo '<!-- seed not installed -->';
219 $targetm = file_exists($output) ? filemtime($output) : 0;
222 foreach($files as $f => $mt) {
223 $max = max($max,$mt);
224 $ofiles[] = escapeshellarg($f);
226 if ($max < $targetm) {
230 if (!file_exists(dirname($output))) {
231 mkdir(dirname($output), 0755, true);
233 $eoutput = escapeshellarg($output);
234 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
235 //echo "<PRE>$cmd\n";
240 // we should do more checking.. return val etc..
241 if (file_exists($output) && ($max < filemtime($output) ) ) {
252 * @param {String} $proj name of Pman component to build
253 * runs pack.js -m {proj} -a $src/*.js
258 function build($proj)
260 echo "Building $proj\n";
263 $this->err = "no project";
264 if ($this->cli) echo $this->err;
267 // first item in path is always the app start directory..
268 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
272 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
275 require_once 'System.php';
276 $seed= System::which('seed');
278 $this->err ="no seed installed";
279 if ($this->cli) echo $this->err;
283 $o = HTML_FlexyFramework::get()->Pman_Core;
285 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
286 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
287 introspection documentation directory where pack.js is located.";
288 if ($this->cli) echo $this->err;
292 // should we be more specirfic!??!?!?
294 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
297 // technically we should trash old compiled files..
298 // or we move towards a 'cache in session directory model..'
303 $ret = $tmp . '/'. $proj . '.js';
305 echo "BUILT: $ret \n";
312 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
314 function install($proj)
317 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
321 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
322 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
324 echo "SKIP : no js file $proj\n";
327 if (!file_exists("$base/_compiled_")) {
328 mkdir ("$base/_compiled_", 0755, true);
330 $target = "$base/_compiled_/".$proj .'.js';
331 print_R(array($src,$target));
332 if (file_exists($target)) {
333 return; // already installed.
336 symlink($src, $target);
341 function gatherProjects() {
342 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
345 foreach(scandir($src) as $f) {
346 if (!strlen($f) || $f[0] == '.') {
354 if ($f == 'templates') {