Skip to content

Commit

Permalink
New CLI yireo_extensionchecker:list:modules (module name, enabled/d…
Browse files Browse the repository at this point in the history
…isabled, composer version)
  • Loading branch information
jissereitsma committed Jun 21, 2024
1 parent 7cea6c1 commit e85ae6d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

# [2.4.0] = 21 June 2024
### Added
- New CLI `yireo_extensionchecker:list:modules` (module name, enabled/disabled, composer version)

# [2.3.4] = 8 May 2024
### Fixed
- Do not pick up on nodes that are functions #54 @sprankhub
Expand Down
1 change: 0 additions & 1 deletion Composer/ComposerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function __construct(
public function getVersionByComposerName(string $composerName): string
{
$composerPackages = $this->getComposerPackages();

foreach ($composerPackages as $composerPackage) {
if ($composerPackage['name'] === $composerName) {
return $composerPackage['version'];
Expand Down
99 changes: 99 additions & 0 deletions Console/Command/ListModulesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);

namespace Yireo\ExtensionChecker\Console\Command;

use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Module\ModuleList;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface as Input;
use Symfony\Component\Console\Output\OutputInterface as Output;
use Yireo\ExtensionChecker\Composer\ComposerFileFactory;
use Yireo\ExtensionChecker\Composer\ComposerProvider;

class ListModulesCommand extends Command
{
public function __construct(
private ComponentRegistrar $componentRegistrar,
private ModuleList $moduleList,
private ComposerFileFactory $composerFileFactory,
private ComposerProvider $composerProvider,
?string $name = null)
{
parent::__construct($name);
}

/**
* Configure this command
*/
protected function configure()
{
$this->setName('yireo_extensionchecker:list:modules');
$this->setDescription('List all Magento modules');
}

/**
* @param Input $input
* @param Output $output
*
* @return int
*/
protected function execute(Input $input, Output $output): int
{
$table = new Table($output);
$table->setHeaders([
'Module',
'Status',
'Setup Version',
'Composer Version'
]);

$componentPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
$moduleNames = array_keys($componentPaths);

foreach ($moduleNames as $moduleName) {
$moduleInfo = $this->moduleList->getOne($moduleName);
$status = $moduleInfo ? 'enabled' : 'disabled';
$setupVersion = isset($moduleInfo['setup_version']) ? $moduleInfo['setup_version'] : '-';

$table->addRow([
$moduleName,
$status,
$setupVersion,
$this->getComposerVersion($moduleName)
]);
}

$table->render();

return Command::SUCCESS;
}

private function getComposerVersion(string $moduleName): string
{
$path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
$composerJsonFile = $path. '/composer.json';
if (false === file_exists($composerJsonFile)) {
$composerJsonFile = dirname($path).'/composer.json';
}

if (false === file_exists($composerJsonFile)) {
return '';
}

$composerFile = $this->composerFileFactory->create($composerJsonFile);

try {
$composerVersion = $composerFile->get('version');
if (!empty($composerVersion)) {
return $composerVersion;
}
} catch(RuntimeException) {}


$composerName = $composerFile->get('name');
return $this->composerProvider->getVersionByComposerName($composerName);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "yireo/magento2-extensionchecker",
"license": "OSL-3.0",
"type": "magento2-module",
"version": "2.3.4",
"version": "2.4.0",
"homepage": "https://github.com/yireo/Yireo_ExtensionChecker",
"description": "Scan the code of a Magento module",
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<item name="yireo_extensionchecker_list_classes" xsi:type="object">Yireo\ExtensionChecker\Console\Command\ListClassesCommand</item>
<item name="yireo_extensionchecker_create_plantuml_diagram" xsi:type="object">Yireo\ExtensionChecker\Console\Command\CreatePlantUmlDiagramCommand</item>
<item name="yireo_extensionchecker_check_magento_version" xsi:type="object">Yireo\ExtensionChecker\Console\Command\CheckMagentoVersionCommand</item>
<item name="yireo_extensionchecker_list_modules" xsi:type="object">Yireo\ExtensionChecker\Console\Command\ListModulesCommand</item>
</argument>
</arguments>
</type>
Expand Down

0 comments on commit e85ae6d

Please sign in to comment.