|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MagentoHackathon\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Magento\Framework\App\Filesystem\DirectoryList; |
|
|
|
|
|
|
6
|
|
|
use Magento\Framework\Filesystem; |
|
|
|
|
|
|
7
|
|
|
use MagentoHackathon\Api\GetModulePathFolderByNameInterface; |
|
8
|
|
|
use MagentoHackathon\FileCollector; |
|
9
|
|
|
use MagentoHackathon\Service\CheckDependency as CheckDependencyService; |
|
10
|
|
|
use MagentoHackathon\Service\GetModuleFolderByName; |
|
11
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
|
|
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @codeCoverageIgnore |
|
18
|
|
|
*/ |
|
19
|
|
|
class CheckDependency extends AbstractMagentoCommand |
|
20
|
|
|
{ |
|
21
|
|
|
const COMMAND_NAME = 'generate:dependencies'; |
|
22
|
|
|
|
|
23
|
|
|
const OPTION_EXT_DIR = 'extension-dir'; |
|
24
|
|
|
|
|
25
|
|
|
const OPTION_EXT_DIR_SHORT = 'x'; |
|
26
|
|
|
|
|
27
|
|
|
const OPTION_EXT_DIR_DECS = 'Folder name of the extension (e.g. module-catalog)'; |
|
28
|
|
|
|
|
29
|
|
|
const OPTION_EXT_PREFERENCE = 'local-magento-dependencies'; |
|
30
|
|
|
|
|
31
|
|
|
const OPTION_EXT_PREFERENCE_SHORT = 'l'; |
|
32
|
|
|
|
|
33
|
|
|
const OPTION_EXT_PREFERENCE_DESC = "All extension dependencies will be generated against the local magento version. \n" . |
|
34
|
|
|
"\t e.g. \"magento/module-customer\": \"^101.0.0\" \n" . |
|
35
|
|
|
"(If not set the version will be generated against magento 2.2 and 2.3 \n" . |
|
36
|
|
|
"e.g \"magento/module-customer\": \"^101.0.0|^102.0.0\")"; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var CheckDependencyService |
|
40
|
|
|
*/ |
|
41
|
|
|
private $checkDependency; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var GetModulePathFolderByNameInterface|GetModuleFolderByName |
|
44
|
|
|
*/ |
|
45
|
|
|
private $folderByName; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var FileCollector |
|
49
|
|
|
*/ |
|
50
|
|
|
private $fileCollector; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param CheckDependencyService $checkDependency |
|
54
|
|
|
* @param GetModuleFolderByName $folderByName |
|
55
|
|
|
*/ |
|
56
|
|
|
public function inject( |
|
57
|
|
|
CheckDependencyService $checkDependency, |
|
58
|
|
|
GetModuleFolderByName $folderByName, |
|
59
|
|
|
FileCollector $fileCollector |
|
60
|
|
|
) { |
|
61
|
|
|
$this->checkDependency = $checkDependency; |
|
62
|
|
|
$this->folderByName = $folderByName; |
|
63
|
|
|
$this->fileCollector = $fileCollector; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function configure() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->setName('extension:generate:dependencies') |
|
69
|
|
|
->addOption( |
|
70
|
|
|
self::OPTION_EXT_DIR, |
|
71
|
|
|
self::OPTION_EXT_DIR_SHORT, |
|
72
|
|
|
InputOption::VALUE_REQUIRED, |
|
73
|
|
|
self::OPTION_EXT_DIR_DECS |
|
74
|
|
|
) |
|
75
|
|
|
->addOption( |
|
76
|
|
|
self::OPTION_EXT_PREFERENCE, |
|
77
|
|
|
self::OPTION_EXT_PREFERENCE_SHORT, |
|
78
|
|
|
InputOption::VALUE_NONE, |
|
79
|
|
|
self::OPTION_EXT_PREFERENCE_DESC |
|
80
|
|
|
) |
|
81
|
|
|
->setDescription('This command will search for any soft and hard dependencies for the given extension and will generate a list of recommended composer dependencies.'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param InputInterface $input |
|
86
|
|
|
* @param OutputInterface $output |
|
87
|
|
|
* @return int|void |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function execute( |
|
90
|
|
|
InputInterface $input, |
|
91
|
|
|
OutputInterface $output |
|
92
|
|
|
) { |
|
93
|
|
|
$this->detectMagento($output); |
|
94
|
|
|
if ($this->initMagento($output)) { |
|
95
|
|
|
$moduleName = $this->getExtensionFolderName($input, $output); |
|
96
|
|
|
if ($moduleName === false) { |
|
97
|
|
|
return; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$modulePath = $this->folderByName->execute($moduleName); |
|
|
|
|
|
|
101
|
|
|
if ($modulePath === null) { |
|
102
|
|
|
$output->writeln('<info>Please provide a valid module name. </info>'); |
|
103
|
|
|
return; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
$relevantFiles = $this->fileCollector->getRelevantFiles($modulePath); |
|
107
|
|
|
$dependencyList = $this->checkDependency->execute($relevantFiles); |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
return $output; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param InputInterface $input |
|
114
|
|
|
* @param OutputInterface $output |
|
115
|
|
|
* @return bool|string |
|
116
|
|
|
*/ |
|
117
|
|
|
private function getExtensionFolderName( |
|
118
|
|
|
InputInterface $input, |
|
119
|
|
|
OutputInterface $output |
|
120
|
|
|
) { |
|
121
|
|
|
$extensionName = $input->getOption(self::OPTION_EXT_DIR); |
|
122
|
|
|
|
|
123
|
|
|
if (empty($extensionName)) { |
|
124
|
|
|
$output->writeln('<info>Please provide a folder name. </info>'); |
|
125
|
|
|
$output->writeln('<comment>n98-magerun2 ' . self::COMMAND_NAME . ' (-' . self::OPTION_EXT_DIR . '|-' . self::OPTION_EXT_DIR_SHORT . ') FOLDER_NAME</comment>'); |
|
126
|
|
|
return false; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$output->writeln('<info>Find extension by folder name : </info><comment>' . $extensionName . '</comment></info>'); |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
return $extensionName; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths