Exemplo n.º 1
0
 /**
  * Populate all static view files for specified root path and list of languages
  *
  * @param ObjectManagerFactory $omFactory
  * @param array $locales
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function deploy(ObjectManagerFactory $omFactory, array $locales)
 {
     $this->omFactory = $omFactory;
     if ($this->isDryRun) {
         $this->output->writeln('Dry run. Nothing will be recorded to the target directory.');
     }
     $langList = implode(', ', $locales);
     $this->output->writeln("Requested languages: {$langList}");
     $libFiles = $this->filesUtil->getStaticLibraryFiles();
     list($areas, $appFiles) = $this->collectAppFiles($locales);
     foreach ($areas as $area => $themes) {
         $this->emulateApplicationArea($area);
         foreach ($locales as $locale) {
             $this->emulateApplicationLocale($locale, $area);
             foreach ($themes as $themePath) {
                 $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ===");
                 $this->count = 0;
                 $this->errorCount = 0;
                 /** @var \Magento\Theme\Model\View\Design $design */
                 $design = $this->objectManager->create('Magento\\Theme\\Model\\View\\Design');
                 $design->setDesignTheme($themePath, $area);
                 $assetRepo = $this->objectManager->create('Magento\\Framework\\View\\Asset\\Repository', ['design' => $design]);
                 $fileManager = $this->objectManager->create('Magento\\RequireJs\\Model\\FileManager', ['config' => $this->objectManager->create('Magento\\Framework\\RequireJs\\Config', ['assetRepo' => $assetRepo, 'design' => $design]), 'assetRepo' => $assetRepo]);
                 $fileManager->createRequireJsConfigAsset();
                 foreach ($appFiles as $info) {
                     list($fileArea, $fileTheme, , $module, $filePath) = $info;
                     if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array($fileArea . Theme::THEME_PATH_SEPARATOR . $fileTheme, $this->findAncestors($area . Theme::THEME_PATH_SEPARATOR . $themePath)))) {
                         $this->deployFile($filePath, $area, $themePath, $locale, $module);
                     }
                 }
                 foreach ($libFiles as $filePath) {
                     $this->deployFile($filePath, $area, $themePath, $locale, null);
                 }
                 if ($this->jsTranslationConfig->dictionaryEnabled()) {
                     $this->deployFile($this->jsTranslationConfig->getDictionaryFileName(), $area, $themePath, $locale, null);
                 }
                 $fileManager->clearBundleJsPool();
                 $this->bundleManager->flush();
                 $this->output->writeln("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n");
             }
         }
     }
     $this->output->writeln("=== Minify templates ===");
     $this->count = 0;
     foreach ($this->filesUtil->getPhtmlFiles(false, false) as $template) {
         $this->htmlMinifier->minify($template);
         if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
             $this->output->writeln($template . " minified\n");
         } else {
             $this->output->write('.');
         }
         $this->count++;
     }
     $this->output->writeln("\nSuccessful: {$this->count} files modified\n---\n");
     $version = (new \DateTime())->getTimestamp();
     $this->output->writeln("New version of deployed files: {$version}");
     if (!$this->isDryRun) {
         $this->versionStorage->save($version);
     }
 }
