Ejemplo n.º 1
0
 public static function precompile(InputInterface $input, OutputInterface $output)
 {
     self::_initConfig($input);
     $files = Config::getPrecompile();
     if (empty($files)) {
         return true;
     }
     $compiledFiles = array();
     $serverRootPath = Config::getServerRootPath();
     foreach ($files as $file) {
         $file = ltrim($file, DIRECTORY_SEPARATOR);
         $fileInfo = new SplFileInfo($file);
         $extName = strtolower($fileInfo->getExtension());
         if ($extName !== 'js' && $extName !== 'css') {
             continue;
         }
         $uglifyClass = '\\Assets\\Uglify\\' . ucfirst($extName);
         $distFile = $uglifyClass::uglify($file);
         if ($distFile === false) {
             $output->writeln("<error>Can't compile file : {$file}</error>");
         } else {
             $compiledFiles[$file] = $distFile;
             $output->writeln('<info>Create file</info> : ' . $serverRootPath . $distFile);
         }
     }
     if (!empty($compiledFiles)) {
         file_put_contents($serverRootPath . DIRECTORY_SEPARATOR . '.assetsrc', serialize($compiledFiles));
     }
     $uglifiedPath = DIRECTORY_SEPARATOR . 'uglified' . DIRECTORY_SEPARATOR . 'assets';
     $files = scandir($serverRootPath . $uglifiedPath);
     foreach ($files as $file) {
         if ($file === '.' || $file === '..') {
             continue;
         }
         $file = $uglifiedPath . DIRECTORY_SEPARATOR . $file;
         if (in_array($file, $compiledFiles)) {
             continue;
         }
         $file = $serverRootPath . $file;
         if (unlink($file)) {
             $output->writeln('<info>Remove unuseful file</info> : ' . $file);
         }
     }
 }