Ejemplo n.º 1
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task\Min
  */
 public function execute()
 {
     $info = '';
     $dir = \Deployer::applyGlobalParams($this->param('dir'));
     $finder = new Finder();
     $iterator = $finder->files();
     $overallDecrease = 0;
     foreach ($this->param('name') as $name) {
         $iterator->name(\Deployer::applyGlobalParams($name));
     }
     $files = $iterator->in($dir);
     foreach ($files as $file) {
         $fileName = str_replace('/', DIRECTORY_SEPARATOR, $file);
         list($decreasePrecent, $decreaseBytes) = $this->_min($fileName);
         $overallDecrease += $decreaseBytes;
         $info .= sprintf('%s file decreased at %01.2f%% (%s)', \Deployer::censor($fileName), $decreasePrecent, \Deployer::size($decreaseBytes)) . PHP_EOL;
     }
     $message = sprintf('%d files minifyed at %s', sizeof($files), \Deployer::size($overallDecrease));
     \Deployer::messageInfo($message);
     $info .= $message . PHP_EOL;
     if (!empty($info)) {
         return $this->info($info);
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $zipDir = \Deployer::applyGlobalParams($this->param('dir'));
     $zipFile = \Deployer::applyGlobalParams($this->param('file'));
     if (is_file($zipFile)) {
         unlink($zipFile);
     }
     if (!is_dir($zipDir)) {
         throw new \Deployer\TaskException('"dir" must be a valid directory');
     }
     $zip = new \ZipArchive();
     if (!$zip->open($zipFile, \ZIPARCHIVE::CREATE)) {
         throw new \Deployer\TaskException('can\'t create zip file');
     }
     $dirs = \Deployer::sortByDepth(\Deployer::dirs($zipDir, SORT_ASC));
     foreach ($dirs as $dir) {
         $newDir = $this->_localPath($zipDir, $dir);
         $zip->addEmptyDir($newDir);
     }
     $files = \Deployer::files($zipDir);
     foreach ($files as $file) {
         $newFile = $this->_localPath($zipDir, $file);
         $zip->addFile($file, $newFile);
     }
     $zip->close();
     if (is_file($zipFile)) {
         return $this->info(sprintf('file created; size: %s', \Deployer::size(filezize($zipFile))));
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     foreach (array('dir', 'result') as $param) {
         ${$param} = \Deployer::applyGlobalParams($this->param($param));
     }
     $content = '';
     $finder = new Finder();
     $iterator = $finder->files();
     $allFiles = 0;
     foreach ($this->param('names') as $name) {
         $files = $iterator->name(\Deployer::applyGlobalParams($name))->in($dir);
         foreach ($files as $file) {
             if ($this->param('debug')) {
                 $content .= PHP_EOL . sprintf('/* %s */', $file) . PHP_EOL;
             }
             $content .= file_get_contents($file) . PHP_EOL;
             if ($this->param('delete')) {
                 unlink($file);
             }
             $allFiles++;
         }
     }
     if (is_file($result)) {
         unlink($result);
     }
     file_put_contents($result, $content);
     $info = sprintf('%d files merged; result file size: %s', $allFiles, \Deployer::size(filesize($result)));
     \Deployer::messageInfo($info);
     return $this->info($info);
 }