From 4e6548620f07fbbaa121f94ecd79d6b9d400b7c1 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Mon, 25 Apr 2016 16:08:45 +0200 Subject: [PATCH 01/15] Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme --- .../Command/DeployStaticContentCommand.php | 137 ++++++++++++++- app/code/Magento/Deploy/Model/Deployer.php | 157 +++++++++++++++--- 2 files changed, 266 insertions(+), 28 deletions(-) mode change 100644 => 100755 app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php mode change 100644 => 100755 app/code/Magento/Deploy/Model/Deployer.php diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php old mode 100644 new mode 100755 index 470b92811e7d9..c3928a89b47db --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -31,6 +31,51 @@ class DeployStaticContentCommand extends Command */ const LANGUAGE_OPTION = 'languages'; + /** + * Key for javascript option + */ + const JAVASCRIPT_OPTION = 'no-javascript'; + + /** + * Key for css option + */ + const CSS_OPTION = 'no-css'; + + /** + * Key for less option + */ + const LESS_OPTION = 'no-less'; + + /** + * Key for images option + */ + const IMAGES_OPTION = 'no-images'; + + /** + * Key for fonts option + */ + const FONTS_OPTION = 'no-fonts'; + + /** + * Key for misc option + */ + const MISC_OPTION = 'no-misc'; + + /** + * Key for html option + */ + const HTML_OPTION = 'no-html'; + + /** + * Key for html option + */ + const HTML_MINIFY_OPTION = 'no-html-minify'; + + /** + * Key for themes option + */ + const THEMES_OPTION = 'themes'; + /** * @var Locale */ @@ -84,6 +129,60 @@ protected function configure() InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), + new InputOption( + self::JAVASCRIPT_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no JavaScript will be deployed.' + ), + new InputOption( + self::CSS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no CSS will be deployed.' + ), + new InputOption( + self::LESS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no LESS will be deployed.' + ), + new InputOption( + self::IMAGES_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no images will be deployed.' + ), + new InputOption( + self::FONTS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no font files will be deployed.' + ), + new InputOption( + self::HTML_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no html files will be deployed.' + ), + new InputOption( + self::MISC_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no miscellaneous files will be deployed.' + ), + new InputOption( + self::HTML_MINIFY_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, just html will not be minified and actually deployed.' + ), + new InputOption( + self::THEMES_OPTION, + '-t', + InputOption::VALUE_IS_ARRAY + InputOption::VALUE_OPTIONAL, + 'If specified, just specific themes will be actually deployed.' + ), new InputArgument( self::LANGUAGE_OPTION, InputArgument::IS_ARRAY, @@ -91,6 +190,7 @@ protected function configure() ['en_US'] ), ]); + parent::configure(); } @@ -114,10 +214,43 @@ protected function execute(InputInterface $input, OutputInterface $output) // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); + $mageThemes = []; + $files = $filesUtil->getStaticPreProcessingFiles(); + foreach ($files as $info) { + list(, $themePath) = $info; + if ($themePath && !in_array($themePath, $mageThemes)) { + $mageThemes[] = $themePath; + } + } + + $themes = $input->getOption(self::THEMES_OPTION); + + foreach ($themes as $theme) { + + if ($theme != 'all' && !in_array($theme, $mageThemes)) { + throw new \InvalidArgumentException( + $theme . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageThemes) + ); + } + } + $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', - ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] + [ + 'filesUtil' => $filesUtil, + 'output' => $output, + 'isDryRun' => $options[self::DRY_RUN_OPTION], + 'isJavaScript' => $options[self::JAVASCRIPT_OPTION], + 'isCss' => $options[self::CSS_OPTION], + 'isLess' => $options[self::LESS_OPTION], + 'isImages' => $options[self::IMAGES_OPTION], + 'isFonts' => $options[self::FONTS_OPTION], + 'isHtml' => $options[self::HTML_OPTION], + 'isMisc' => $options[self::MISC_OPTION], + 'isHtmlMinify' => $options[self::HTML_MINIFY_OPTION] + ] ); - $deployer->deploy($this->objectManagerFactory, $languages); + + $deployer->deploy($this->objectManagerFactory, $languages, $themes); } } diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php old mode 100644 new mode 100755 index c1128f9ec5885..47545a063b8d3 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -50,6 +50,30 @@ class Deployer /** @var bool */ private $isDryRun; + /** @var bool */ + private $isJavaScript; + + /** @var bool */ + private $isCss; + + /** @var bool */ + private $isLess; + + /** @var bool */ + private $isImages; + + /** @var bool */ + private $isFonts; + + /** @var bool */ + private $isHtml; + + /** @var bool */ + private $isMisc; + + /** @var bool */ + private $isHtmlMinify; + /** @var int */ private $count; @@ -83,6 +107,13 @@ class Deployer * @param JsTranslationConfig $jsTranslationConfig * @param AlternativeSourceInterface[] $alternativeSources * @param bool $isDryRun + * @param bool $isJavaScript + * @param bool $isCss + * @param bool $isLess + * @param bool $isImages + * @param bool $isHtml + * @param bool $isFonts + * @param bool $isHtmlMinify */ public function __construct( Files $filesUtil, @@ -90,12 +121,28 @@ public function __construct( Version\StorageInterface $versionStorage, JsTranslationConfig $jsTranslationConfig, array $alternativeSources, - $isDryRun = false + $isDryRun = false, + $isJavaScript = false, + $isCss = false, + $isLess = false, + $isImages = false, + $isFonts = false, + $isHtml = false, + $isMisc = false, + $isHtmlMinify = false ) { $this->filesUtil = $filesUtil; $this->output = $output; $this->versionStorage = $versionStorage; $this->isDryRun = $isDryRun; + $this->isJavaScript = $isJavaScript; + $this->isCss = $isCss; + $this->isLess = $isLess; + $this->isImages = $isImages; + $this->isFonts = $isFonts; + $this->isHtml = $isHtml; + $this->isMisc = $isMisc; + $this->isHtmlMinify = $isHtmlMinify; $this->jsTranslationConfig = $jsTranslationConfig; $this->parentTheme = []; @@ -105,6 +152,42 @@ function (AlternativeSourceInterface $alternative) { $alternativeSources ); $this->alternativeSources = $alternativeSources; + + } + + /** + * Check if skip flag is affecting file by extension + * + * @param string $filePath + * @return boolean + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + private function checkSkip($filePath) { + $path = $filePath; + $ext = pathinfo($path, PATHINFO_EXTENSION); + + $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); + + if ($check && $filePath != '.') { + if ($this->isJavaScript && in_array($ext, array('js', 'map'))) { + return true; + } else if ($this->isCss && $ext == 'css') { + return true; + } else if ($this->isLess && $ext == 'less') { + return true; + } else if ($this->isHtml && in_array($ext, array('html', 'htm'))) { + return true; + } else if ($this->isImages && in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'ico', 'svg'))) { + return true; + } else if ($this->isFonts && in_array($ext, array('eot', 'svg', 'ttf', 'woff', 'woff2'))) { + return true; + } else if ($this->isMisc && in_array($ext, array('md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', ''))) { + return true; + } + + return false; + } } /** @@ -112,13 +195,16 @@ function (AlternativeSourceInterface $alternative) { * * @param ObjectManagerFactory $omFactory * @param array $locales + * @param array $themesArg * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales) + public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg) { + $this->omFactory = $omFactory; + if ($this->isDryRun) { $this->output->writeln('Dry run. Nothing will be recorded to the target directory.'); } @@ -131,6 +217,9 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) foreach ($locales as $locale) { $this->emulateApplicationLocale($locale, $area); foreach ($themes as $themePath) { + if (count($themes) && !in_array($themePath, $themesArg)) { + continue; + } $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); $this->count = 0; $this->errorCount = 0; @@ -162,6 +251,11 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) foreach ($appFiles as $info) { list($fileArea, $fileTheme, , $module, $filePath) = $info; + + if ($this->checkSkip($filePath)) { + continue; + } + if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array( @@ -176,42 +270,53 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) } } 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->jsTranslationConfig->dictionaryEnabled()) { - $this->deployFile( - $this->jsTranslationConfig->getDictionaryFileName(), - $area, - $themePath, - $locale, - null - ); + if (!$this->isJavaScript) { + if ($this->jsTranslationConfig->dictionaryEnabled()) { + $this->deployFile( + $this->jsTranslationConfig->getDictionaryFileName(), + $area, + $themePath, + $locale, + null + ); + } + $fileManager->clearBundleJsPool(); } - $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('.'); + if (!$this->isHtmlMinify) { + $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); } - $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); } } From 8216e1253cf4e42cd1c375392f0948c4e80c1410 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Mon, 25 Apr 2016 16:41:19 +0200 Subject: [PATCH 02/15] Revert "Revert "Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme"" This reverts commit 04ebbe796c2a11608581fecdf4d9b6645e19d2e1. --- .../Command/DeployStaticContentCommand.php | 137 ++++++++++++++- app/code/Magento/Deploy/Model/Deployer.php | 157 +++++++++++++++--- 2 files changed, 266 insertions(+), 28 deletions(-) mode change 100644 => 100755 app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php mode change 100644 => 100755 app/code/Magento/Deploy/Model/Deployer.php diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php old mode 100644 new mode 100755 index 470b92811e7d9..c3928a89b47db --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -31,6 +31,51 @@ class DeployStaticContentCommand extends Command */ const LANGUAGE_OPTION = 'languages'; + /** + * Key for javascript option + */ + const JAVASCRIPT_OPTION = 'no-javascript'; + + /** + * Key for css option + */ + const CSS_OPTION = 'no-css'; + + /** + * Key for less option + */ + const LESS_OPTION = 'no-less'; + + /** + * Key for images option + */ + const IMAGES_OPTION = 'no-images'; + + /** + * Key for fonts option + */ + const FONTS_OPTION = 'no-fonts'; + + /** + * Key for misc option + */ + const MISC_OPTION = 'no-misc'; + + /** + * Key for html option + */ + const HTML_OPTION = 'no-html'; + + /** + * Key for html option + */ + const HTML_MINIFY_OPTION = 'no-html-minify'; + + /** + * Key for themes option + */ + const THEMES_OPTION = 'themes'; + /** * @var Locale */ @@ -84,6 +129,60 @@ protected function configure() InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), + new InputOption( + self::JAVASCRIPT_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no JavaScript will be deployed.' + ), + new InputOption( + self::CSS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no CSS will be deployed.' + ), + new InputOption( + self::LESS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no LESS will be deployed.' + ), + new InputOption( + self::IMAGES_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no images will be deployed.' + ), + new InputOption( + self::FONTS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no font files will be deployed.' + ), + new InputOption( + self::HTML_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no html files will be deployed.' + ), + new InputOption( + self::MISC_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no miscellaneous files will be deployed.' + ), + new InputOption( + self::HTML_MINIFY_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, just html will not be minified and actually deployed.' + ), + new InputOption( + self::THEMES_OPTION, + '-t', + InputOption::VALUE_IS_ARRAY + InputOption::VALUE_OPTIONAL, + 'If specified, just specific themes will be actually deployed.' + ), new InputArgument( self::LANGUAGE_OPTION, InputArgument::IS_ARRAY, @@ -91,6 +190,7 @@ protected function configure() ['en_US'] ), ]); + parent::configure(); } @@ -114,10 +214,43 @@ protected function execute(InputInterface $input, OutputInterface $output) // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); + $mageThemes = []; + $files = $filesUtil->getStaticPreProcessingFiles(); + foreach ($files as $info) { + list(, $themePath) = $info; + if ($themePath && !in_array($themePath, $mageThemes)) { + $mageThemes[] = $themePath; + } + } + + $themes = $input->getOption(self::THEMES_OPTION); + + foreach ($themes as $theme) { + + if ($theme != 'all' && !in_array($theme, $mageThemes)) { + throw new \InvalidArgumentException( + $theme . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageThemes) + ); + } + } + $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', - ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] + [ + 'filesUtil' => $filesUtil, + 'output' => $output, + 'isDryRun' => $options[self::DRY_RUN_OPTION], + 'isJavaScript' => $options[self::JAVASCRIPT_OPTION], + 'isCss' => $options[self::CSS_OPTION], + 'isLess' => $options[self::LESS_OPTION], + 'isImages' => $options[self::IMAGES_OPTION], + 'isFonts' => $options[self::FONTS_OPTION], + 'isHtml' => $options[self::HTML_OPTION], + 'isMisc' => $options[self::MISC_OPTION], + 'isHtmlMinify' => $options[self::HTML_MINIFY_OPTION] + ] ); - $deployer->deploy($this->objectManagerFactory, $languages); + + $deployer->deploy($this->objectManagerFactory, $languages, $themes); } } diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php old mode 100644 new mode 100755 index c1128f9ec5885..47545a063b8d3 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -50,6 +50,30 @@ class Deployer /** @var bool */ private $isDryRun; + /** @var bool */ + private $isJavaScript; + + /** @var bool */ + private $isCss; + + /** @var bool */ + private $isLess; + + /** @var bool */ + private $isImages; + + /** @var bool */ + private $isFonts; + + /** @var bool */ + private $isHtml; + + /** @var bool */ + private $isMisc; + + /** @var bool */ + private $isHtmlMinify; + /** @var int */ private $count; @@ -83,6 +107,13 @@ class Deployer * @param JsTranslationConfig $jsTranslationConfig * @param AlternativeSourceInterface[] $alternativeSources * @param bool $isDryRun + * @param bool $isJavaScript + * @param bool $isCss + * @param bool $isLess + * @param bool $isImages + * @param bool $isHtml + * @param bool $isFonts + * @param bool $isHtmlMinify */ public function __construct( Files $filesUtil, @@ -90,12 +121,28 @@ public function __construct( Version\StorageInterface $versionStorage, JsTranslationConfig $jsTranslationConfig, array $alternativeSources, - $isDryRun = false + $isDryRun = false, + $isJavaScript = false, + $isCss = false, + $isLess = false, + $isImages = false, + $isFonts = false, + $isHtml = false, + $isMisc = false, + $isHtmlMinify = false ) { $this->filesUtil = $filesUtil; $this->output = $output; $this->versionStorage = $versionStorage; $this->isDryRun = $isDryRun; + $this->isJavaScript = $isJavaScript; + $this->isCss = $isCss; + $this->isLess = $isLess; + $this->isImages = $isImages; + $this->isFonts = $isFonts; + $this->isHtml = $isHtml; + $this->isMisc = $isMisc; + $this->isHtmlMinify = $isHtmlMinify; $this->jsTranslationConfig = $jsTranslationConfig; $this->parentTheme = []; @@ -105,6 +152,42 @@ function (AlternativeSourceInterface $alternative) { $alternativeSources ); $this->alternativeSources = $alternativeSources; + + } + + /** + * Check if skip flag is affecting file by extension + * + * @param string $filePath + * @return boolean + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + private function checkSkip($filePath) { + $path = $filePath; + $ext = pathinfo($path, PATHINFO_EXTENSION); + + $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); + + if ($check && $filePath != '.') { + if ($this->isJavaScript && in_array($ext, array('js', 'map'))) { + return true; + } else if ($this->isCss && $ext == 'css') { + return true; + } else if ($this->isLess && $ext == 'less') { + return true; + } else if ($this->isHtml && in_array($ext, array('html', 'htm'))) { + return true; + } else if ($this->isImages && in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'ico', 'svg'))) { + return true; + } else if ($this->isFonts && in_array($ext, array('eot', 'svg', 'ttf', 'woff', 'woff2'))) { + return true; + } else if ($this->isMisc && in_array($ext, array('md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', ''))) { + return true; + } + + return false; + } } /** @@ -112,13 +195,16 @@ function (AlternativeSourceInterface $alternative) { * * @param ObjectManagerFactory $omFactory * @param array $locales + * @param array $themesArg * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales) + public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg) { + $this->omFactory = $omFactory; + if ($this->isDryRun) { $this->output->writeln('Dry run. Nothing will be recorded to the target directory.'); } @@ -131,6 +217,9 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) foreach ($locales as $locale) { $this->emulateApplicationLocale($locale, $area); foreach ($themes as $themePath) { + if (count($themes) && !in_array($themePath, $themesArg)) { + continue; + } $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); $this->count = 0; $this->errorCount = 0; @@ -162,6 +251,11 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) foreach ($appFiles as $info) { list($fileArea, $fileTheme, , $module, $filePath) = $info; + + if ($this->checkSkip($filePath)) { + continue; + } + if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array( @@ -176,42 +270,53 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) } } 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->jsTranslationConfig->dictionaryEnabled()) { - $this->deployFile( - $this->jsTranslationConfig->getDictionaryFileName(), - $area, - $themePath, - $locale, - null - ); + if (!$this->isJavaScript) { + if ($this->jsTranslationConfig->dictionaryEnabled()) { + $this->deployFile( + $this->jsTranslationConfig->getDictionaryFileName(), + $area, + $themePath, + $locale, + null + ); + } + $fileManager->clearBundleJsPool(); } - $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('.'); + if (!$this->isHtmlMinify) { + $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); } - $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); } } From 478cc3e68b070ef35c5ef1f09faba838ea071bc8 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Mon, 25 Apr 2016 16:43:38 +0200 Subject: [PATCH 03/15] Revert "Revert "Revert "Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme""" This reverts commit 8216e1253cf4e42cd1c375392f0948c4e80c1410. --- .../Command/DeployStaticContentCommand.php | 137 +-------------- app/code/Magento/Deploy/Model/Deployer.php | 157 +++--------------- 2 files changed, 28 insertions(+), 266 deletions(-) mode change 100755 => 100644 app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php mode change 100755 => 100644 app/code/Magento/Deploy/Model/Deployer.php diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php old mode 100755 new mode 100644 index c3928a89b47db..470b92811e7d9 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -31,51 +31,6 @@ class DeployStaticContentCommand extends Command */ const LANGUAGE_OPTION = 'languages'; - /** - * Key for javascript option - */ - const JAVASCRIPT_OPTION = 'no-javascript'; - - /** - * Key for css option - */ - const CSS_OPTION = 'no-css'; - - /** - * Key for less option - */ - const LESS_OPTION = 'no-less'; - - /** - * Key for images option - */ - const IMAGES_OPTION = 'no-images'; - - /** - * Key for fonts option - */ - const FONTS_OPTION = 'no-fonts'; - - /** - * Key for misc option - */ - const MISC_OPTION = 'no-misc'; - - /** - * Key for html option - */ - const HTML_OPTION = 'no-html'; - - /** - * Key for html option - */ - const HTML_MINIFY_OPTION = 'no-html-minify'; - - /** - * Key for themes option - */ - const THEMES_OPTION = 'themes'; - /** * @var Locale */ @@ -129,60 +84,6 @@ protected function configure() InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), - new InputOption( - self::JAVASCRIPT_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no JavaScript will be deployed.' - ), - new InputOption( - self::CSS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no CSS will be deployed.' - ), - new InputOption( - self::LESS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no LESS will be deployed.' - ), - new InputOption( - self::IMAGES_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no images will be deployed.' - ), - new InputOption( - self::FONTS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no font files will be deployed.' - ), - new InputOption( - self::HTML_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no html files will be deployed.' - ), - new InputOption( - self::MISC_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no miscellaneous files will be deployed.' - ), - new InputOption( - self::HTML_MINIFY_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, just html will not be minified and actually deployed.' - ), - new InputOption( - self::THEMES_OPTION, - '-t', - InputOption::VALUE_IS_ARRAY + InputOption::VALUE_OPTIONAL, - 'If specified, just specific themes will be actually deployed.' - ), new InputArgument( self::LANGUAGE_OPTION, InputArgument::IS_ARRAY, @@ -190,7 +91,6 @@ protected function configure() ['en_US'] ), ]); - parent::configure(); } @@ -214,43 +114,10 @@ protected function execute(InputInterface $input, OutputInterface $output) // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); - $mageThemes = []; - $files = $filesUtil->getStaticPreProcessingFiles(); - foreach ($files as $info) { - list(, $themePath) = $info; - if ($themePath && !in_array($themePath, $mageThemes)) { - $mageThemes[] = $themePath; - } - } - - $themes = $input->getOption(self::THEMES_OPTION); - - foreach ($themes as $theme) { - - if ($theme != 'all' && !in_array($theme, $mageThemes)) { - throw new \InvalidArgumentException( - $theme . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageThemes) - ); - } - } - $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', - [ - 'filesUtil' => $filesUtil, - 'output' => $output, - 'isDryRun' => $options[self::DRY_RUN_OPTION], - 'isJavaScript' => $options[self::JAVASCRIPT_OPTION], - 'isCss' => $options[self::CSS_OPTION], - 'isLess' => $options[self::LESS_OPTION], - 'isImages' => $options[self::IMAGES_OPTION], - 'isFonts' => $options[self::FONTS_OPTION], - 'isHtml' => $options[self::HTML_OPTION], - 'isMisc' => $options[self::MISC_OPTION], - 'isHtmlMinify' => $options[self::HTML_MINIFY_OPTION] - ] + ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] ); - - $deployer->deploy($this->objectManagerFactory, $languages, $themes); + $deployer->deploy($this->objectManagerFactory, $languages); } } diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php old mode 100755 new mode 100644 index 47545a063b8d3..c1128f9ec5885 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -50,30 +50,6 @@ class Deployer /** @var bool */ private $isDryRun; - /** @var bool */ - private $isJavaScript; - - /** @var bool */ - private $isCss; - - /** @var bool */ - private $isLess; - - /** @var bool */ - private $isImages; - - /** @var bool */ - private $isFonts; - - /** @var bool */ - private $isHtml; - - /** @var bool */ - private $isMisc; - - /** @var bool */ - private $isHtmlMinify; - /** @var int */ private $count; @@ -107,13 +83,6 @@ class Deployer * @param JsTranslationConfig $jsTranslationConfig * @param AlternativeSourceInterface[] $alternativeSources * @param bool $isDryRun - * @param bool $isJavaScript - * @param bool $isCss - * @param bool $isLess - * @param bool $isImages - * @param bool $isHtml - * @param bool $isFonts - * @param bool $isHtmlMinify */ public function __construct( Files $filesUtil, @@ -121,28 +90,12 @@ public function __construct( Version\StorageInterface $versionStorage, JsTranslationConfig $jsTranslationConfig, array $alternativeSources, - $isDryRun = false, - $isJavaScript = false, - $isCss = false, - $isLess = false, - $isImages = false, - $isFonts = false, - $isHtml = false, - $isMisc = false, - $isHtmlMinify = false + $isDryRun = false ) { $this->filesUtil = $filesUtil; $this->output = $output; $this->versionStorage = $versionStorage; $this->isDryRun = $isDryRun; - $this->isJavaScript = $isJavaScript; - $this->isCss = $isCss; - $this->isLess = $isLess; - $this->isImages = $isImages; - $this->isFonts = $isFonts; - $this->isHtml = $isHtml; - $this->isMisc = $isMisc; - $this->isHtmlMinify = $isHtmlMinify; $this->jsTranslationConfig = $jsTranslationConfig; $this->parentTheme = []; @@ -152,42 +105,6 @@ function (AlternativeSourceInterface $alternative) { $alternativeSources ); $this->alternativeSources = $alternativeSources; - - } - - /** - * Check if skip flag is affecting file by extension - * - * @param string $filePath - * @return boolean - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - private function checkSkip($filePath) { - $path = $filePath; - $ext = pathinfo($path, PATHINFO_EXTENSION); - - $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); - - if ($check && $filePath != '.') { - if ($this->isJavaScript && in_array($ext, array('js', 'map'))) { - return true; - } else if ($this->isCss && $ext == 'css') { - return true; - } else if ($this->isLess && $ext == 'less') { - return true; - } else if ($this->isHtml && in_array($ext, array('html', 'htm'))) { - return true; - } else if ($this->isImages && in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'ico', 'svg'))) { - return true; - } else if ($this->isFonts && in_array($ext, array('eot', 'svg', 'ttf', 'woff', 'woff2'))) { - return true; - } else if ($this->isMisc && in_array($ext, array('md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', ''))) { - return true; - } - - return false; - } } /** @@ -195,16 +112,13 @@ private function checkSkip($filePath) { * * @param ObjectManagerFactory $omFactory * @param array $locales - * @param array $themesArg * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg) + 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.'); } @@ -217,9 +131,6 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t foreach ($locales as $locale) { $this->emulateApplicationLocale($locale, $area); foreach ($themes as $themePath) { - if (count($themes) && !in_array($themePath, $themesArg)) { - continue; - } $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); $this->count = 0; $this->errorCount = 0; @@ -251,11 +162,6 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t foreach ($appFiles as $info) { list($fileArea, $fileTheme, , $module, $filePath) = $info; - - if ($this->checkSkip($filePath)) { - continue; - } - if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array( @@ -270,53 +176,42 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t } } 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->isJavaScript) { - if ($this->jsTranslationConfig->dictionaryEnabled()) { - $this->deployFile( - $this->jsTranslationConfig->getDictionaryFileName(), - $area, - $themePath, - $locale, - null - ); - } - $fileManager->clearBundleJsPool(); + 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"); } } } - if (!$this->isHtmlMinify) { - $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); + $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); } } From fc77f20228a7e0335ec29c108ceca10884fee917 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Mon, 25 Apr 2016 16:40:35 +0200 Subject: [PATCH 04/15] Revert "Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme" This reverts commit 4e6548620f07fbbaa121f94ecd79d6b9d400b7c1. --- .../Command/DeployStaticContentCommand.php | 137 +-------------- app/code/Magento/Deploy/Model/Deployer.php | 157 +++--------------- 2 files changed, 28 insertions(+), 266 deletions(-) mode change 100755 => 100644 app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php mode change 100755 => 100644 app/code/Magento/Deploy/Model/Deployer.php diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php old mode 100755 new mode 100644 index c3928a89b47db..470b92811e7d9 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -31,51 +31,6 @@ class DeployStaticContentCommand extends Command */ const LANGUAGE_OPTION = 'languages'; - /** - * Key for javascript option - */ - const JAVASCRIPT_OPTION = 'no-javascript'; - - /** - * Key for css option - */ - const CSS_OPTION = 'no-css'; - - /** - * Key for less option - */ - const LESS_OPTION = 'no-less'; - - /** - * Key for images option - */ - const IMAGES_OPTION = 'no-images'; - - /** - * Key for fonts option - */ - const FONTS_OPTION = 'no-fonts'; - - /** - * Key for misc option - */ - const MISC_OPTION = 'no-misc'; - - /** - * Key for html option - */ - const HTML_OPTION = 'no-html'; - - /** - * Key for html option - */ - const HTML_MINIFY_OPTION = 'no-html-minify'; - - /** - * Key for themes option - */ - const THEMES_OPTION = 'themes'; - /** * @var Locale */ @@ -129,60 +84,6 @@ protected function configure() InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), - new InputOption( - self::JAVASCRIPT_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no JavaScript will be deployed.' - ), - new InputOption( - self::CSS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no CSS will be deployed.' - ), - new InputOption( - self::LESS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no LESS will be deployed.' - ), - new InputOption( - self::IMAGES_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no images will be deployed.' - ), - new InputOption( - self::FONTS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no font files will be deployed.' - ), - new InputOption( - self::HTML_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no html files will be deployed.' - ), - new InputOption( - self::MISC_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no miscellaneous files will be deployed.' - ), - new InputOption( - self::HTML_MINIFY_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, just html will not be minified and actually deployed.' - ), - new InputOption( - self::THEMES_OPTION, - '-t', - InputOption::VALUE_IS_ARRAY + InputOption::VALUE_OPTIONAL, - 'If specified, just specific themes will be actually deployed.' - ), new InputArgument( self::LANGUAGE_OPTION, InputArgument::IS_ARRAY, @@ -190,7 +91,6 @@ protected function configure() ['en_US'] ), ]); - parent::configure(); } @@ -214,43 +114,10 @@ protected function execute(InputInterface $input, OutputInterface $output) // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); - $mageThemes = []; - $files = $filesUtil->getStaticPreProcessingFiles(); - foreach ($files as $info) { - list(, $themePath) = $info; - if ($themePath && !in_array($themePath, $mageThemes)) { - $mageThemes[] = $themePath; - } - } - - $themes = $input->getOption(self::THEMES_OPTION); - - foreach ($themes as $theme) { - - if ($theme != 'all' && !in_array($theme, $mageThemes)) { - throw new \InvalidArgumentException( - $theme . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageThemes) - ); - } - } - $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', - [ - 'filesUtil' => $filesUtil, - 'output' => $output, - 'isDryRun' => $options[self::DRY_RUN_OPTION], - 'isJavaScript' => $options[self::JAVASCRIPT_OPTION], - 'isCss' => $options[self::CSS_OPTION], - 'isLess' => $options[self::LESS_OPTION], - 'isImages' => $options[self::IMAGES_OPTION], - 'isFonts' => $options[self::FONTS_OPTION], - 'isHtml' => $options[self::HTML_OPTION], - 'isMisc' => $options[self::MISC_OPTION], - 'isHtmlMinify' => $options[self::HTML_MINIFY_OPTION] - ] + ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] ); - - $deployer->deploy($this->objectManagerFactory, $languages, $themes); + $deployer->deploy($this->objectManagerFactory, $languages); } } diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php old mode 100755 new mode 100644 index 47545a063b8d3..c1128f9ec5885 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -50,30 +50,6 @@ class Deployer /** @var bool */ private $isDryRun; - /** @var bool */ - private $isJavaScript; - - /** @var bool */ - private $isCss; - - /** @var bool */ - private $isLess; - - /** @var bool */ - private $isImages; - - /** @var bool */ - private $isFonts; - - /** @var bool */ - private $isHtml; - - /** @var bool */ - private $isMisc; - - /** @var bool */ - private $isHtmlMinify; - /** @var int */ private $count; @@ -107,13 +83,6 @@ class Deployer * @param JsTranslationConfig $jsTranslationConfig * @param AlternativeSourceInterface[] $alternativeSources * @param bool $isDryRun - * @param bool $isJavaScript - * @param bool $isCss - * @param bool $isLess - * @param bool $isImages - * @param bool $isHtml - * @param bool $isFonts - * @param bool $isHtmlMinify */ public function __construct( Files $filesUtil, @@ -121,28 +90,12 @@ public function __construct( Version\StorageInterface $versionStorage, JsTranslationConfig $jsTranslationConfig, array $alternativeSources, - $isDryRun = false, - $isJavaScript = false, - $isCss = false, - $isLess = false, - $isImages = false, - $isFonts = false, - $isHtml = false, - $isMisc = false, - $isHtmlMinify = false + $isDryRun = false ) { $this->filesUtil = $filesUtil; $this->output = $output; $this->versionStorage = $versionStorage; $this->isDryRun = $isDryRun; - $this->isJavaScript = $isJavaScript; - $this->isCss = $isCss; - $this->isLess = $isLess; - $this->isImages = $isImages; - $this->isFonts = $isFonts; - $this->isHtml = $isHtml; - $this->isMisc = $isMisc; - $this->isHtmlMinify = $isHtmlMinify; $this->jsTranslationConfig = $jsTranslationConfig; $this->parentTheme = []; @@ -152,42 +105,6 @@ function (AlternativeSourceInterface $alternative) { $alternativeSources ); $this->alternativeSources = $alternativeSources; - - } - - /** - * Check if skip flag is affecting file by extension - * - * @param string $filePath - * @return boolean - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - private function checkSkip($filePath) { - $path = $filePath; - $ext = pathinfo($path, PATHINFO_EXTENSION); - - $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); - - if ($check && $filePath != '.') { - if ($this->isJavaScript && in_array($ext, array('js', 'map'))) { - return true; - } else if ($this->isCss && $ext == 'css') { - return true; - } else if ($this->isLess && $ext == 'less') { - return true; - } else if ($this->isHtml && in_array($ext, array('html', 'htm'))) { - return true; - } else if ($this->isImages && in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'ico', 'svg'))) { - return true; - } else if ($this->isFonts && in_array($ext, array('eot', 'svg', 'ttf', 'woff', 'woff2'))) { - return true; - } else if ($this->isMisc && in_array($ext, array('md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', ''))) { - return true; - } - - return false; - } } /** @@ -195,16 +112,13 @@ private function checkSkip($filePath) { * * @param ObjectManagerFactory $omFactory * @param array $locales - * @param array $themesArg * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg) + 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.'); } @@ -217,9 +131,6 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t foreach ($locales as $locale) { $this->emulateApplicationLocale($locale, $area); foreach ($themes as $themePath) { - if (count($themes) && !in_array($themePath, $themesArg)) { - continue; - } $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); $this->count = 0; $this->errorCount = 0; @@ -251,11 +162,6 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t foreach ($appFiles as $info) { list($fileArea, $fileTheme, , $module, $filePath) = $info; - - if ($this->checkSkip($filePath)) { - continue; - } - if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array( @@ -270,53 +176,42 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t } } 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->isJavaScript) { - if ($this->jsTranslationConfig->dictionaryEnabled()) { - $this->deployFile( - $this->jsTranslationConfig->getDictionaryFileName(), - $area, - $themePath, - $locale, - null - ); - } - $fileManager->clearBundleJsPool(); + 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"); } } } - if (!$this->isHtmlMinify) { - $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); + $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); } } From c1a09cd713128a44a26e4faa41e0cf98542b76dd Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Mon, 25 Apr 2016 16:47:13 +0200 Subject: [PATCH 05/15] Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme - fixed --- .../Command/DeployStaticContentCommand.php | 137 ++++++++++++++- app/code/Magento/Deploy/Model/Deployer.php | 157 +++++++++++++++--- 2 files changed, 266 insertions(+), 28 deletions(-) mode change 100644 => 100755 app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php mode change 100644 => 100755 app/code/Magento/Deploy/Model/Deployer.php diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php old mode 100644 new mode 100755 index 470b92811e7d9..c3928a89b47db --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -31,6 +31,51 @@ class DeployStaticContentCommand extends Command */ const LANGUAGE_OPTION = 'languages'; + /** + * Key for javascript option + */ + const JAVASCRIPT_OPTION = 'no-javascript'; + + /** + * Key for css option + */ + const CSS_OPTION = 'no-css'; + + /** + * Key for less option + */ + const LESS_OPTION = 'no-less'; + + /** + * Key for images option + */ + const IMAGES_OPTION = 'no-images'; + + /** + * Key for fonts option + */ + const FONTS_OPTION = 'no-fonts'; + + /** + * Key for misc option + */ + const MISC_OPTION = 'no-misc'; + + /** + * Key for html option + */ + const HTML_OPTION = 'no-html'; + + /** + * Key for html option + */ + const HTML_MINIFY_OPTION = 'no-html-minify'; + + /** + * Key for themes option + */ + const THEMES_OPTION = 'themes'; + /** * @var Locale */ @@ -84,6 +129,60 @@ protected function configure() InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), + new InputOption( + self::JAVASCRIPT_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no JavaScript will be deployed.' + ), + new InputOption( + self::CSS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no CSS will be deployed.' + ), + new InputOption( + self::LESS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no LESS will be deployed.' + ), + new InputOption( + self::IMAGES_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no images will be deployed.' + ), + new InputOption( + self::FONTS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no font files will be deployed.' + ), + new InputOption( + self::HTML_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no html files will be deployed.' + ), + new InputOption( + self::MISC_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no miscellaneous files will be deployed.' + ), + new InputOption( + self::HTML_MINIFY_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, just html will not be minified and actually deployed.' + ), + new InputOption( + self::THEMES_OPTION, + '-t', + InputOption::VALUE_IS_ARRAY + InputOption::VALUE_OPTIONAL, + 'If specified, just specific themes will be actually deployed.' + ), new InputArgument( self::LANGUAGE_OPTION, InputArgument::IS_ARRAY, @@ -91,6 +190,7 @@ protected function configure() ['en_US'] ), ]); + parent::configure(); } @@ -114,10 +214,43 @@ protected function execute(InputInterface $input, OutputInterface $output) // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); + $mageThemes = []; + $files = $filesUtil->getStaticPreProcessingFiles(); + foreach ($files as $info) { + list(, $themePath) = $info; + if ($themePath && !in_array($themePath, $mageThemes)) { + $mageThemes[] = $themePath; + } + } + + $themes = $input->getOption(self::THEMES_OPTION); + + foreach ($themes as $theme) { + + if ($theme != 'all' && !in_array($theme, $mageThemes)) { + throw new \InvalidArgumentException( + $theme . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageThemes) + ); + } + } + $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', - ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] + [ + 'filesUtil' => $filesUtil, + 'output' => $output, + 'isDryRun' => $options[self::DRY_RUN_OPTION], + 'isJavaScript' => $options[self::JAVASCRIPT_OPTION], + 'isCss' => $options[self::CSS_OPTION], + 'isLess' => $options[self::LESS_OPTION], + 'isImages' => $options[self::IMAGES_OPTION], + 'isFonts' => $options[self::FONTS_OPTION], + 'isHtml' => $options[self::HTML_OPTION], + 'isMisc' => $options[self::MISC_OPTION], + 'isHtmlMinify' => $options[self::HTML_MINIFY_OPTION] + ] ); - $deployer->deploy($this->objectManagerFactory, $languages); + + $deployer->deploy($this->objectManagerFactory, $languages, $themes); } } diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php old mode 100644 new mode 100755 index c1128f9ec5885..351f3c689331b --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -50,6 +50,30 @@ class Deployer /** @var bool */ private $isDryRun; + /** @var bool */ + private $isJavaScript; + + /** @var bool */ + private $isCss; + + /** @var bool */ + private $isLess; + + /** @var bool */ + private $isImages; + + /** @var bool */ + private $isFonts; + + /** @var bool */ + private $isHtml; + + /** @var bool */ + private $isMisc; + + /** @var bool */ + private $isHtmlMinify; + /** @var int */ private $count; @@ -83,6 +107,13 @@ class Deployer * @param JsTranslationConfig $jsTranslationConfig * @param AlternativeSourceInterface[] $alternativeSources * @param bool $isDryRun + * @param bool $isJavaScript + * @param bool $isCss + * @param bool $isLess + * @param bool $isImages + * @param bool $isHtml + * @param bool $isFonts + * @param bool $isHtmlMinify */ public function __construct( Files $filesUtil, @@ -90,12 +121,28 @@ public function __construct( Version\StorageInterface $versionStorage, JsTranslationConfig $jsTranslationConfig, array $alternativeSources, - $isDryRun = false + $isDryRun = false, + $isJavaScript = false, + $isCss = false, + $isLess = false, + $isImages = false, + $isFonts = false, + $isHtml = false, + $isMisc = false, + $isHtmlMinify = false ) { $this->filesUtil = $filesUtil; $this->output = $output; $this->versionStorage = $versionStorage; $this->isDryRun = $isDryRun; + $this->isJavaScript = $isJavaScript; + $this->isCss = $isCss; + $this->isLess = $isLess; + $this->isImages = $isImages; + $this->isFonts = $isFonts; + $this->isHtml = $isHtml; + $this->isMisc = $isMisc; + $this->isHtmlMinify = $isHtmlMinify; $this->jsTranslationConfig = $jsTranslationConfig; $this->parentTheme = []; @@ -105,6 +152,42 @@ function (AlternativeSourceInterface $alternative) { $alternativeSources ); $this->alternativeSources = $alternativeSources; + + } + + /** + * Check if skip flag is affecting file by extension + * + * @param string $filePath + * @return boolean + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + private function checkSkip($filePath) { + $path = $filePath; + $ext = pathinfo($path, PATHINFO_EXTENSION); + + $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); + + if ($check && $filePath != '.') { + if ($this->isJavaScript && in_array($ext, array('js', 'map'))) { + return true; + } else if ($this->isCss && $ext == 'css') { + return true; + } else if ($this->isLess && $ext == 'less') { + return true; + } else if ($this->isHtml && in_array($ext, array('html', 'htm'))) { + return true; + } else if ($this->isImages && in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'ico', 'svg'))) { + return true; + } else if ($this->isFonts && in_array($ext, array('eot', 'svg', 'ttf', 'woff', 'woff2'))) { + return true; + } else if ($this->isMisc && in_array($ext, array('md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', ''))) { + return true; + } + + return false; + } } /** @@ -112,13 +195,16 @@ function (AlternativeSourceInterface $alternative) { * * @param ObjectManagerFactory $omFactory * @param array $locales + * @param array $themesArg * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales) + public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg) { + $this->omFactory = $omFactory; + if ($this->isDryRun) { $this->output->writeln('Dry run. Nothing will be recorded to the target directory.'); } @@ -131,6 +217,9 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) foreach ($locales as $locale) { $this->emulateApplicationLocale($locale, $area); foreach ($themes as $themePath) { + if (count($themesArg) && !in_array($themePath, $themesArg)) { + continue; + } $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); $this->count = 0; $this->errorCount = 0; @@ -162,6 +251,11 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) foreach ($appFiles as $info) { list($fileArea, $fileTheme, , $module, $filePath) = $info; + + if ($this->checkSkip($filePath)) { + continue; + } + if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array( @@ -176,42 +270,53 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) } } 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->jsTranslationConfig->dictionaryEnabled()) { - $this->deployFile( - $this->jsTranslationConfig->getDictionaryFileName(), - $area, - $themePath, - $locale, - null - ); + if (!$this->isJavaScript) { + if ($this->jsTranslationConfig->dictionaryEnabled()) { + $this->deployFile( + $this->jsTranslationConfig->getDictionaryFileName(), + $area, + $themePath, + $locale, + null + ); + } + $fileManager->clearBundleJsPool(); } - $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('.'); + if (!$this->isHtmlMinify) { + $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); } - $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); } } From 1cb1c2d30335b09a00a5867053d4fab03da15a85 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Mon, 25 Apr 2016 17:09:58 +0200 Subject: [PATCH 06/15] Fixed code style, remarks by @adragus-inviqa --- app/code/Magento/Deploy/Model/Deployer.php | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 351f3c689331b..9d2c76f158034 100755 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -98,6 +98,27 @@ class Deployer */ private $alternativeSources; + /** @var array **/ + private $fileExtensionsJs = ['js', 'map']; + + /** @var array **/ + private $fileExtensionsCss = ['css']; + + /** @var array **/ + private $fileExtensionsLess = ['less']; + + /** @var array **/ + private $fileExtensionsHtml = ['html', 'htm']; + + /** @var array **/ + private $fileExtensionsImages = ['jpg', 'jpeg', 'gif', 'png', 'ico', 'svg']; + + /** @var array **/ + private $fileExtensionsFonts = ['eot', 'svg', 'ttf', 'woff', 'woff2']; + + /** @var array **/ + private $fileExtensionsMisc = ['md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', '']; + /** * Constructor * @@ -163,26 +184,27 @@ function (AlternativeSourceInterface $alternative) { * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - private function checkSkip($filePath) { + private function checkSkip($filePath) + { $path = $filePath; $ext = pathinfo($path, PATHINFO_EXTENSION); $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); if ($check && $filePath != '.') { - if ($this->isJavaScript && in_array($ext, array('js', 'map'))) { + if ($this->isJavaScript && in_array($ext, $this->fileExtensionsJs)) { return true; - } else if ($this->isCss && $ext == 'css') { + } elseif ($this->isCss && in_array($ext, $this->fileExtensionsCss)) { return true; - } else if ($this->isLess && $ext == 'less') { + } elseif ($this->isLess && in_array($ext, $this->fileExtensionsLess)) { return true; - } else if ($this->isHtml && in_array($ext, array('html', 'htm'))) { + } elseif ($this->isHtml && in_array($ext, $this->fileExtensionsJs)) { return true; - } else if ($this->isImages && in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'ico', 'svg'))) { + } elseif ($this->isImages && in_array($ext, $this->fileExtensionsImages)) { return true; - } else if ($this->isFonts && in_array($ext, array('eot', 'svg', 'ttf', 'woff', 'woff2'))) { + } elseif ($this->isFonts && in_array($ext, $this->fileExtensionsFonts)) { return true; - } else if ($this->isMisc && in_array($ext, array('md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', ''))) { + } elseif ($this->isMisc && in_array($ext, $this->fileExtensionsMisc)) { return true; } From 6b66db74c26103c8f9adc17fcbceccb9b1e4de4a Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Sat, 30 Apr 2016 13:34:16 +0200 Subject: [PATCH 07/15] Fixed method parameter instatiation when paramter is empty --- app/code/Magento/Deploy/Model/Deployer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 9d2c76f158034..06fea96897b73 100755 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -222,7 +222,7 @@ private function checkSkip($filePath) * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg) + public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg = []) { $this->omFactory = $omFactory; From 387f829c45f617d8d5e9bc8c2661bdd92bf57e78 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Thu, 23 Jun 2016 13:34:46 +0200 Subject: [PATCH 08/15] RENAMED --themes to -theme (@erikhansen suggestion) ADDDED --exclude-theme flag (@erikhansen suggestion) UPDATED --language flag (@giacmir) ADDED flags: --area (-a), --exclude-area (-ea), --exclude-language (-el), --exclude-theme (-et) ADDED flag shotcuts: -l, -el, -t, -et, -a, -ea ADDED check for wrong language, theme and/or area parameter value FIXED variable names, changet do camelCase --- .../Command/DeployStaticContentCommand.php | 203 +++++++++++++++--- app/code/Magento/Deploy/Model/Deployer.php | 42 ++-- 2 files changed, 197 insertions(+), 48 deletions(-) diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php index c3928a89b47db..748594bf946c5 100755 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -27,9 +27,14 @@ class DeployStaticContentCommand extends Command const DRY_RUN_OPTION = 'dry-run'; /** - * Key for languages parameter + * Key for language parameter */ - const LANGUAGE_OPTION = 'languages'; + const LANGUAGE_OPTION = 'language'; + + /** + * Key for exclude language parameter + */ + const EXCLUDE_LANGUAGE_OPTION = 'exclude-language'; /** * Key for javascript option @@ -72,9 +77,24 @@ class DeployStaticContentCommand extends Command const HTML_MINIFY_OPTION = 'no-html-minify'; /** - * Key for themes option + * Key for theme option */ - const THEMES_OPTION = 'themes'; + const THEME_OPTION = 'theme'; + + /** + * Key for exclude theme option + */ + const EXCLUDE_THEME_OPTION = 'exclude-theme'; + + /** + * Key for area option + */ + const AREA_OPTION = 'area'; + + /** + * Key for exclude area option + */ + const EXCLUDE_AREA_OPTION = 'exclude-area'; /** * @var Locale @@ -131,106 +151,221 @@ protected function configure() ), new InputOption( self::JAVASCRIPT_OPTION, - '', + null, InputOption::VALUE_NONE, 'If specified, no JavaScript will be deployed.' ), new InputOption( self::CSS_OPTION, - '', + null, InputOption::VALUE_NONE, 'If specified, no CSS will be deployed.' ), new InputOption( self::LESS_OPTION, - '', + null, InputOption::VALUE_NONE, 'If specified, no LESS will be deployed.' ), new InputOption( self::IMAGES_OPTION, - '', + null, InputOption::VALUE_NONE, 'If specified, no images will be deployed.' ), new InputOption( self::FONTS_OPTION, - '', + null, InputOption::VALUE_NONE, 'If specified, no font files will be deployed.' ), new InputOption( self::HTML_OPTION, - '', + null, InputOption::VALUE_NONE, 'If specified, no html files will be deployed.' ), new InputOption( self::MISC_OPTION, - '', + null, InputOption::VALUE_NONE, 'If specified, no miscellaneous files will be deployed.' ), new InputOption( self::HTML_MINIFY_OPTION, - '', + null, InputOption::VALUE_NONE, 'If specified, just html will not be minified and actually deployed.' ), new InputOption( - self::THEMES_OPTION, + self::THEME_OPTION, '-t', - InputOption::VALUE_IS_ARRAY + InputOption::VALUE_OPTIONAL, - 'If specified, just specific themes will be actually deployed.' + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, + 'If specified, just specific theme(s) will be actually deployed.', + ['all'] + ), + new InputOption( + self::EXCLUDE_THEME_OPTION, + '-et', + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, + 'If specified, exclude specific theme(s) from deployment.', + ['none'] ), - new InputArgument( + new InputOption( self::LANGUAGE_OPTION, - InputArgument::IS_ARRAY, - 'List of languages you want the tool populate files for.', - ['en_US'] + '-l', + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, + 'List of locales you want the tool populate files for.', + ['all'] + ), + new InputOption( + self::EXCLUDE_LANGUAGE_OPTION, + '-el', + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, + 'List of locales you do not want the tool populate files for.', + ['none'] + ), + new InputOption( + self::AREA_OPTION, + '-a', + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, + 'List of areas you want the tool populate files for.', + ['all'] + ), + new InputOption( + self::EXCLUDE_AREA_OPTION, + '-ea', + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, + 'List of areas you do not want the tool populate files for.', + ['none'] ), ]); parent::configure(); + } /** * {@inheritdoc} + * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { + $options = $input->getOptions(); - $languages = $input->getArgument(self::LANGUAGE_OPTION); - foreach ($languages as $lang) { + $excludeAreas = $input->getOption(self::EXCLUDE_AREA_OPTION); - if (!$this->validator->isValid($lang)) { - throw new \InvalidArgumentException( - $lang . ' argument has invalid value, please run info:language:list for list of available locales' - ); - } + $areas = $input->getOption(self::AREA_OPTION); + + if ($excludeAreas[0] != 'none' && $areas[0] != 'all') { + throw new \InvalidArgumentException( + '--area (-a) and --exclude-area (-ea) cannot be used at the same time' + ); + } + + $excludeLanguages = $input->getOption(self::EXCLUDE_LANGUAGE_OPTION); + + $languages = $input->getOption(self::LANGUAGE_OPTION); + + if ($excludeLanguages[0] != 'none' && $languages[0] != 'all') { + throw new \InvalidArgumentException( + '--language (-l) and --exclude-language (-el) cannot be used at the same time' + ); + } + + $excludeThemes = $input->getOption(self::EXCLUDE_THEME_OPTION); + + $themes = $input->getOption(self::THEME_OPTION); + + if ($excludeThemes[0] != 'none' && $themes[0] != 'all') { + throw new \InvalidArgumentException( + '--theme (-t) and --exclude-theme (-et) cannot be used at the same time' + ); } // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); + $mageAreas = []; $mageThemes = []; + $mageLanguages = ['en_US']; + $files = $filesUtil->getStaticPreProcessingFiles(); foreach ($files as $info) { - list(, $themePath) = $info; + list($area, $themePath, $locale) = $info; + if ($themePath && !in_array($themePath, $mageThemes)) { $mageThemes[] = $themePath; } + if ($locale && !in_array($locale, $mageLanguages)) { + $mageLanguages[] = $locale; + } + if ($area && !in_array($area, $mageAreas)) { + $mageAreas[] = $area; + } } - $themes = $input->getOption(self::THEMES_OPTION); + if ($languages[0] != 'all') { + foreach ($languages as $locale) { + if (!$this->validator->isValid($locale)) { + throw new \InvalidArgumentException( + $locale . ' argument has invalid value, please run info:language:list for list of available locales' + ); + } + } + } + + $deployLanguages = []; + foreach ($mageLanguages as $locale) { + if ($languages[0] != 'all' && in_array($locale, $languages)) { + $deployLanguages[] = $locale; + } elseif ($excludeLanguages[0] != 'none' && in_array($locale, $excludeLanguages)) { + continue; + } elseif ($languages[0] == 'all' && $excludeLanguages[0] == 'none') { + $deployLanguages[] = $locale; + } + } + + if ($themes[0] != 'all') { + foreach ($themes as $theme) { + if (!in_array($theme, $mageThemes)) { + throw new \InvalidArgumentException( + $theme . ' argument has invalid value, avalilable themes are: ' . implode(', ', $mageThemes) + ); + } + } + } + + $deployThemes = []; + foreach ($mageThemes as $theme) { + if ($themes[0] != 'all' && in_array($theme, $themes)) { + $deployThemes[] = $theme; + } elseif ($excludeThemes[0] != 'none' && in_array($theme, $excludeThemes)) { + continue; + } elseif ($themes[0] == 'all' && $excludeThemes[0] == 'none') { + $deployThemes[] = $theme; + } + } - foreach ($themes as $theme) { + if ($areas[0] != 'all') { + foreach ($areas as $area) { + if (!in_array($area, $mageAreas)) { + throw new \InvalidArgumentException( + $area . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageAreas) + ); + } + } + } - if ($theme != 'all' && !in_array($theme, $mageThemes)) { - throw new \InvalidArgumentException( - $theme . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageThemes) - ); + $deployAreas = []; + foreach ($mageAreas as $area) { + if ($areas[0] != 'all' && in_array($area, $areas)) { + $deployAreas[] = $area; + } elseif ($excludeAreas[0] != 'none' && in_array($area, $excludeAreas)) { + continue; + } elseif ($areas[0] == 'all' && $excludeAreas[0] == 'none') { + $deployAreas[] = $area; } } @@ -251,6 +386,6 @@ protected function execute(InputInterface $input, OutputInterface $output) ] ); - $deployer->deploy($this->objectManagerFactory, $languages, $themes); + $deployer->deploy($this->objectManagerFactory, $deployAreas, $deployLanguages, $deployThemes); } } diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 06fea96897b73..1c4a27850e3a4 100755 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -16,6 +16,7 @@ use Magento\Framework\Config\Theme; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Translate\Js\Config as JsTranslationConfig; +use Magento\TestFramework\Inspection\Exception; use Symfony\Component\Console\Output\OutputInterface; /** @@ -132,8 +133,9 @@ class Deployer * @param bool $isCss * @param bool $isLess * @param bool $isImages - * @param bool $isHtml * @param bool $isFonts + * @param bool $isHtml + * @param bool $isMisc * @param bool $isHtmlMinify */ public function __construct( @@ -216,13 +218,14 @@ private function checkSkip($filePath) * Populate all static view files for specified root path and list of languages * * @param ObjectManagerFactory $omFactory - * @param array $locales + * @param array $areasArg + * @param array $localesArg * @param array $themesArg * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg = []) + public function deploy(ObjectManagerFactory $omFactory, array $areasArg, array $localesArg, array $themesArg) { $this->omFactory = $omFactory; @@ -230,25 +233,36 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t 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}"); + + $areaList = implode(', ', $areasArg); + $this->output->writeln("Requested areas: {$areaList}"); + + $localeList = implode(', ', $localesArg); + $this->output->writeln("Requested languages: {$localeList}"); + + $themeList = implode(', ', $themesArg); + $this->output->writeln("Requested themes: {$themeList}"); + $libFiles = $this->filesUtil->getStaticLibraryFiles(); - list($areas, $appFiles) = $this->collectAppFiles($locales); - foreach ($areas as $area => $themes) { + list($areas, $appFiles) = $this->collectAppFiles($localesArg); + foreach ($areasArg as $area) { $this->emulateApplicationArea($area); - foreach ($locales as $locale) { + foreach ($localesArg as $locale) { $this->emulateApplicationLocale($locale, $area); - foreach ($themes as $themePath) { - if (count($themesArg) && !in_array($themePath, $themesArg)) { - continue; - } + foreach ($themesArg 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); + try { + $design = $this->objectManager->create('Magento\Theme\Model\View\Design'); + $design->setDesignTheme($themePath, $area); + } catch (\LogicException $e) { + continue; + } + $assetRepo = $this->objectManager->create( 'Magento\Framework\View\Asset\Repository', [ From 992553eaa540224b79e944f1396b9746be5e49c0 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Fri, 24 Jun 2016 11:41:08 +0200 Subject: [PATCH 09/15] merged with 2.1 codebase changed permissions as @hostep suggested --- .../Magento/Deploy/Console/Command/DeployStaticContentCommand.php | 0 app/code/Magento/Deploy/Model/Deployer.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php mode change 100755 => 100644 app/code/Magento/Deploy/Model/Deployer.php diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php old mode 100755 new mode 100644 diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php old mode 100755 new mode 100644 From 261f82ca2461367089af8579b20449db995878c7 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Mon, 25 Apr 2016 16:08:45 +0200 Subject: [PATCH 10/15] Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme --- .../Command/DeployStaticContentCommand.php | 139 +++++++++++++++- app/code/Magento/Deploy/Model/Deployer.php | 156 ++++++++++++++++-- 2 files changed, 276 insertions(+), 19 deletions(-) mode change 100644 => 100755 app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php mode change 100644 => 100755 app/code/Magento/Deploy/Model/Deployer.php diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php old mode 100644 new mode 100755 index a87fe24ec6a18..9579a9c5cbfa5 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -31,6 +31,51 @@ class DeployStaticContentCommand extends Command */ const LANGUAGE_OPTION = 'languages'; + /** + * Key for javascript option + */ + const JAVASCRIPT_OPTION = 'no-javascript'; + + /** + * Key for css option + */ + const CSS_OPTION = 'no-css'; + + /** + * Key for less option + */ + const LESS_OPTION = 'no-less'; + + /** + * Key for images option + */ + const IMAGES_OPTION = 'no-images'; + + /** + * Key for fonts option + */ + const FONTS_OPTION = 'no-fonts'; + + /** + * Key for misc option + */ + const MISC_OPTION = 'no-misc'; + + /** + * Key for html option + */ + const HTML_OPTION = 'no-html'; + + /** + * Key for html option + */ + const HTML_MINIFY_OPTION = 'no-html-minify'; + + /** + * Key for themes option + */ + const THEMES_OPTION = 'themes'; + /** * @var Locale */ @@ -84,6 +129,60 @@ protected function configure() InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), + new InputOption( + self::JAVASCRIPT_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no JavaScript will be deployed.' + ), + new InputOption( + self::CSS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no CSS will be deployed.' + ), + new InputOption( + self::LESS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no LESS will be deployed.' + ), + new InputOption( + self::IMAGES_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no images will be deployed.' + ), + new InputOption( + self::FONTS_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no font files will be deployed.' + ), + new InputOption( + self::HTML_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no html files will be deployed.' + ), + new InputOption( + self::MISC_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, no miscellaneous files will be deployed.' + ), + new InputOption( + self::HTML_MINIFY_OPTION, + '', + InputOption::VALUE_NONE, + 'If specified, just html will not be minified and actually deployed.' + ), + new InputOption( + self::THEMES_OPTION, + '-t', + InputOption::VALUE_IS_ARRAY + InputOption::VALUE_OPTIONAL, + 'If specified, just specific themes will be actually deployed.' + ), new InputArgument( self::LANGUAGE_OPTION, InputArgument::IS_ARRAY, @@ -91,6 +190,7 @@ protected function configure() ['en_US'] ), ]); + parent::configure(); } @@ -114,10 +214,47 @@ protected function execute(InputInterface $input, OutputInterface $output) // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); + $mageThemes = []; + $files = $filesUtil->getStaticPreProcessingFiles(); + foreach ($files as $info) { + list(, $themePath) = $info; + if ($themePath && !in_array($themePath, $mageThemes)) { + $mageThemes[] = $themePath; + } + } + + $themes = $input->getOption(self::THEMES_OPTION); + + foreach ($themes as $theme) { + + if ($theme != 'all' && !in_array($theme, $mageThemes)) { + throw new \InvalidArgumentException( + $theme . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageThemes) + ); + } + } + $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', - ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] + [ + 'filesUtil' => $filesUtil, + 'output' => $output, + 'isDryRun' => $options[self::DRY_RUN_OPTION], + 'isJavaScript' => $options[self::JAVASCRIPT_OPTION], + 'isCss' => $options[self::CSS_OPTION], + 'isLess' => $options[self::LESS_OPTION], + 'isImages' => $options[self::IMAGES_OPTION], + 'isFonts' => $options[self::FONTS_OPTION], + 'isHtml' => $options[self::HTML_OPTION], + 'isMisc' => $options[self::MISC_OPTION], + 'isHtmlMinify' => $options[self::HTML_MINIFY_OPTION] + ] ); +<<<<<<< 7e9d1812b6ecd31ff9d00f6b8de81aaf46bf4aad return $deployer->deploy($this->objectManagerFactory, $languages); +======= + + $deployer->deploy($this->objectManagerFactory, $languages, $themes); +>>>>>>> Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme } } diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php old mode 100644 new mode 100755 index 5ce8251db1e8b..51e6178c3b7f7 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -50,6 +50,30 @@ class Deployer /** @var bool */ private $isDryRun; + /** @var bool */ + private $isJavaScript; + + /** @var bool */ + private $isCss; + + /** @var bool */ + private $isLess; + + /** @var bool */ + private $isImages; + + /** @var bool */ + private $isFonts; + + /** @var bool */ + private $isHtml; + + /** @var bool */ + private $isMisc; + + /** @var bool */ + private $isHtmlMinify; + /** @var int */ private $count; @@ -83,6 +107,13 @@ class Deployer * @param JsTranslationConfig $jsTranslationConfig * @param AlternativeSourceInterface[] $alternativeSources * @param bool $isDryRun + * @param bool $isJavaScript + * @param bool $isCss + * @param bool $isLess + * @param bool $isImages + * @param bool $isHtml + * @param bool $isFonts + * @param bool $isHtmlMinify */ public function __construct( Files $filesUtil, @@ -90,12 +121,28 @@ public function __construct( Version\StorageInterface $versionStorage, JsTranslationConfig $jsTranslationConfig, array $alternativeSources, - $isDryRun = false + $isDryRun = false, + $isJavaScript = false, + $isCss = false, + $isLess = false, + $isImages = false, + $isFonts = false, + $isHtml = false, + $isMisc = false, + $isHtmlMinify = false ) { $this->filesUtil = $filesUtil; $this->output = $output; $this->versionStorage = $versionStorage; $this->isDryRun = $isDryRun; + $this->isJavaScript = $isJavaScript; + $this->isCss = $isCss; + $this->isLess = $isLess; + $this->isImages = $isImages; + $this->isFonts = $isFonts; + $this->isHtml = $isHtml; + $this->isMisc = $isMisc; + $this->isHtmlMinify = $isHtmlMinify; $this->jsTranslationConfig = $jsTranslationConfig; $this->parentTheme = []; @@ -105,6 +152,42 @@ function (AlternativeSourceInterface $alternative) { $alternativeSources ); $this->alternativeSources = $alternativeSources; + + } + + /** + * Check if skip flag is affecting file by extension + * + * @param string $filePath + * @return boolean + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + private function checkSkip($filePath) { + $path = $filePath; + $ext = pathinfo($path, PATHINFO_EXTENSION); + + $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); + + if ($check && $filePath != '.') { + if ($this->isJavaScript && in_array($ext, array('js', 'map'))) { + return true; + } else if ($this->isCss && $ext == 'css') { + return true; + } else if ($this->isLess && $ext == 'less') { + return true; + } else if ($this->isHtml && in_array($ext, array('html', 'htm'))) { + return true; + } else if ($this->isImages && in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'ico', 'svg'))) { + return true; + } else if ($this->isFonts && in_array($ext, array('eot', 'svg', 'ttf', 'woff', 'woff2'))) { + return true; + } else if ($this->isMisc && in_array($ext, array('md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', ''))) { + return true; + } + + return false; + } } /** @@ -112,13 +195,20 @@ function (AlternativeSourceInterface $alternative) { * * @param ObjectManagerFactory $omFactory * @param array $locales +<<<<<<< 7e9d1812b6ecd31ff9d00f6b8de81aaf46bf4aad * @return int +======= + * @param array $themesArg + * @return void +>>>>>>> Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales) + public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg) { + $this->omFactory = $omFactory; + if ($this->isDryRun) { $this->output->writeln('Dry run. Nothing will be recorded to the target directory.'); } @@ -131,6 +221,9 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) foreach ($locales as $locale) { $this->emulateApplicationLocale($locale, $area); foreach ($themes as $themePath) { + if (count($themes) && !in_array($themePath, $themesArg)) { + continue; + } $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); $this->count = 0; $this->errorCount = 0; @@ -160,6 +253,11 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) $fileManager->createRequireJsConfigAsset(); foreach ($appFiles as $info) { list($fileArea, $fileTheme, , $module, $filePath) = $info; + + if ($this->checkSkip($filePath)) { + continue; + } + if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array( @@ -174,37 +272,59 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) } } 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); } } +<<<<<<< 7e9d1812b6ecd31ff9d00f6b8de81aaf46bf4aad if ($this->jsTranslationConfig->dictionaryEnabled()) { $dictionaryFileName = $this->jsTranslationConfig->getDictionaryFileName(); $this->deployFile($dictionaryFileName, $area, $themePath, $locale, null); +======= + if (!$this->isJavaScript) { + if ($this->jsTranslationConfig->dictionaryEnabled()) { + $this->deployFile( + $this->jsTranslationConfig->getDictionaryFileName(), + $area, + $themePath, + $locale, + null + ); + } + $fileManager->clearBundleJsPool(); +>>>>>>> Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme } - $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('.'); + if (!$this->isHtmlMinify) { + $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); } - $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); } if ($this->errorCount > 0) { // we must have an exit code higher than zero to indicate something was wrong From 4f7f385833893315cc3d472fa74cddbc11b107d2 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Mon, 25 Apr 2016 16:40:35 +0200 Subject: [PATCH 11/15] Revert "Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme" This reverts commit 4e6548620f07fbbaa121f94ecd79d6b9d400b7c1. --- .../Command/DeployStaticContentCommand.php | 141 +--------------- app/code/Magento/Deploy/Model/Deployer.php | 158 +++--------------- 2 files changed, 21 insertions(+), 278 deletions(-) mode change 100755 => 100644 app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php mode change 100755 => 100644 app/code/Magento/Deploy/Model/Deployer.php diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php old mode 100755 new mode 100644 index 9579a9c5cbfa5..5a6de12fb84f1 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -31,51 +31,6 @@ class DeployStaticContentCommand extends Command */ const LANGUAGE_OPTION = 'languages'; - /** - * Key for javascript option - */ - const JAVASCRIPT_OPTION = 'no-javascript'; - - /** - * Key for css option - */ - const CSS_OPTION = 'no-css'; - - /** - * Key for less option - */ - const LESS_OPTION = 'no-less'; - - /** - * Key for images option - */ - const IMAGES_OPTION = 'no-images'; - - /** - * Key for fonts option - */ - const FONTS_OPTION = 'no-fonts'; - - /** - * Key for misc option - */ - const MISC_OPTION = 'no-misc'; - - /** - * Key for html option - */ - const HTML_OPTION = 'no-html'; - - /** - * Key for html option - */ - const HTML_MINIFY_OPTION = 'no-html-minify'; - - /** - * Key for themes option - */ - const THEMES_OPTION = 'themes'; - /** * @var Locale */ @@ -129,60 +84,6 @@ protected function configure() InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), - new InputOption( - self::JAVASCRIPT_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no JavaScript will be deployed.' - ), - new InputOption( - self::CSS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no CSS will be deployed.' - ), - new InputOption( - self::LESS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no LESS will be deployed.' - ), - new InputOption( - self::IMAGES_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no images will be deployed.' - ), - new InputOption( - self::FONTS_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no font files will be deployed.' - ), - new InputOption( - self::HTML_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no html files will be deployed.' - ), - new InputOption( - self::MISC_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, no miscellaneous files will be deployed.' - ), - new InputOption( - self::HTML_MINIFY_OPTION, - '', - InputOption::VALUE_NONE, - 'If specified, just html will not be minified and actually deployed.' - ), - new InputOption( - self::THEMES_OPTION, - '-t', - InputOption::VALUE_IS_ARRAY + InputOption::VALUE_OPTIONAL, - 'If specified, just specific themes will be actually deployed.' - ), new InputArgument( self::LANGUAGE_OPTION, InputArgument::IS_ARRAY, @@ -190,7 +91,6 @@ protected function configure() ['en_US'] ), ]); - parent::configure(); } @@ -214,47 +114,10 @@ protected function execute(InputInterface $input, OutputInterface $output) // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); - $mageThemes = []; - $files = $filesUtil->getStaticPreProcessingFiles(); - foreach ($files as $info) { - list(, $themePath) = $info; - if ($themePath && !in_array($themePath, $mageThemes)) { - $mageThemes[] = $themePath; - } - } - - $themes = $input->getOption(self::THEMES_OPTION); - - foreach ($themes as $theme) { - - if ($theme != 'all' && !in_array($theme, $mageThemes)) { - throw new \InvalidArgumentException( - $theme . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageThemes) - ); - } - } - $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', - [ - 'filesUtil' => $filesUtil, - 'output' => $output, - 'isDryRun' => $options[self::DRY_RUN_OPTION], - 'isJavaScript' => $options[self::JAVASCRIPT_OPTION], - 'isCss' => $options[self::CSS_OPTION], - 'isLess' => $options[self::LESS_OPTION], - 'isImages' => $options[self::IMAGES_OPTION], - 'isFonts' => $options[self::FONTS_OPTION], - 'isHtml' => $options[self::HTML_OPTION], - 'isMisc' => $options[self::MISC_OPTION], - 'isHtmlMinify' => $options[self::HTML_MINIFY_OPTION] - ] + ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] ); -<<<<<<< 7e9d1812b6ecd31ff9d00f6b8de81aaf46bf4aad return $deployer->deploy($this->objectManagerFactory, $languages); -======= - - $deployer->deploy($this->objectManagerFactory, $languages, $themes); ->>>>>>> Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme } -} +} \ No newline at end of file diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php old mode 100755 new mode 100644 index 51e6178c3b7f7..a8e2e3385cf71 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -50,30 +50,6 @@ class Deployer /** @var bool */ private $isDryRun; - /** @var bool */ - private $isJavaScript; - - /** @var bool */ - private $isCss; - - /** @var bool */ - private $isLess; - - /** @var bool */ - private $isImages; - - /** @var bool */ - private $isFonts; - - /** @var bool */ - private $isHtml; - - /** @var bool */ - private $isMisc; - - /** @var bool */ - private $isHtmlMinify; - /** @var int */ private $count; @@ -107,13 +83,6 @@ class Deployer * @param JsTranslationConfig $jsTranslationConfig * @param AlternativeSourceInterface[] $alternativeSources * @param bool $isDryRun - * @param bool $isJavaScript - * @param bool $isCss - * @param bool $isLess - * @param bool $isImages - * @param bool $isHtml - * @param bool $isFonts - * @param bool $isHtmlMinify */ public function __construct( Files $filesUtil, @@ -121,28 +90,12 @@ public function __construct( Version\StorageInterface $versionStorage, JsTranslationConfig $jsTranslationConfig, array $alternativeSources, - $isDryRun = false, - $isJavaScript = false, - $isCss = false, - $isLess = false, - $isImages = false, - $isFonts = false, - $isHtml = false, - $isMisc = false, - $isHtmlMinify = false + $isDryRun = false ) { $this->filesUtil = $filesUtil; $this->output = $output; $this->versionStorage = $versionStorage; $this->isDryRun = $isDryRun; - $this->isJavaScript = $isJavaScript; - $this->isCss = $isCss; - $this->isLess = $isLess; - $this->isImages = $isImages; - $this->isFonts = $isFonts; - $this->isHtml = $isHtml; - $this->isMisc = $isMisc; - $this->isHtmlMinify = $isHtmlMinify; $this->jsTranslationConfig = $jsTranslationConfig; $this->parentTheme = []; @@ -152,42 +105,6 @@ function (AlternativeSourceInterface $alternative) { $alternativeSources ); $this->alternativeSources = $alternativeSources; - - } - - /** - * Check if skip flag is affecting file by extension - * - * @param string $filePath - * @return boolean - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - private function checkSkip($filePath) { - $path = $filePath; - $ext = pathinfo($path, PATHINFO_EXTENSION); - - $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); - - if ($check && $filePath != '.') { - if ($this->isJavaScript && in_array($ext, array('js', 'map'))) { - return true; - } else if ($this->isCss && $ext == 'css') { - return true; - } else if ($this->isLess && $ext == 'less') { - return true; - } else if ($this->isHtml && in_array($ext, array('html', 'htm'))) { - return true; - } else if ($this->isImages && in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'ico', 'svg'))) { - return true; - } else if ($this->isFonts && in_array($ext, array('eot', 'svg', 'ttf', 'woff', 'woff2'))) { - return true; - } else if ($this->isMisc && in_array($ext, array('md', 'txt', 'jbf', 'csv', 'json', 'txt', 'htc', 'swf', 'LICENSE', ''))) { - return true; - } - - return false; - } } /** @@ -195,20 +112,13 @@ private function checkSkip($filePath) { * * @param ObjectManagerFactory $omFactory * @param array $locales -<<<<<<< 7e9d1812b6ecd31ff9d00f6b8de81aaf46bf4aad * @return int -======= - * @param array $themesArg - * @return void ->>>>>>> Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales, array $themesArg) + 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.'); } @@ -221,9 +131,6 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t foreach ($locales as $locale) { $this->emulateApplicationLocale($locale, $area); foreach ($themes as $themePath) { - if (count($themes) && !in_array($themePath, $themesArg)) { - continue; - } $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); $this->count = 0; $this->errorCount = 0; @@ -253,11 +160,6 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t $fileManager->createRequireJsConfigAsset(); foreach ($appFiles as $info) { list($fileArea, $fileTheme, , $module, $filePath) = $info; - - if ($this->checkSkip($filePath)) { - continue; - } - if (($fileArea == $area || $fileArea == 'base') && ($fileTheme == '' || $fileTheme == $themePath || in_array( @@ -272,59 +174,37 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $t } } 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); } } -<<<<<<< 7e9d1812b6ecd31ff9d00f6b8de81aaf46bf4aad if ($this->jsTranslationConfig->dictionaryEnabled()) { $dictionaryFileName = $this->jsTranslationConfig->getDictionaryFileName(); $this->deployFile($dictionaryFileName, $area, $themePath, $locale, null); -======= - if (!$this->isJavaScript) { - if ($this->jsTranslationConfig->dictionaryEnabled()) { - $this->deployFile( - $this->jsTranslationConfig->getDictionaryFileName(), - $area, - $themePath, - $locale, - null - ); - } - $fileManager->clearBundleJsPool(); ->>>>>>> Added flags to static deploy command to skip filetypes (js, css, less, images, fonts...) and filter by theme } + $fileManager->clearBundleJsPool(); $this->bundleManager->flush(); $this->output->writeln("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n"); } } } - if (!$this->isHtmlMinify) { - $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); + $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); } if ($this->errorCount > 0) { // we must have an exit code higher than zero to indicate something was wrong @@ -504,4 +384,4 @@ private function verboseLog($message) $this->output->writeln($message); } } -} +} \ No newline at end of file From bed14570414ed23850652d03b56d21d8c2cfaae5 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Fri, 24 Jun 2016 12:24:40 +0200 Subject: [PATCH 12/15] FIXED merge confilct --- .../Command/DeployStaticContentCommand.php | 30 ++++++++++------- app/code/Magento/Deploy/Model/Deployer.php | 32 ++++++------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php index 782092f08c079..fc51057b55335 100644 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -27,14 +27,14 @@ class DeployStaticContentCommand extends Command const DRY_RUN_OPTION = 'dry-run'; /** - * Key for language parameter + * Key for languages parameter */ - const LANGUAGE_OPTION = 'language'; + const LANGUAGE_OPTION = 'languages'; /** - * Key for exclude language parameter + * Key for exclude languages parameter */ - const EXCLUDE_LANGUAGE_OPTION = 'exclude-language'; + const EXCLUDE_LANGUAGE_OPTION = 'exclude-languages'; /** * Key for javascript option @@ -215,14 +215,14 @@ protected function configure() self::LANGUAGE_OPTION, '-l', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, - 'List of locales you want the tool populate files for.', + 'List of languages you want the tool populate files for.', ['all'] ), new InputOption( self::EXCLUDE_LANGUAGE_OPTION, '-el', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, - 'List of locales you do not want the tool populate files for.', + 'List of langiages you do not want the tool populate files for.', ['none'] ), new InputOption( @@ -284,6 +284,16 @@ protected function execute(InputInterface $input, OutputInterface $output) ); } + $languages = $input->getArgument(self::LANGUAGE_OPTION); + foreach ($languages as $lang) { + + if (!$this->validator->isValid($lang)) { + throw new \InvalidArgumentException( + $lang . ' argument has invalid value, please run info:language:list for list of available locales' + ); + } + } + // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); @@ -385,11 +395,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'isHtmlMinify' => $options[self::HTML_MINIFY_OPTION] ] ); -<<<<<<< HEAD - $deployer->deploy($this->objectManagerFactory, $deployAreas, $deployLanguages, $deployThemes); -======= - return $deployer->deploy($this->objectManagerFactory, $languages); ->>>>>>> develop + return $deployer->deploy($this->objectManagerFactory, $languages, $deployAreas, $deployLanguages, $deployThemes); } -} \ No newline at end of file +} diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 608140bf9cf85..a95c13839a5dd 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -16,7 +16,6 @@ use Magento\Framework\Config\Theme; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Translate\Js\Config as JsTranslationConfig; -use Magento\TestFramework\Inspection\Exception; use Symfony\Component\Console\Output\OutputInterface; /** @@ -218,19 +217,15 @@ private function checkSkip($filePath) * Populate all static view files for specified root path and list of languages * * @param ObjectManagerFactory $omFactory -<<<<<<< HEAD + * @param array $locales * @param array $areasArg * @param array $localesArg * @param array $themesArg - * @return void -======= - * @param array $locales * @return int ->>>>>>> develop * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $areasArg, array $localesArg, array $themesArg) + public function deploy(ObjectManagerFactory $omFactory, array $locales, array $areasArg = [], array $localesArg = [], array $themesArg = []) { $this->omFactory = $omFactory; @@ -242,8 +237,8 @@ public function deploy(ObjectManagerFactory $omFactory, array $areasArg, array $ $areaList = implode(', ', $areasArg); $this->output->writeln("Requested areas: {$areaList}"); - $localeList = implode(', ', $localesArg); - $this->output->writeln("Requested languages: {$localeList}"); + $langList = implode(', ', $localesArg); + $this->output->writeln("Requested languages: {$langList}"); $themeList = implode(', ', $themesArg); $this->output->writeln("Requested themes: {$themeList}"); @@ -259,6 +254,7 @@ public function deploy(ObjectManagerFactory $omFactory, array $areasArg, array $ $this->output->writeln("=== {$area} -> {$themePath} -> {$locale} ==="); $this->count = 0; $this->errorCount = 0; + /** @var \Magento\Theme\Model\View\Design $design */ try { $design = $this->objectManager->create('Magento\Theme\Model\View\Design'); @@ -288,6 +284,7 @@ public function deploy(ObjectManagerFactory $omFactory, array $areasArg, array $ ] ); $fileManager->createRequireJsConfigAsset(); + foreach ($appFiles as $info) { list($fileArea, $fileTheme, , $module, $filePath) = $info; @@ -321,23 +318,12 @@ public function deploy(ObjectManagerFactory $omFactory, array $areasArg, array $ $this->deployFile($compiledFile, $area, $themePath, $locale, null); } } -<<<<<<< HEAD if (!$this->isJavaScript) { if ($this->jsTranslationConfig->dictionaryEnabled()) { - $this->deployFile( - $this->jsTranslationConfig->getDictionaryFileName(), - $area, - $themePath, - $locale, - null - ); + $dictionaryFileName = $this->jsTranslationConfig->getDictionaryFileName(); + $this->deployFile($dictionaryFileName, $area, $themePath, $locale, null); } $fileManager->clearBundleJsPool(); -======= - if ($this->jsTranslationConfig->dictionaryEnabled()) { - $dictionaryFileName = $this->jsTranslationConfig->getDictionaryFileName(); - $this->deployFile($dictionaryFileName, $area, $themePath, $locale, null); ->>>>>>> develop } $this->bundleManager->flush(); $this->output->writeln("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n"); @@ -541,4 +527,4 @@ private function verboseLog($message) $this->output->writeln($message); } } -} \ No newline at end of file +} From 73f8b812ccc84374c7109a98ae0bcabc2fa17420 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Fri, 24 Jun 2016 13:06:14 +0200 Subject: [PATCH 13/15] FIXED Travis CI errors (PHPMD, PHPCS...) --- .../Command/DeployStaticContentCommand.php | 194 +++++++++--------- app/code/Magento/Deploy/Model/Deployer.php | 12 +- 2 files changed, 110 insertions(+), 96 deletions(-) diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php index fc51057b55335..420144fd24066 100644 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -143,97 +143,82 @@ protected function configure() $this->setName('setup:static-content:deploy') ->setDescription('Deploys static view files') ->setDefinition([ - new InputOption( - self::DRY_RUN_OPTION, + new InputOption(self::DRY_RUN_OPTION, '-d', InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), - new InputOption( - self::JAVASCRIPT_OPTION, + new InputOption(self::JAVASCRIPT_OPTION, null, InputOption::VALUE_NONE, 'If specified, no JavaScript will be deployed.' ), - new InputOption( - self::CSS_OPTION, + new InputOption(self::CSS_OPTION, null, InputOption::VALUE_NONE, 'If specified, no CSS will be deployed.' ), - new InputOption( - self::LESS_OPTION, + new InputOption(self::LESS_OPTION, null, InputOption::VALUE_NONE, 'If specified, no LESS will be deployed.' ), - new InputOption( - self::IMAGES_OPTION, + new InputOption(self::IMAGES_OPTION, null, InputOption::VALUE_NONE, 'If specified, no images will be deployed.' ), - new InputOption( - self::FONTS_OPTION, + new InputOption(self::FONTS_OPTION, null, InputOption::VALUE_NONE, 'If specified, no font files will be deployed.' ), - new InputOption( - self::HTML_OPTION, + new InputOption(self::HTML_OPTION, null, InputOption::VALUE_NONE, 'If specified, no html files will be deployed.' ), - new InputOption( - self::MISC_OPTION, + new InputOption(self::MISC_OPTION, null, InputOption::VALUE_NONE, 'If specified, no miscellaneous files will be deployed.' ), - new InputOption( - self::HTML_MINIFY_OPTION, + new InputOption(self::HTML_MINIFY_OPTION, null, InputOption::VALUE_NONE, 'If specified, just html will not be minified and actually deployed.' ), - new InputOption( - self::THEME_OPTION, + new InputOption(self::THEME_OPTION, '-t', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'If specified, just specific theme(s) will be actually deployed.', ['all'] ), - new InputOption( - self::EXCLUDE_THEME_OPTION, + new InputOption(self::EXCLUDE_THEME_OPTION, '-et', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'If specified, exclude specific theme(s) from deployment.', ['none'] ), - new InputOption( - self::LANGUAGE_OPTION, + new InputOption(self::LANGUAGE_OPTION, '-l', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'List of languages you want the tool populate files for.', ['all'] ), - new InputOption( - self::EXCLUDE_LANGUAGE_OPTION, + new InputOption(self::EXCLUDE_LANGUAGE_OPTION, '-el', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'List of langiages you do not want the tool populate files for.', ['none'] ), - new InputOption( - self::AREA_OPTION, + new InputOption(self::AREA_OPTION, '-a', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'List of areas you want the tool populate files for.', ['all'] ), - new InputOption( - self::EXCLUDE_AREA_OPTION, + new InputOption(self::EXCLUDE_AREA_OPTION, '-ea', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'List of areas you do not want the tool populate files for.', @@ -247,53 +232,83 @@ protected function configure() /** * {@inheritdoc} + * @param $areasInclude array + * @param $areasExclude array * @throws \InvalidArgumentException */ - protected function execute(InputInterface $input, OutputInterface $output) + private function checkAreasInput($areasInclude, $areasExclude) { - - $options = $input->getOptions(); - - $excludeAreas = $input->getOption(self::EXCLUDE_AREA_OPTION); - - $areas = $input->getOption(self::AREA_OPTION); - - if ($excludeAreas[0] != 'none' && $areas[0] != 'all') { + if ($areasInclude[0] != 'all' && $areasExclude[0] != 'none') { throw new \InvalidArgumentException( '--area (-a) and --exclude-area (-ea) cannot be used at the same time' ); } + } - $excludeLanguages = $input->getOption(self::EXCLUDE_LANGUAGE_OPTION); - - $languages = $input->getOption(self::LANGUAGE_OPTION); - - if ($excludeLanguages[0] != 'none' && $languages[0] != 'all') { + /** + * {@inheritdoc} + * @param $languagesInclude array + * @param $languagesExclude array + * @throws \InvalidArgumentException + */ + private function checkLanguagesInput($languagesInclude, $languagesExclude) + { + if ($languagesInclude[0] != 'all' && $languagesExclude[0] != 'none') { throw new \InvalidArgumentException( '--language (-l) and --exclude-language (-el) cannot be used at the same time' ); } + } - $excludeThemes = $input->getOption(self::EXCLUDE_THEME_OPTION); - - $themes = $input->getOption(self::THEME_OPTION); - - if ($excludeThemes[0] != 'none' && $themes[0] != 'all') { + /** + * {@inheritdoc} + * @param $themesInclude array + * @param $themesExclude array + * @throws \InvalidArgumentException + */ + private function checkThemesInput($themesInclude, $themesExclude) + { + if ($themesInclude[0] != 'all' && $themesExclude[0] != 'none') { throw new \InvalidArgumentException( '--theme (-t) and --exclude-theme (-et) cannot be used at the same time' ); } + } + + /** + * {@inheritdoc} + * @throws \InvalidArgumentException + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + + $options = $input->getOptions(); $languages = $input->getArgument(self::LANGUAGE_OPTION); - foreach ($languages as $lang) { + if ($languages[0] != 'all') { + foreach ($languages as $lang) { - if (!$this->validator->isValid($lang)) { - throw new \InvalidArgumentException( - $lang . ' argument has invalid value, please run info:language:list for list of available locales' - ); + if (!$this->validator->isValid($lang)) { + throw new \InvalidArgumentException( + $lang . + ' argument has invalid value, please run info:language:list for list of available locales' + ); + } } } + $areasInclude = $input->getOption(self::AREA_OPTION); + $areasExclude = $input->getOption(self::EXCLUDE_AREA_OPTION); + $this->checkAreasInput($areasInclude, $areasExclude); + + $languagesInclude = $input->getOption(self::LANGUAGE_OPTION); + $languagesExclude = $input->getOption(self::EXCLUDE_LANGUAGE_OPTION); + $this->checkLangugesInput($languagesInclude, $languagesExclude); + + $themesInclude = $input->getOption(self::THEME_OPTION); + $themesExclude = $input->getOption(self::EXCLUDE_THEME_OPTION); + $this->checkThemesInput($themesInclude, $themesExclude); + // run the deployment logic $filesUtil = $this->objectManager->create(Files::class); @@ -305,43 +320,56 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($files as $info) { list($area, $themePath, $locale) = $info; - if ($themePath && !in_array($themePath, $mageThemes)) { - $mageThemes[] = $themePath; + if ($area && !in_array($area, $mageAreas)) { + $mageAreas[] = $area; } if ($locale && !in_array($locale, $mageLanguages)) { $mageLanguages[] = $locale; } - if ($area && !in_array($area, $mageAreas)) { - $mageAreas[] = $area; + if ($themePath && !in_array($themePath, $mageThemes)) { + $mageThemes[] = $themePath; } } - if ($languages[0] != 'all') { - foreach ($languages as $locale) { - if (!$this->validator->isValid($locale)) { + if ($areasInclude[0] != 'all') { + foreach ($areasInclude as $area) { + if (!in_array($area, $mageAreas)) { throw new \InvalidArgumentException( - $locale . ' argument has invalid value, please run info:language:list for list of available locales' + $area . + ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageAreas) ); } } } + $deployAreas = []; + foreach ($mageAreas as $area) { + if ($areasInclude[0] != 'all' && in_array($area, $areasInclude)) { + $deployAreas[] = $area; + } elseif ($areasExclude[0] != 'none' && in_array($area, $areasExclude)) { + continue; + } elseif ($areasInclude[0] == 'all' && $areasExclude[0] == 'none') { + $deployAreas[] = $area; + } + } + $deployLanguages = []; foreach ($mageLanguages as $locale) { - if ($languages[0] != 'all' && in_array($locale, $languages)) { + if ($languagesInclude[0] != 'all' && in_array($locale, $languagesInclude)) { $deployLanguages[] = $locale; - } elseif ($excludeLanguages[0] != 'none' && in_array($locale, $excludeLanguages)) { + } elseif ($languagesExclude[0] != 'none' && in_array($locale, $languagesExclude)) { continue; - } elseif ($languages[0] == 'all' && $excludeLanguages[0] == 'none') { + } elseif ($languagesInclude[0] == 'all' && $languagesExclude[0] == 'none') { $deployLanguages[] = $locale; } } - if ($themes[0] != 'all') { - foreach ($themes as $theme) { + if ($themesInclude[0] != 'all') { + foreach ($themesInclude as $theme) { if (!in_array($theme, $mageThemes)) { throw new \InvalidArgumentException( - $theme . ' argument has invalid value, avalilable themes are: ' . implode(', ', $mageThemes) + $theme . + ' argument has invalid value, avalilable themes are: ' . implode(', ', $mageThemes) ); } } @@ -349,36 +377,15 @@ protected function execute(InputInterface $input, OutputInterface $output) $deployThemes = []; foreach ($mageThemes as $theme) { - if ($themes[0] != 'all' && in_array($theme, $themes)) { + if ($themesInclude[0] != 'all' && in_array($theme, $themesInclude)) { $deployThemes[] = $theme; - } elseif ($excludeThemes[0] != 'none' && in_array($theme, $excludeThemes)) { + } elseif ($themesExclude[0] != 'none' && in_array($theme, $themesExclude)) { continue; - } elseif ($themes[0] == 'all' && $excludeThemes[0] == 'none') { + } elseif ($themesInclude[0] == 'all' && $themesExclude[0] == 'none') { $deployThemes[] = $theme; } } - if ($areas[0] != 'all') { - foreach ($areas as $area) { - if (!in_array($area, $mageAreas)) { - throw new \InvalidArgumentException( - $area . ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageAreas) - ); - } - } - } - - $deployAreas = []; - foreach ($mageAreas as $area) { - if ($areas[0] != 'all' && in_array($area, $areas)) { - $deployAreas[] = $area; - } elseif ($excludeAreas[0] != 'none' && in_array($area, $excludeAreas)) { - continue; - } elseif ($areas[0] == 'all' && $excludeAreas[0] == 'none') { - $deployAreas[] = $area; - } - } - $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', [ @@ -396,6 +403,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ] ); - return $deployer->deploy($this->objectManagerFactory, $languages, $deployAreas, $deployLanguages, $deployThemes); + return $deployer->deploy($this->objectManagerFactory, $languages, + $deployAreas, $deployLanguages, $deployThemes); } } diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index a95c13839a5dd..6b8e3e6f60933 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -190,7 +190,13 @@ private function checkSkip($filePath) $path = $filePath; $ext = pathinfo($path, PATHINFO_EXTENSION); - $check = ($this->isJavaScript || $this->isCss || $this->isLess || $this->isHtml || $this->isImages || $this->isFonts || $this->isMisc); + $check = ($this->isJavaScript + || $this->isCss + || $this->isLess + || $this->isHtml + || $this->isImages + || $this->isFonts + || $this->isMisc); if ($check && $filePath != '.') { if ($this->isJavaScript && in_array($ext, $this->fileExtensionsJs)) { @@ -225,7 +231,8 @@ private function checkSkip($filePath) * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales, array $areasArg = [], array $localesArg = [], array $themesArg = []) + public function deploy(ObjectManagerFactory $omFactory, array $locales, + array $areasArg = [], array $localesArg = [], array $themesArg = []) { $this->omFactory = $omFactory; @@ -312,7 +319,6 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, array $a } $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, null); - if ($compiledFile !== '') { $this->deployFile($compiledFile, $area, $themePath, $locale, null); From f8b09105dcfb8a51db179247eed14a4c195e1b28 Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Fri, 24 Jun 2016 14:01:52 +0200 Subject: [PATCH 14/15] FIXED Avoid unused private fields such as '$fileExtensionsHtml'. FIXED Avoid unused private methods such as 'checkLanguagesInput' FIXED Avoid unused parameters such as '$locales'. FIXED restored original languages argument --- .../Command/DeployStaticContentCommand.php | 248 ++++++++++++------ app/code/Magento/Deploy/Model/Deployer.php | 4 +- 2 files changed, 174 insertions(+), 78 deletions(-) diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php index 420144fd24066..8332fa0ab8f9d 100644 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -29,12 +29,17 @@ class DeployStaticContentCommand extends Command /** * Key for languages parameter */ - const LANGUAGE_OPTION = 'languages'; + const LANGUAGES_OPTION = 'languages'; + + /** + * Key for languages parameter + */ + const LANGUAGE_OPTION = 'language'; /** * Key for exclude languages parameter */ - const EXCLUDE_LANGUAGE_OPTION = 'exclude-languages'; + const EXCLUDE_LANGUAGE_OPTION = 'exclude-language'; /** * Key for javascript option @@ -224,6 +229,12 @@ protected function configure() 'List of areas you do not want the tool populate files for.', ['none'] ), + new InputArgument( + self::LANGUAGES_OPTION, + InputArgument::IS_ARRAY, + 'List of languages you want the tool populate files for.', + ['en_US'] + ), ]); parent::configure(); @@ -232,118 +243,129 @@ protected function configure() /** * {@inheritdoc} + * @param $magentoAreas array * @param $areasInclude array * @param $areasExclude array * @throws \InvalidArgumentException */ - private function checkAreasInput($areasInclude, $areasExclude) + private function checkAreasInput($magentoAreas, $areasInclude, $areasExclude) { if ($areasInclude[0] != 'all' && $areasExclude[0] != 'none') { throw new \InvalidArgumentException( '--area (-a) and --exclude-area (-ea) cannot be used at the same time' ); } + + if ($areasInclude[0] != 'all') { + foreach ($areasInclude as $area) { + if (!in_array($area, $magentoAreas)) { + throw new \InvalidArgumentException( + $area . + ' argument has invalid value, avalilable areas are: ' . implode(', ', $magentoAreas) + ); + } + } + } + + if ($areasExclude[0] != 'none') { + foreach ($areasExclude as $area) { + if (!in_array($area, $magentoAreas)) { + throw new \InvalidArgumentException( + $area . + ' argument has invalid value, avalilable areas are: ' . implode(', ', $magentoAreas) + ); + } + } + } } /** * {@inheritdoc} + * @param $magentoLanguages array * @param $languagesInclude array * @param $languagesExclude array * @throws \InvalidArgumentException */ - private function checkLanguagesInput($languagesInclude, $languagesExclude) + private function checkLanguagesInput($magentoLanguages, $languagesInclude, $languagesExclude) { if ($languagesInclude[0] != 'all' && $languagesExclude[0] != 'none') { throw new \InvalidArgumentException( '--language (-l) and --exclude-language (-el) cannot be used at the same time' ); } + + if ($languagesInclude[0] != 'all') { + foreach ($languagedInclude as $language) { + if (!in_array($language, $magentoLanguages)) { + throw new \InvalidArgumentException( + $language . + ' argument has invalid value, avalilable languages are: ' . implode(', ', $magentoLanguages) + ); + } + } + } + + if ($languagesExclude[0] != 'none') { + foreach ($languagesExclude as $language) { + if (!in_array($language, $magentoLanguages)) { + throw new \InvalidArgumentException( + $language . + ' argument has invalid value, avalilable languages are: ' . implode(', ', $magentoLanguages) + ); + } + } + } } /** * {@inheritdoc} + * @param $magentoThemes array * @param $themesInclude array * @param $themesExclude array * @throws \InvalidArgumentException */ - private function checkThemesInput($themesInclude, $themesExclude) + private function checkThemesInput($magentoThemes, $themesInclude, $themesExclude) { if ($themesInclude[0] != 'all' && $themesExclude[0] != 'none') { throw new \InvalidArgumentException( '--theme (-t) and --exclude-theme (-et) cannot be used at the same time' ); } - } - - /** - * {@inheritdoc} - * @throws \InvalidArgumentException - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - - $options = $input->getOptions(); - $languages = $input->getArgument(self::LANGUAGE_OPTION); - if ($languages[0] != 'all') { - foreach ($languages as $lang) { - - if (!$this->validator->isValid($lang)) { + if ($themesInclude[0] != 'all') { + foreach ($themesInclude as $theme) { + if (!in_array($theme, $magentoThemes)) { throw new \InvalidArgumentException( - $lang . - ' argument has invalid value, please run info:language:list for list of available locales' + $theme . + ' argument has invalid value, avalilable themes are: ' . implode(', ', $magentoThemes) ); } } } - $areasInclude = $input->getOption(self::AREA_OPTION); - $areasExclude = $input->getOption(self::EXCLUDE_AREA_OPTION); - $this->checkAreasInput($areasInclude, $areasExclude); - - $languagesInclude = $input->getOption(self::LANGUAGE_OPTION); - $languagesExclude = $input->getOption(self::EXCLUDE_LANGUAGE_OPTION); - $this->checkLangugesInput($languagesInclude, $languagesExclude); - - $themesInclude = $input->getOption(self::THEME_OPTION); - $themesExclude = $input->getOption(self::EXCLUDE_THEME_OPTION); - $this->checkThemesInput($themesInclude, $themesExclude); - - // run the deployment logic - $filesUtil = $this->objectManager->create(Files::class); - - $mageAreas = []; - $mageThemes = []; - $mageLanguages = ['en_US']; - - $files = $filesUtil->getStaticPreProcessingFiles(); - foreach ($files as $info) { - list($area, $themePath, $locale) = $info; - - if ($area && !in_array($area, $mageAreas)) { - $mageAreas[] = $area; - } - if ($locale && !in_array($locale, $mageLanguages)) { - $mageLanguages[] = $locale; - } - if ($themePath && !in_array($themePath, $mageThemes)) { - $mageThemes[] = $themePath; - } - } - - if ($areasInclude[0] != 'all') { - foreach ($areasInclude as $area) { - if (!in_array($area, $mageAreas)) { + if ($themesExclude[0] != 'none') { + foreach ($themesExclude as $theme) { + if (!in_array($theme, $magentoThemes)) { throw new \InvalidArgumentException( - $area . - ' argument has invalid value, avalilable areas are: ' . implode(', ', $mageAreas) + $theme . + ' argument has invalid value, avalilable themes are: ' . implode(', ', $magentoThemes) ); } } } + } + /** + * {@inheritdoc} + * @param $magentoAreas array + * @param $areasInclude array + * @param $areasExclude array + * @return array + */ + private function getDeployAreas($magentoAreas, $areasInclude, $areasExclude) + { $deployAreas = []; - foreach ($mageAreas as $area) { + foreach ($magentoAreas as $area) { if ($areasInclude[0] != 'all' && in_array($area, $areasInclude)) { $deployAreas[] = $area; } elseif ($areasExclude[0] != 'none' && in_array($area, $areasExclude)) { @@ -352,40 +374,112 @@ protected function execute(InputInterface $input, OutputInterface $output) $deployAreas[] = $area; } } + return $deployAreas; + } + /** + * {@inheritdoc} + * @param $magentoLanguages array + * @param $languagesInclude array + * @param $languagesExclude array + * @return array + */ + private function getDeployLanguages($magentoLanguages, $languagesInclude, $languagesExclude) + { $deployLanguages = []; - foreach ($mageLanguages as $locale) { + foreach ($magentoLanguages as $locale) { if ($languagesInclude[0] != 'all' && in_array($locale, $languagesInclude)) { $deployLanguages[] = $locale; } elseif ($languagesExclude[0] != 'none' && in_array($locale, $languagesExclude)) { continue; - } elseif ($languagesInclude[0] == 'all' && $languagesExclude[0] == 'none') { + } elseif ($languagesInclude[0] == 'all' || $languagesExclude[0] == 'none') { $deployLanguages[] = $locale; } } + return $deployLanguages; + } - if ($themesInclude[0] != 'all') { - foreach ($themesInclude as $theme) { - if (!in_array($theme, $mageThemes)) { - throw new \InvalidArgumentException( - $theme . - ' argument has invalid value, avalilable themes are: ' . implode(', ', $mageThemes) - ); - } - } - } - + /** + * {@inheritdoc} + * @param $magentoThemes array + * @param $themesInclude array + * @param $themesExclude array + * @return array + */ + private function getDeployThemes($magentoThemes, $themesInclude, $themesExclude) + { $deployThemes = []; - foreach ($mageThemes as $theme) { + foreach ($magentoThemes as $theme) { if ($themesInclude[0] != 'all' && in_array($theme, $themesInclude)) { $deployThemes[] = $theme; } elseif ($themesExclude[0] != 'none' && in_array($theme, $themesExclude)) { continue; - } elseif ($themesInclude[0] == 'all' && $themesExclude[0] == 'none') { + } elseif ($themesInclude[0] == 'all' || $themesExclude[0] == 'none') { $deployThemes[] = $theme; } } + return $deployThemes; + } + + + /** + * {@inheritdoc} + * @throws \InvalidArgumentException + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + + $options = $input->getOptions(); + + $languages = $input->getArgument(self::LANGUAGES_OPTION); + if ($languages[0] != 'all') { + foreach ($languages as $lang) { + + if (!$this->validator->isValid($lang)) { + throw new \InvalidArgumentException( + $lang . + ' argument has invalid value, please run info:language:list for list of available locales' + ); + } + } + } + + // run the deployment logic + $filesUtil = $this->objectManager->create(Files::class); + + $magentoAreas = []; + $magentoThemes = []; + $magentoLanguages = ['en_US']; + + $files = $filesUtil->getStaticPreProcessingFiles(); + foreach ($files as $info) { + list($area, $themePath, $locale) = $info; + if ($area && !in_array($area, $magentoAreas)) { + $magentoAreas[] = $area; + } + if ($locale && !in_array($locale, $magentoLanguages)) { + $magentoLanguages[] = $locale; + } + if ($themePath && !in_array($themePath, $magentoThemes)) { + $magentoThemes[] = $themePath; + } + } + $areasInclude = $input->getOption(self::AREA_OPTION); + $areasExclude = $input->getOption(self::EXCLUDE_AREA_OPTION); + $this->checkAreasInput($magentoAreas, $areasInclude, $areasExclude); + $deployAreas = $this->getDeployAreas($magentoAreas, $areasInclude, $areasExclude); + + $languagesInclude = $input->getOption(self::LANGUAGE_OPTION); + $languagesExclude = $input->getOption(self::EXCLUDE_LANGUAGE_OPTION); + $this->checkLanguagesInput($magentoLanguages, $languagesInclude, $languagesExclude); + $deployLanguages = $this->getDeployLanguages($magentoLanguages, $languagesInclude, $languagesExclude); + + $themesInclude = $input->getOption(self::THEME_OPTION); + $themesExclude = $input->getOption(self::EXCLUDE_THEME_OPTION); + $this->checkThemesInput($magentoThemes, $themesInclude, $themesExclude); + $deployThemes = $this->getDeployThemes($magentoThemes, $themesInclude, $themesExclude); + $deployer = $this->objectManager->create( 'Magento\Deploy\Model\Deployer', [ diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 6b8e3e6f60933..8b586309e2e81 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -205,7 +205,7 @@ private function checkSkip($filePath) return true; } elseif ($this->isLess && in_array($ext, $this->fileExtensionsLess)) { return true; - } elseif ($this->isHtml && in_array($ext, $this->fileExtensionsJs)) { + } elseif ($this->isHtml && in_array($ext, $this->fileExtensionsHtml)) { return true; } elseif ($this->isImages && in_array($ext, $this->fileExtensionsImages)) { return true; @@ -249,6 +249,8 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales, $themeList = implode(', ', $themesArg); $this->output->writeln("Requested themes: {$themeList}"); + + $locales = null; $libFiles = $this->filesUtil->getStaticLibraryFiles(); list($areas, $appFiles) = $this->collectAppFiles($localesArg); From 6766de7828a90f7f6b9a1e813e0bf82d56fb647e Mon Sep 17 00:00:00 2001 From: Denis Ristic Date: Tue, 28 Jun 2016 15:53:15 +0200 Subject: [PATCH 15/15] FIXED Avoid unused local variables such as '$languagedInclude'. FIXED Invalid argument supplied for foreach() FIXED code style (PHPCS & PHPMD) --- .../Command/DeployStaticContentCommand.php | 95 +++++++++++-------- app/code/Magento/Deploy/Model/Deployer.php | 17 ++-- 2 files changed, 67 insertions(+), 45 deletions(-) diff --git a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php index 8332fa0ab8f9d..9d0154415e4e1 100644 --- a/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php +++ b/app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php @@ -148,82 +148,97 @@ protected function configure() $this->setName('setup:static-content:deploy') ->setDescription('Deploys static view files') ->setDefinition([ - new InputOption(self::DRY_RUN_OPTION, + new InputOption( + self::DRY_RUN_OPTION, '-d', InputOption::VALUE_NONE, 'If specified, then no files will be actually deployed.' ), - new InputOption(self::JAVASCRIPT_OPTION, + new InputOption( + self::JAVASCRIPT_OPTION, null, InputOption::VALUE_NONE, 'If specified, no JavaScript will be deployed.' ), - new InputOption(self::CSS_OPTION, + new InputOption( + self::CSS_OPTION, null, InputOption::VALUE_NONE, 'If specified, no CSS will be deployed.' ), - new InputOption(self::LESS_OPTION, + new InputOption( + self::LESS_OPTION, null, InputOption::VALUE_NONE, 'If specified, no LESS will be deployed.' ), - new InputOption(self::IMAGES_OPTION, + new InputOption( + self::IMAGES_OPTION, null, InputOption::VALUE_NONE, 'If specified, no images will be deployed.' ), - new InputOption(self::FONTS_OPTION, + new InputOption( + self::FONTS_OPTION, null, InputOption::VALUE_NONE, 'If specified, no font files will be deployed.' ), - new InputOption(self::HTML_OPTION, + new InputOption( + self::HTML_OPTION, null, InputOption::VALUE_NONE, 'If specified, no html files will be deployed.' ), - new InputOption(self::MISC_OPTION, + new InputOption( + self::MISC_OPTION, null, InputOption::VALUE_NONE, 'If specified, no miscellaneous files will be deployed.' ), - new InputOption(self::HTML_MINIFY_OPTION, + new InputOption( + self::HTML_MINIFY_OPTION, null, InputOption::VALUE_NONE, 'If specified, just html will not be minified and actually deployed.' ), - new InputOption(self::THEME_OPTION, + new InputOption( + self::THEME_OPTION, '-t', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'If specified, just specific theme(s) will be actually deployed.', ['all'] ), - new InputOption(self::EXCLUDE_THEME_OPTION, + new InputOption( + self::EXCLUDE_THEME_OPTION, '-et', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'If specified, exclude specific theme(s) from deployment.', ['none'] ), - new InputOption(self::LANGUAGE_OPTION, + new InputOption( + self::LANGUAGE_OPTION, '-l', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'List of languages you want the tool populate files for.', ['all'] ), - new InputOption(self::EXCLUDE_LANGUAGE_OPTION, + new InputOption( + self::EXCLUDE_LANGUAGE_OPTION, '-el', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'List of langiages you do not want the tool populate files for.', ['none'] ), - new InputOption(self::AREA_OPTION, + new InputOption( + self::AREA_OPTION, '-a', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'List of areas you want the tool populate files for.', ['all'] ), - new InputOption(self::EXCLUDE_AREA_OPTION, + new InputOption( + self::EXCLUDE_AREA_OPTION, '-ea', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'List of areas you do not want the tool populate files for.', @@ -260,7 +275,7 @@ private function checkAreasInput($magentoAreas, $areasInclude, $areasExclude) foreach ($areasInclude as $area) { if (!in_array($area, $magentoAreas)) { throw new \InvalidArgumentException( - $area . + $area . ' argument has invalid value, avalilable areas are: ' . implode(', ', $magentoAreas) ); } @@ -271,7 +286,7 @@ private function checkAreasInput($magentoAreas, $areasInclude, $areasExclude) foreach ($areasExclude as $area) { if (!in_array($area, $magentoAreas)) { throw new \InvalidArgumentException( - $area . + $area . ' argument has invalid value, avalilable areas are: ' . implode(', ', $magentoAreas) ); } @@ -295,10 +310,10 @@ private function checkLanguagesInput($magentoLanguages, $languagesInclude, $lang } if ($languagesInclude[0] != 'all') { - foreach ($languagedInclude as $language) { + foreach ($languagesInclude as $language) { if (!in_array($language, $magentoLanguages)) { throw new \InvalidArgumentException( - $language . + $language . ' argument has invalid value, avalilable languages are: ' . implode(', ', $magentoLanguages) ); } @@ -309,7 +324,7 @@ private function checkLanguagesInput($magentoLanguages, $languagesInclude, $lang foreach ($languagesExclude as $language) { if (!in_array($language, $magentoLanguages)) { throw new \InvalidArgumentException( - $language . + $language . ' argument has invalid value, avalilable languages are: ' . implode(', ', $magentoLanguages) ); } @@ -336,7 +351,7 @@ private function checkThemesInput($magentoThemes, $themesInclude, $themesExclude foreach ($themesInclude as $theme) { if (!in_array($theme, $magentoThemes)) { throw new \InvalidArgumentException( - $theme . + $theme . ' argument has invalid value, avalilable themes are: ' . implode(', ', $magentoThemes) ); } @@ -347,7 +362,7 @@ private function checkThemesInput($magentoThemes, $themesInclude, $themesExclude foreach ($themesExclude as $theme) { if (!in_array($theme, $magentoThemes)) { throw new \InvalidArgumentException( - $theme . + $theme . ' argument has invalid value, avalilable themes are: ' . implode(', ', $magentoThemes) ); } @@ -421,7 +436,6 @@ private function getDeployThemes($magentoThemes, $themesInclude, $themesExclude) return $deployThemes; } - /** * {@inheritdoc} * @throws \InvalidArgumentException @@ -437,7 +451,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$this->validator->isValid($lang)) { throw new \InvalidArgumentException( - $lang . + $lang . ' argument has invalid value, please run info:language:list for list of available locales' ); } @@ -452,16 +466,18 @@ protected function execute(InputInterface $input, OutputInterface $output) $magentoLanguages = ['en_US']; $files = $filesUtil->getStaticPreProcessingFiles(); - foreach ($files as $info) { - list($area, $themePath, $locale) = $info; - if ($area && !in_array($area, $magentoAreas)) { - $magentoAreas[] = $area; - } - if ($locale && !in_array($locale, $magentoLanguages)) { - $magentoLanguages[] = $locale; - } - if ($themePath && !in_array($themePath, $magentoThemes)) { - $magentoThemes[] = $themePath; + if (is_array($files)) { + foreach ($files as $info) { + list($area, $themePath, $locale) = $info; + if ($area && !in_array($area, $magentoAreas)) { + $magentoAreas[] = $area; + } + if ($locale && !in_array($locale, $magentoLanguages)) { + $magentoLanguages[] = $locale; + } + if ($themePath && !in_array($themePath, $magentoThemes)) { + $magentoThemes[] = $themePath; + } } } @@ -497,7 +513,12 @@ protected function execute(InputInterface $input, OutputInterface $output) ] ); - return $deployer->deploy($this->objectManagerFactory, $languages, - $deployAreas, $deployLanguages, $deployThemes); + return $deployer->deploy( + $this->objectManagerFactory, + $languages, + $deployAreas, + $deployLanguages, + $deployThemes + ); } -} +} \ No newline at end of file diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 8b586309e2e81..9984812a8c431 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -190,12 +190,12 @@ private function checkSkip($filePath) $path = $filePath; $ext = pathinfo($path, PATHINFO_EXTENSION); - $check = ($this->isJavaScript - || $this->isCss - || $this->isLess - || $this->isHtml - || $this->isImages - || $this->isFonts + $check = ($this->isJavaScript + || $this->isCss + || $this->isLess + || $this->isHtml + || $this->isImages + || $this->isFonts || $this->isMisc); if ($check && $filePath != '.') { @@ -231,8 +231,9 @@ private function checkSkip($filePath) * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function deploy(ObjectManagerFactory $omFactory, array $locales, - array $areasArg = [], array $localesArg = [], array $themesArg = []) + public function deploy(ObjectManagerFactory $omFactory, array $locales, + array $areasArg = [], array $localesArg = [], array $themesArg = [] + ) { $this->omFactory = $omFactory;