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 = serialize($arfiles) .'.js';
90 if (!file_exists($output_path.'/'.$output)) {
91 $this->pack($arfiles,$output);
94 print_r($arfiles);exit;
104 * wrapper arroudn packer...
105 * @param {Array} $files the files to pack
106 * @param {String} $output name fo file to output
109 function pack($files, $output)
113 $o = HTML_FlexyFramework::get()->Pman_Core;
115 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
116 echo '<!-- jspacker not set -->';
120 require_once 'System.php';
121 $seed= System::which('seed');
123 echo '<!-- seed not installed -->';
127 $targetm = file_exists($output) ? filemtime($output) : 0;
129 foreach($files as $i => $f) {
130 $max = max($max,filemtime($f));
131 $files[$i] = escapeshellarg($f);
133 if ($max < filemtime($output)) {
137 $eoutput = escapeshellarg($f);
138 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($files, ' ');
143 // we should do more checking.. return val etc..
144 if (file_exists($output) && ($max < filemtime($output) ) ) {
155 * @param {String} $proj name of Pman component to build
156 * runs pack.js -m {proj} -a $src/*.js
161 function build($proj)
163 echo "Building $proj\n";
166 $this->err = "no project";
167 if ($this->cli) echo $this->err;
170 // first item in path is always the app start directory..
171 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
175 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
178 require_once 'System.php';
179 $seed= System::which('seed');
181 $this->err ="no seed installed";
182 if ($this->cli) echo $this->err;
186 $o = HTML_FlexyFramework::get()->Pman_Core;
188 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
189 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
190 introspection documentation directory where pack.js is located.";
191 if ($this->cli) echo $this->err;
195 // should we be more specirfic!??!?!?
197 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
200 // technically we should trash old compiled files..
201 // or we move towards a 'cache in session directory model..'
206 $ret = $tmp . '/'. $proj . '.js';
208 echo "BUILT: $ret \n";
215 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
217 function install($proj)
220 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
224 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
225 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
227 echo "SKIP : no js file $proj\n";
230 if (!file_exists("$base/_compiled_")) {
231 mkdir ("$base/_compiled_", 0755, true);
233 $target = "$base/_compiled_/".$proj .'.js';
234 print_R(array($src,$target));
235 if (file_exists($target)) {
236 return; // already installed.
239 symlink($src, $target);
244 function gatherProjects() {
245 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
248 foreach(scandir($src) as $f) {
249 if (!strlen($f) || $f[0] == '.') {
257 if ($f == 'templates') {