/**
  * @param Config $config
  * @param Section $section
  * @param Server $server
  * @param Logger $logger
  * @param Deployer $deployer
  * @return void
  */
 public function onBefore(Config $config, Section $section, Server $server, Logger $logger, Deployer $deployer)
 {
     $cwd = $section->getLocal();
     // Display info
     $logger->log(sprintf('Composer: composer install --no-dev --prefer-dist --optimize-autoloader -d %s', $cwd));
     // Execute command
     System::run(sprintf('composer install --no-dev --prefer-dist --optimize-autoloader -d %s', $cwd), $return);
     // Display result
     if ($return) {
         $logger->log('Composer: FAILED (' . $return . ')', 'red');
     } else {
         $logger->log('Composer: INSTALLED / OPTIMIZED', 'green');
     }
 }
Пример #2
0
 private function writeProgress($count, $total, $file, $percent = NULL, $color = NULL)
 {
     $len = strlen((string) $total);
     $s = sprintf("(% {$len}d of %-{$len}d) %s", $count, $total, $file);
     if ($percent === NULL) {
         $this->logger->log($s, $color);
     } else {
         echo $s . ' [' . round($percent) . "%]\r";
     }
 }
 /**
  * @param string $message
  * @param string $color
  */
 private function log($message, $color = NULL)
 {
     $this->logger->log("{$this->pluginName}: {$message}", $color);
 }
Пример #4
0
 /**
  * @param Config $config
  */
 public function run(Config $config)
 {
     // Create logger
     $logFile = $config->getLogFile();
     $this->logger = $logFile ? new Logger($logFile) : new StdOutLogger();
     $this->logger->useColors = $config->useColors();
     // Create temp dir
     if (!is_dir($tempDir = $config->getTempDir())) {
         $this->logger->log("Creating temporary directory {$tempDir}");
         @mkdir($tempDir, 0777, TRUE);
     }
     // Start time
     $time = time();
     $this->logger->log("Started at " . date('[Y/m/d H:i]'));
     // Get sections and get sections names
     $sections = $config->getSections();
     $sectionNames = array_map(function (Section $s) {
         return $s->getName();
     }, $sections);
     // Show info
     $this->logger->log(sprintf('Found sections: %d (%s)', count($sectionNames), implode(',', $sectionNames)));
     // Process all sections
     foreach ($sections as $section) {
         // Show info
         $this->logger->log("\nDeploying section [{$section->getName()}]");
         // Create deployer
         $deployment = $this->createDeployer($config, $section);
         $deployment->tempDir = $tempDir;
         // Detect mode -> generate
         if ($config->getMode() === 'generate') {
             $this->logger->log('Scanning files');
             $localFiles = $deployment->collectPaths();
             $this->logger->log("Saved " . $deployment->writeDeploymentFile($localFiles));
             continue;
         }
         // Show info
         if ($deployment->testMode) {
             $this->logger->log('Test mode');
         } else {
             $this->logger->log('Live mode');
         }
         if (!$deployment->allowDelete) {
             $this->logger->log('Deleting disabled');
         }
         // Deploy
         $deployment->deploy();
     }
     // Show elapsed time
     $time = time() - $time;
     $this->logger->log("\nFinished at " . date('[Y/m/d H:i]') . " (in {$time} seconds)", 'lime');
 }