diff --git a/README.md b/README.md index 405b861..1a7c60f 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,6 @@ This is a small (hopefully expanding in the future) collection of commands for `n98-magerun2`. -## Installation - -### Quick install for CentOS 7 - -This will install our [RPM repository](https://www.getpagespeed.com/redhat), `n98-magerun2` and the module: - - yum install https://extras.getpagespeed.com/release-el7-latest.rpm - yum install n98-magerun2-module-getpagespeed - -### Other platforms - -Just place the files over to `/usr/local/share/n98-magerun2`. - ## Commands available ### `n98-magerun2 varnish:tuned` @@ -29,3 +16,33 @@ Largest product category has this number of products: 1715 | 36015 | 60591 | 93359 | +-------------------+----------------+-------------------+ ``` + +### `n98-magerun2 dev:theme:active` + +Allows to get list of used themes. Example output (suitable for deploy static command): + + --theme Swissup/argento-pure2 + +This is useful for scripts to facilitate faster builds. + +Many Magento 2 themes come bundled with many actual themes, and deploying static assets takes huge time. +All because you unnecessarily minify a ton of CSS and Javascript files for themes which are not even in use! + +You can deploy just the used themes with: + + bin/magento setup:static-content:deploy --theme Magento/backend $(n98-magerun2 dev:theme:active) + +## Installation + +### Quick install for CentOS 7 + +This will install our [RPM repository](https://www.getpagespeed.com/redhat), `n98-magerun2` and the module: + + yum install https://extras.getpagespeed.com/release-el7-latest.rpm + yum install n98-magerun2-module-getpagespeed + +### Other platforms + +Just place the files over to `/usr/local/share/n98-magerun2`. + + diff --git a/n98-magerun2.yaml b/n98-magerun2.yaml index 7ad3b65..6db17e9 100644 --- a/n98-magerun2.yaml +++ b/n98-magerun2.yaml @@ -3,4 +3,5 @@ autoloaders: commands: customCommands: - GetPageSpeed\VarnishTunedCommand + - GetPageSpeed\DevThemeActiveCommand diff --git a/src/GetPageSpeed/DevThemeActiveCommand.php b/src/GetPageSpeed/DevThemeActiveCommand.php new file mode 100644 index 0000000..607b88b --- /dev/null +++ b/src/GetPageSpeed/DevThemeActiveCommand.php @@ -0,0 +1,63 @@ +setName('dev:theme:active') + ->setDescription('Get list of used themes') + ->addOption( + 'format', + null, + InputOption::VALUE_OPTIONAL, + 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']' + ) + ; + } + + /** + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->detectMagento($output); + if ($this->initMagento()) { + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager + $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); + $connection = $resource->getConnection(); + + $themeTableName = $resource->getTableName('theme'); //gives table name with prefix + $configTableName = $resource->getTableName('core_config_data'); + $sql = sprintf('SELECT theme_path FROM `%s` LEFT JOIN `%s` ON `value` = `theme_id` WHERE `path`=\'design/theme/theme_id\'', + $themeTableName, $configTableName); + $res = $connection->fetchCol($sql); + + if (!$input->getOption('format')) { + $out = array(); + foreach ($res as $t) { + $out[] = '--theme ' . $t; + } + $output->writeln(implode(' ', $out)); + } + + if ($input->getOption('format') == 'json') { + $output->writeln( + json_encode($res, JSON_PRETTY_PRINT) + ); + } + } + } +}