Beispiel #1
0
 public function build($script)
 {
     $dependencies = array_merge($this->dependency->getList($this->project->getPath("resources coffee {$script}.coffee")), $this->dependency->getList($this->sencha->getPath('src coffee Cti.coffee')));
     $fs = new Filesystem();
     $result = '';
     $sourceList = array();
     $stopwatch = new Stopwatch();
     foreach (array_reverse($dependencies) as $coffee) {
         $sourceList[] = $coffee;
         $local = $this->source->getLocalPath($coffee);
         $local_js = dirname($local) . DIRECTORY_SEPARATOR . basename($local, 'coffee') . 'js';
         $javascript = $this->project->getPath(sprintf('build js %s', $local_js));
         if (!file_exists($javascript) || filemtime($coffee) >= filemtime($javascript)) {
             if ($this->debug) {
                 $stopwatch->start($local);
                 echo '- compile ' . $local;
             }
             $code = \CoffeeScript\Compiler::compile(file_get_contents($coffee), array('filename' => $coffee, 'bare' => true, 'header' => false));
             if ($this->debug) {
                 $event = $stopwatch->stop($local);
                 echo ' (' . String::formatMilliseconds($event->getDuration()) . ' using ' . String::formatBytes($event->getMemory()) . ')' . PHP_EOL;
             }
             $fs->dumpFile($javascript, $code);
         } else {
             $code = file_get_contents($javascript);
         }
         $result .= $code . PHP_EOL;
     }
     $this->hash[$script] = $sourceList;
     $this->cache->set(__CLASS__, $this->hash);
     $filename = $this->project->getPath("public js {$script}.js");
     $fs->dumpFile($filename, $result);
     return $filename;
 }
Beispiel #2
0
 /**
  * @param Cache $cache
  */
 public function init(Cache $cache)
 {
     if ($cache->exists(get_class($this))) {
         $this->cache = $cache->get(get_class($this));
     }
 }