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=">
98 echo "output compressed..";
101 echo "output original..";
111 * wrapper arroudn packer...
112 * @param {Array} map of $files => filemtime the files to pack
113 * @param {String} $output name fo file to output
116 function pack($files, $output)
120 $o = HTML_FlexyFramework::get()->Pman_Core;
122 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
123 echo '<!-- jspacker not set -->';
127 require_once 'System.php';
128 $seed= System::which('seed');
130 echo '<!-- seed not installed -->';
134 $targetm = file_exists($output) ? filemtime($output) : 0;
137 foreach($files as $f => $mt) {
138 $max = max($max,$mt);
139 $ofiles[] = escapeshellarg($f);
141 if ($max < $targetm) {
144 if (!file_exists(dirname($output))) {
145 mkdir(dirname($output), 0755, true);
147 $eoutput = escapeshellarg($output);
148 $cmd = "$seed {$o['jspacker']}/pack.js -o $eoutput " . implode($ofiles, ' ');
149 //echo "<PRE>$cmd\n";
154 // we should do more checking.. return val etc..
155 if (file_exists($output) && ($max < filemtime($output) ) ) {
166 * @param {String} $proj name of Pman component to build
167 * runs pack.js -m {proj} -a $src/*.js
172 function build($proj)
174 echo "Building $proj\n";
177 $this->err = "no project";
178 if ($this->cli) echo $this->err;
181 // first item in path is always the app start directory..
182 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman/'. $proj;
186 //$tmp = ini_get('session.save_path')."/{$proj}_". posix_getuid(). '_'.md5($src);
189 require_once 'System.php';
190 $seed= System::which('seed');
192 $this->err ="no seed installed";
193 if ($this->cli) echo $this->err;
197 $o = HTML_FlexyFramework::get()->Pman_Core;
199 if (empty($o['jspacker']) || !file_exists($o['jspacker'].'/pack.js')) {
200 $this->err ="no jstoolkit path set [Pman_Core][jspacker] to the
201 introspection documentation directory where pack.js is located.";
202 if ($this->cli) echo $this->err;
206 // should we be more specirfic!??!?!?
208 $cmd = "$seed {$o['jspacker']}/pack.js -m $proj -a $src/*.js";
211 // technically we should trash old compiled files..
212 // or we move towards a 'cache in session directory model..'
217 $ret = $tmp . '/'. $proj . '.js';
219 echo "BUILT: $ret \n";
226 // link {PROJECT}/compiled/{PROJECT}.js to _compiled_ folder to make it live.
228 function install($proj)
231 $base = dirname(realpath($_SERVER["SCRIPT_FILENAME"]));
235 var_dump($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
236 $src = realpath($base .'/Pman/'. $proj.'/compiled/'.$proj .'.js');
238 echo "SKIP : no js file $proj\n";
241 if (!file_exists("$base/_compiled_")) {
242 mkdir ("$base/_compiled_", 0755, true);
244 $target = "$base/_compiled_/".$proj .'.js';
245 print_R(array($src,$target));
246 if (file_exists($target)) {
247 return; // already installed.
250 symlink($src, $target);
255 function gatherProjects() {
256 $src= array_shift(explode(PATH_SEPARATOR, ini_get('include_path'))) .'/Pman';
259 foreach(scandir($src) as $f) {
260 if (!strlen($f) || $f[0] == '.') {
268 if ($f == 'templates') {