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)
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);
94 if (file_exists($output_path.'/'.$output)) {
95 echo "output compressed..";
98 echo "output original..";
108 * wrapper arroudn packer...
109 * @param {Array} map of $files => filemtime the files to pack
110 * @param {String} $output name fo file to output
113 function pack($files, $output)
117 $o = HTML_FlexyFramework::get()->Pman_Core;
119 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
120 echo '<!-- jspacker not set -->';
124 require_once 'System.php';
125 $seed= System::which('seed');
127 echo '<!-- seed not installed -->';
131 $targetm = file_exists($output) ? filemtime($output) : 0;
134 foreach($files as $f => $mt) {
135 $max = max($max,$mt);
136 $ofiles[] = escapeshellarg($f);
138 if ($max < $targetm)) {
142 $eoutput = escapeshellarg($f);
143 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
148 // we should do more checking.. return val etc..
149 if (file_exists($output) && ($max < filemtime($output) ) ) {
160 * @param {String} $proj name of Pman component to build
161 * runs pack.js -m {proj} -a $src/*.js
166 function build($proj)
168 echo "Building $proj\n";
171 $this->err = "no project";
172 if ($this->cli) echo $this->err;
175 // first item in path is always the app start directory..
176 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
180 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
183 require_once 'System.php';
184 $seed= System::which('seed');
186 $this->err ="no seed installed";
187 if ($this->cli) echo $this->err;
191 $o = HTML_FlexyFramework::get()->Pman_Core;
193 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
194 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
195 introspection documentation directory where pack.js is located.";
196 if ($this->cli) echo $this->err;
200 // should we be more specirfic!??!?!?
202 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
205 // technically we should trash old compiled files..
206 // or we move towards a 'cache in session directory model..'
211 $ret = $tmp . '/'. $proj . '.js';
213 echo "BUILT: $ret \n";
220 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
222 function install($proj)
225 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
229 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
230 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
232 echo "SKIP : no js file $proj\n";
235 if (!file_exists("$base/_compiled_")) {
236 mkdir ("$base/_compiled_", 0755, true);
238 $target = "$base/_compiled_/".$proj .'.js';
239 print_R(array($src,$target));
240 if (file_exists($target)) {
241 return; // already installed.
244 symlink($src, $target);
249 function gatherProjects() {
250 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
253 foreach(scandir($src) as $f) {
254 if (!strlen($f) || $f[0] == '.') {
262 if ($f == 'templates') {