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..
78 foreach($files as $f) {
79 if (!is_dir($basedir .'/' .$f)) {
80 $arfiles[$basedir .'/' .$f] = filemtime($basedir .'/' .$f);
83 foreach(glob($basedir .'/' .$f.'/*.js') as $fx) {
84 $arfiles[$fx] = filemtime($fx);
88 $output = md5(serialize($arfiles)) .'.js';
90 if (!file_exists($output_path.'/'.$output)) {
91 $this->pack($arfiles,$output_path.'/'.$output);
94 if (file_exists($output_path.'/'.$output)) {
96 echo '<script type="text/javascript" src="'.$output_url.'/'. $output.'"></script>';
99 foreach($arfiles as $f=>$t) {
100 echo '<script type="text/javascript" src="'.$f.'"></script>';
112 * wrapper arroudn packer...
113 * @param {Array} map of $files => filemtime the files to pack
114 * @param {String} $output name fo file to output
117 function pack($files, $output)
121 $o = HTML_FlexyFramework::get()->Pman_Core;
123 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
124 echo '<!-- jspacker not set -->';
128 require_once 'System.php';
129 $seed= System::which('seed');
131 echo '<!-- seed not installed -->';
135 $targetm = file_exists($output) ? filemtime($output) : 0;
138 foreach($files as $f => $mt) {
139 $max = max($max,$mt);
140 $ofiles[] = escapeshellarg($f);
142 if ($max < $targetm) {
145 if (!file_exists(dirname($output))) {
146 mkdir(dirname($output), 0755, true);
148 $eoutput = escapeshellarg($output);
149 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
150 //echo "<PRE>$cmd\n";
155 // we should do more checking.. return val etc..
156 if (file_exists($output) && ($max < filemtime($output) ) ) {
167 * @param {String} $proj name of Pman component to build
168 * runs pack.js -m {proj} -a $src/*.js
173 function build($proj)
175 echo "Building $proj\n";
178 $this->err = "no project";
179 if ($this->cli) echo $this->err;
182 // first item in path is always the app start directory..
183 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
187 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
190 require_once 'System.php';
191 $seed= System::which('seed');
193 $this->err ="no seed installed";
194 if ($this->cli) echo $this->err;
198 $o = HTML_FlexyFramework::get()->Pman_Core;
200 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
201 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
202 introspection documentation directory where pack.js is located.";
203 if ($this->cli) echo $this->err;
207 // should we be more specirfic!??!?!?
209 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
212 // technically we should trash old compiled files..
213 // or we move towards a 'cache in session directory model..'
218 $ret = $tmp . '/'. $proj . '.js';
220 echo "BUILT: $ret \n";
227 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
229 function install($proj)
232 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
236 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
237 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
239 echo "SKIP : no js file $proj\n";
242 if (!file_exists("$base/_compiled_")) {
243 mkdir ("$base/_compiled_", 0755, true);
245 $target = "$base/_compiled_/".$proj .'.js';
246 print_R(array($src,$target));
247 if (file_exists($target)) {
248 return; // already installed.
251 symlink($src, $target);
256 function gatherProjects() {
257 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
260 foreach(scandir($src) as $f) {
261 if (!strlen($f) || $f[0] == '.') {
269 if ($f == 'templates') {