Exemple #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;
 }
Exemple #2
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);
 }
Exemple #3
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $info = '';
     $dirsCopied = $filesCopied = 0;
     $realFrom = realpath($this->_processPathParam($this->param('from'))) . DIRECTORY_SEPARATOR;
     $realTo = $this->_processPathParam($this->param('to'));
     if (!file_exists($realFrom)) {
         \Deployer::criticalError(sprintf('"%s" not found.', $this->_processPathParam($this->param('from'))));
     }
     if (!file_exists($realTo) && $this->param('create')) {
         @mkdir($realTo);
         if (!is_dir($realTo)) {
             \Deployer::criticalError(sprintf('Something went wrong. Can not create directory "%s".', $this->_processPathParam($this->param('from'))));
         }
         $info .= sprintf('Directory "%s" created.', $realTo) . PHP_EOL;
     }
     if (is_file($realFrom)) {
         @copy($realFrom, $realTo);
         if (!is_file($realTo) || filesize($realFrom) != filesize($realTo)) {
             \Deployer::criticalError(sprintf('Can not copy "%s" => "%s".', $realFrom, $realTo));
         }
         $info .= sprintf('Copied "%s" => "$s".', $realFrom, $realTo) . PHP_EOL;
         $filesCopied = 1;
     } else {
         $files = \Deployer::files($realFrom, $this->param('names'), $this->param('notnames'), SORT_ASC);
         $dirs = \Deployer::dirs($realFrom, $this->param('names'), $this->param('notnames'), SORT_ASC);
         foreach ($dirs as $dir) {
             $destDir = str_replace($realFrom, $realTo, $dir);
             if (file_exists($destDir)) {
                 \Deployer::criticalError(sprintf('Can not copy dir "%s" => "%s". Destination directory exists.', $dir, $destDir));
             }
             @mkdir($destDir);
             if (!is_dir($destDir)) {
                 \Deployer::criticalError(sprintf('Something went wrong. Can not copy dir "%s" => "%s".', $dir, $destDir));
             }
             $info .= sprintf('Directory copied "%s" => "%s".', $dir, $destDir) . PHP_EOL;
         }
         foreach ($files as $file) {
             $destFile = str_replace($realFrom, $realTo, $file);
             if (file_exists($destFile)) {
                 \Deployer::criticalError(sprintf('Can not copy file "%s" => "%s". Destination file exists.', $file, $destFile));
             }
             @copy($file, $destFile);
             if (!is_file($destFile) || filesize($file) != filesize($destFile)) {
                 \Deployer::criticalError(sprintf('Something went wrong. Can not copy file "%s" => "%s".', $file, $destFile));
             }
             $info .= sprintf('File copied "%s" => "%s".', $file, $destFile) . PHP_EOL;
             $dirsCopied = sizeof($dirs);
             $filesCopied = sizeof($files);
         }
     }
     $message = sprintf('Copied %d dirs and %d files.', $dirsCopied, $filesCopied);
     \Deployer::messageInfo($message);
     $info .= $message . PHP_EOL;
     if (!empty($info)) {
         return $this->info($info);
     }
     return $this;
 }
Exemple #4
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $info = '';
     $realDir = $this->_processPathParam($this->param('dir'));
     if (!is_dir($realDir)) {
         if ($this->param('create')) {
             @mkdir($realDir);
             if (!is_dir($realDir)) {
                 \Deployer::criticalError(sprintf('Something went wrong. Can not create directory "%s".', $realDir));
             }
             $info = sprintf('Created directory %s.', $realDir);
             \Deployer::messageInfo($info);
             return $this->info($info . PHP_EOL);
         }
         \Deployer::criticalError(sprintf('"%s" is not a directory.', $realDir));
     }
     if (!is_writable($realDir)) {
         \Deployer::criticalError(sprintf('Directory "%s" must be writable.', $realDir));
     }
     $files = \Deployer::files($realDir, $this->param('names'), $this->param('notnames'), SORT_DESC);
     $dirs = \Deployer::dirs($realDir, $this->param('names'), $this->param('notnames'), SORT_DESC);
     foreach ($files as $file) {
         @unlink($file);
         if (is_file($file)) {
             \Deployer::criticalError(sprintf('Something went wrong. Can not delete file "%s".', $file));
         }
         $info .= sprintf('File "%s" deleted.', $file) . PHP_EOL;
     }
     foreach ($dirs as $dir) {
         @rmdir($dir);
         if (is_dir($dir)) {
             \Deployer::criticalError(sprintf('Something went wrong. Can not remove directory "%s".', $dir));
         }
         $info .= sprintf('Directory "%s" removed.', $dir) . PHP_EOL;
     }
     $dirsRemoved = sizeof($dirs);
     $filesRemoved = sizeof($files);
     if ($this->param('remove') && !$this->param('create')) {
         @rmdir($realDir);
         if (is_dir($realDir)) {
             \Deployer::criticalError(sprintf('Something went wrong. Can not remove directory "%s".', $file));
         }
         $info .= sprintf('Directory "%s" removed.', $realDir) . PHP_EOL;
         $dirsRemoved++;
     }
     $message = sprintf('Removed %d dirs and %d files.', $dirsRemoved, sizeof($files));
     \Deployer::messageInfo($message);
     $info .= $message . PHP_EOL;
     if (!empty($info)) {
         return $this->info($info);
     }
     return $this;
 }
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $dir = \Deployer::applyGlobalParams($this->param('dir'));
     $allFiles = 0;
     foreach ($this->param('names') as $name) {
         $files = \Deployer::files($dir, \Deployer::applyGlobalParams($name));
         foreach ($files as $file) {
             if (is_file($file)) {
                 $mask = str_replace('*', null, $name);
                 rename($file, str_replace($mask, null, $file));
                 $allFiles++;
             }
         }
     }
     $info = sprintf('%d files renamed', $allFiles);
     \Deployer::messageInfo($info);
     return $this->info($info);
 }