|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HotRodCli\Commands\Module; |
|
4
|
|
|
|
|
5
|
|
|
use HotRodCli\Commands\BaseCommand; |
|
6
|
|
|
use HotRodCli\Jobs\Filesystem\CopyFiles; |
|
7
|
|
|
use HotRodCli\Jobs\Module\ReplaceText; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
class CreateCommand extends BaseCommand |
|
13
|
|
|
{ |
|
14
|
|
|
protected $jobs = [ |
|
15
|
|
|
CopyFiles::class => null, |
|
16
|
|
|
ReplaceText::class => null |
|
17
|
|
|
]; |
|
18
|
|
|
|
|
19
|
|
|
protected function configure() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->setName('module:create') |
|
22
|
|
|
->setDescription('Creates a new basic 3rd party module') |
|
23
|
|
|
->addArgument( |
|
24
|
|
|
'namespace', |
|
25
|
|
|
InputArgument::REQUIRED, |
|
26
|
|
|
'What is the namespace on the new module' |
|
27
|
|
|
) |
|
28
|
|
|
->setHelp('creates a new basic 3rd party module with given namespace'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->setJobs(); |
|
34
|
|
|
$namespace = explode('_', $input->getArgument('namespace')); |
|
35
|
|
|
|
|
36
|
|
|
try { |
|
37
|
|
|
$this->jobs[CopyFiles::class] |
|
38
|
|
|
->handle( |
|
39
|
|
|
$this->appContainer->get('resource_dir') . '/module', |
|
40
|
|
|
$this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
$this->jobs[ReplaceText::class] |
|
44
|
|
|
->handle( |
|
45
|
|
|
'{{Namespace_Module_xml}}', |
|
46
|
|
|
$input->getArgument('namespace'), |
|
47
|
|
|
$this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
$output->writeln('<info>Module ' . $input->getArgument('namespace') . ' was successfully created</info>'); |
|
51
|
|
|
} catch (\Throwable $e) { |
|
52
|
|
|
$output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|