예제 #1
0
 private function compile()
 {
     $rawDirsPattern = '/^(' . implode('|', $this->rawDirs) . ')(\\/|$)/i';
     foreach (Finder::create()->files()->in($this->assetsPath) as $file) {
         $relativePath = $file->getRelativePath();
         if (empty($relativePath) || preg_match($rawDirsPattern, $relativePath)) {
             continue;
         }
         if (substr($file->getBasename(), 0, 1) === '_') {
             continue;
         }
         $asset = Asset::make($file->getRealPath());
         $process = $asset->getCompileProcess();
         $this->info($process->getCommandline());
         $process->setEnv(['PATH' => trim(`echo \$PATH`) . ':/usr/local/bin/']);
         $out = '';
         $err = '';
         $status = $process->run(function ($type, $line) use(&$out, &$err) {
             if ($type === 'out') {
                 $out .= $line . "\n";
                 $err .= $line . "\n";
             } else {
                 if ($type === 'err') {
                     $err .= $line . "\n";
                 }
             }
         });
         $name = $file->getRelativePathname();
         $name = $asset->getType() . substr($name, strpos($name, '/'));
         $name = substr($name, 0, strrpos($name, '.')) . '-' . md5($out) . '.' . $asset->getType();
         if ($status === 0) {
             $this->storeAsset($file->getRealPath(), $this->publishPath . '/' . $name, $out, $asset->getLastModified());
         } else {
             $this->error($err);
             exit(1);
         }
         unset($out, $err, $process);
     }
 }
예제 #2
0
 private function compile()
 {
     foreach ($this->findAssets($this->assetsPath, $this->rawDirs) as $file) {
         $relativePath = $file->getRelativePath();
         if (empty($relativePath)) {
             continue;
         }
         if (substr($file->getBasename(), 0, 1) === '_') {
             continue;
         }
         $path = $file->getRealPath();
         $asset = Asset::make($path);
         $out = null;
         try {
             $this->info('Compiling ' . $path);
             $out = $asset->compile();
         } catch (CompilationException $e) {
             $this->error($e->getMessage());
             if (is_array($e->context)) {
                 foreach ($e->context as $key => $value) {
                     $this->error(' --> ' . strtoupper($key) . ': ' . $value);
                 }
             } else {
                 if (is_string($e->context)) {
                     $this->error(' --> ' . $e->context);
                 }
             }
             if (!empty($e->log)) {
                 $this->error(' --> ' . $e->log);
             }
             exit(1);
         }
         $name = $file->getRelativePathname();
         $name = $asset->getType() . substr($name, strpos($name, '/'));
         $name = substr($name, 0, strrpos($name, '.')) . '-' . md5($out) . '.' . $asset->getType();
         $this->storeAsset($file->getRealPath(), $this->publishPath . '/' . $name, $out, $asset->getLastModified());
         unset($out, $err, $asset);
     }
 }
예제 #3
0
 public function compile($type)
 {
     $asset = Asset::make($this->path);
     return $this->process($asset->getMime(), $asset, $asset->getLastModified());
 }