Skip to content

Commit

Permalink
Merge pull request #1 from iranimij/first-test-branch
Browse files Browse the repository at this point in the history
Initialize module.xml
  • Loading branch information
iranimij authored Nov 28, 2024
2 parents 23cb3fc + 78c7cd1 commit e192e6d
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 5 deletions.
80 changes: 80 additions & 0 deletions Console/Command/ScanCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace Iranimij\GitExtensionChecker\Console\Command;

use Magento\Framework\Filesystem\DirectoryList;
use SebastianFeldmann\Git\Repository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Iranimij\GitExtensionChecker\Model\Scan;

class ScanCommand extends Command
{
private Scan $scan;

private SerializerInterface $serializer;

public function __construct(
Scan $scan,
SerializerInterface $serializer,
private readonly DirectoryList $dir,
$name = null,
) {
parent::__construct($name);
$this->scan = $scan;
$this->serializer = $serializer;
}

protected function configure()
{
$this->setName('Iranimij_GitExtensionChecker:scan')
->setDescription('Scan a specific Magento module');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$gitRepository = new Repository($this->dir->getRoot());
$currentBranch = $gitRepository->getInfoOperator()->getCurrentBranch();
$diff = $gitRepository->getDiffOperator()->compare('main', $currentBranch);

foreach ($diff as $item) {
$explodedItem = explode('/', $item->getName());

if (empty($explodedItem[0]) || empty($explodedItem[1]) || empty($explodedItem[2])) {
continue;
}

$appModule = $this->dir->getRoot()
. "/$explodedItem[0]/$explodedItem[1]/$explodedItem[2]/$explodedItem[3]/registration.php";
$customModule = $this->dir->getRoot()
. "/$explodedItem[0]/$explodedItem[1]/$explodedItem[2]/registration.php";
if (
!file_exists($appModule)
&& !file_exists($customModule)
) {
continue;
}
$module = file_exists($appModule) ? $appModule : $customModule;
$content = file_get_contents($module);

if (empty($content)) {
continue;
}

preg_match("/'([^']+)'/", $content, $matches);
$moduleName = $matches[1] ?: '';
$greetInput = new ArrayInput([
'command' => 'yireo_extensionchecker:scan',
'--module' => $moduleName,
]);
$this->getApplication()->doRun($greetInput, $output);
}

return 1;
}
}
18 changes: 18 additions & 0 deletions Model/Scan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Iranimij\GitExtensionChecker\Model;

class Scan
{
public function performScan(string $moduleName, string $modulePath): array
{
// Implement the scan logic here
return [
'module' => $moduleName,
'path' => $modulePath,
'status' => 'success'
];
}
}
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"description": "Example module for Magento 2",
"require": {
"php": "~8.1.0||~8.2.0",
"magento/framework": "103.0.*"
"magento/framework": "103.0.*",
"sebastianfeldmann/git": "^3.1",
"yireo/magento2-extensionchecker": "^2.2"
},
"type": "magento2-module",
"version": "1.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand All @@ -16,7 +17,7 @@
"registration.php"
],
"psr-4": {
"Example\\Module\\": ""
"Iranimij\\GitExtensionChecker\\": ""
}
}
}
10 changes: 10 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="Iranimij_GitExtensionChecker:scan" xsi:type="object">Iranimij\GitExtensionChecker\Console\Command\ScanCommand</item>
</argument>
</arguments>
</type>
</config>
7 changes: 6 additions & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Example_Module" setup_version="1.0.0"/>
<module name="Iranimij_GitExtensionChecker" setup_version="1.0.0">
<sequence>
<module name="Magento_Framework"/>
<module name="Yireo_ExtensionChecker"/>
</sequence>
</module>
</config>
2 changes: 1 addition & 1 deletion registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Example_Module',
'Iranimij_GitExtensionChecker',
__DIR__
);

0 comments on commit e192e6d

Please sign in to comment.