Exemplo n.º 2
0
 /**
  * Populate all static view files for specified root path and list of languages
  *
  * @param ObjectManagerFactory $omFactory
  * @param array $locales
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function deploy(ObjectManagerFactory $omFactory, array $locales)
 {
     $this->omFactory = $omFactory;
     if ($this->isDryRun) {
         $this->output->writeln('Dry run. Nothing will be recorded to the target directory.');
     }
     $langList = implode(', ', $locales);
     $this->output->writeln("Requested languages: {$langList}");
     $libFiles = $this->filesUtil->getStaticLibraryFiles();
     list($areas, $appFiles) = $this->collectAppFiles($locales);
     foreach ($areas as $area => $themes) {
         $this->emulateApplicationArea($area);
         foreach ($locales as $locale) {
             $this->emulateApplicationLocale($locale, $area);
             foreach ($themes as $themePath) {
                 $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ===");
                 $this->count = 0;
                 $this->errorCount = 0;
                 foreach ($appFiles as $info) {
                     list($fileArea, , , $module, $filePath) = $info;
                     if ($fileArea == $area || $fileArea == 'base') {
                         $this->deployFile($filePath, $area, $themePath, $locale, $module);
                     }
                 }
                 foreach ($libFiles as $filePath) {
                     $this->deployFile($filePath, $area, $themePath, $locale, null);
                 }
                 if ($this->jsTranslationConfig->dictionaryEnabled()) {
                     $this->deployFile(
                         $this->jsTranslationConfig->getDictionaryFileName(),
                         $area,
                         $themePath,
                         $locale,
                         null
                     );
                 }
                 $this->bundleManager->flush();
                 $this->output->writeln("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n");
             }
         }
     }
     $this->output->writeln("=== Minify templates ===");
     $this->count = 0;
     foreach ($this->filesUtil->getPhtmlFiles(false, false) as $template) {
         $this->htmlMinifier->minify($template);
         if ($this->output->isVerbose()) {
             $this->output->writeln($template . " minified\n");
         } else {
             $this->output->write('.');
         }
         $this->count++;
     }
     $this->output->writeln("\nSuccessful: {$this->count} files modified\n---\n");
     $version = (new \DateTime())->getTimestamp();
     $this->output->writeln("New version of deployed files: {$version}");
     if (!$this->isDryRun) {
         $this->versionStorage->save($version);
     }
 }
Exemplo n.º 3
0
 /**
  * Populate all static view files for specified root path and list of languages
  *
  * @param ObjectManagerFactory $omFactory
  * @param array $locales
  * @param array $deployableAreaThemeMap
  * @return int
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function deploy(ObjectManagerFactory $omFactory, array $locales, array $deployableAreaThemeMap = [])
 {
     $this->omFactory = $omFactory;
     if ($this->getOption(Options::DRY_RUN)) {
         $this->output->writeln('Dry run. Nothing will be recorded to the target directory.');
     }
     $libFiles = $this->filesUtil->getStaticLibraryFiles();
     $appFiles = $this->filesUtil->getStaticPreProcessingFiles();
     foreach ($deployableAreaThemeMap as $area => $themes) {
         $this->emulateApplicationArea($area);
         foreach ($locales as $locale) {
             $this->emulateApplicationLocale($locale, $area);
             foreach ($themes as $themePath) {
                 $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ===");
                 $this->count = 0;
                 $this->errorCount = 0;
                 /** @var \Magento\Theme\Model\View\Design $design */
                 $design = $this->objectManager->create(\Magento\Theme\Model\View\Design::class);
                 $design->setDesignTheme($themePath, $area);
                 $assetRepo = $this->objectManager->create(\Magento\Framework\View\Asset\Repository::class, ['design' => $design]);
                 /** @var \Magento\RequireJs\Model\FileManager $fileManager */
                 $fileManager = $this->objectManager->create(\Magento\RequireJs\Model\FileManager::class, ['config' => $this->objectManager->create(\Magento\Framework\RequireJs\Config::class, ['assetRepo' => $assetRepo, 'design' => $design]), 'assetRepo' => $assetRepo]);
                 $fileManager->createRequireJsConfigAsset();
                 foreach ($appFiles as $info) {
                     list($fileArea, $fileTheme, , $module, $filePath, $fullPath) = $info;
                     if ($this->checkSkip($filePath)) {
                         continue;
                     }
                     if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array($fileArea . Theme::THEME_PATH_SEPARATOR . $fileTheme, $this->findAncestors($area . Theme::THEME_PATH_SEPARATOR . $themePath)))) {
                         $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, $module, $fullPath);
                         if ($compiledFile !== '') {
                             $this->deployFile($compiledFile, $area, $themePath, $locale, $module, $fullPath);
                         }
                     }
                 }
                 foreach ($libFiles as $filePath) {
                     if ($this->checkSkip($filePath)) {
                         continue;
                     }
                     $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, null);
                     if ($compiledFile !== '') {
                         $this->deployFile($compiledFile, $area, $themePath, $locale, null);
                     }
                 }
                 if (!$this->getOption(Options::NO_JAVASCRIPT)) {
                     if ($this->jsTranslationConfig->dictionaryEnabled()) {
                         $dictionaryFileName = $this->jsTranslationConfig->getDictionaryFileName();
                         $this->deployFile($dictionaryFileName, $area, $themePath, $locale, null);
                     }
                     if ($this->getMinification()->isEnabled('js')) {
                         $fileManager->createMinResolverAsset();
                     }
                 }
                 $this->bundleManager->flush();
                 $this->output->writeln("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n");
             }
         }
     }
     if (!($this->getOption(Options::NO_HTML_MINIFY) ?: !$this->getAssetConfig()->isMinifyHtml())) {
         $this->output->writeln('=== Minify templates ===');
         $this->count = 0;
         foreach ($this->filesUtil->getPhtmlFiles(false, false) as $template) {
             $this->htmlMinifier->minify($template);
             if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                 $this->output->writeln($template . " minified\n");
             } else {
                 $this->output->write('.');
             }
             $this->count++;
         }
         $this->output->writeln("\nSuccessful: {$this->count} files modified\n---\n");
     }
     $version = (new \DateTime())->getTimestamp();
     $this->output->writeln("New version of deployed files: {$version}");
     if (!$this->getOption(Options::DRY_RUN)) {
         $this->versionStorage->save($version);
     }
     if ($this->errorCount > 0) {
         // we must have an exit code higher than zero to indicate something was wrong
         return \Magento\Framework\Console\Cli::RETURN_FAILURE;
     }
     return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
 }