Skip to content

Commit

Permalink
DevThemeActiveCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
dvershinin committed Aug 29, 2019
1 parent 37fd761 commit 36a4ec2
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 13 deletions.
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`.


1 change: 1 addition & 0 deletions n98-magerun2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ autoloaders:
commands:
customCommands:
- GetPageSpeed\VarnishTunedCommand
- GetPageSpeed\DevThemeActiveCommand

63 changes: 63 additions & 0 deletions src/GetPageSpeed/DevThemeActiveCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace GetPageSpeed;

use N98\Magento\Command\AbstractMagentoCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Symfony\Component\Console\Input\InputOption;
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;

class DevThemeActiveCommand extends AbstractMagentoCommand
{

protected function configure()
{
$this
->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)
);
}
}
}
}

0 comments on commit 36a4ec2

Please # to comment.