1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UnikCodes\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use UnikCodes\Console\Commander; |
9
|
|
|
|
10
|
|
|
class MakeInstallCommand extends Commander |
11
|
|
|
{ |
12
|
|
|
public $name; |
13
|
|
|
public $path; |
14
|
|
|
public $stub_path; |
15
|
|
|
|
16
|
|
|
protected $configs = [ |
17
|
|
|
'medialibrary' => [ |
18
|
|
|
'app/Config' => 'Do update <info>path_generator</info> to <info>\App\Config\MediaPathGenerator::class</info> in <info>config/medialibrary.php</info>.', |
19
|
|
|
'app/Traits/HasMediaExtended.php' => 'You may add in your model <info>use \App\Models\HasMediaExtended;</info>', |
20
|
|
|
], |
21
|
|
|
'migration' => [ |
22
|
|
|
'database/migrations' => '<info>New migration installed.</info>', |
23
|
|
|
], |
24
|
|
|
'docs' => [ |
25
|
|
|
'docs/' => 'Now you have your application standard document on <info>Code of Conduct, Contributing, Issue Template and Pull Request Template.</info>', |
26
|
|
|
], |
27
|
|
|
'seeder' => [ |
28
|
|
|
'app/Traits/Seeds' => 'Now you have <info>Seeder Progress Bar</info> and <info>Seed Datum Trait.</info>', |
29
|
|
|
], |
30
|
|
|
'support' => [ |
31
|
|
|
'app/Support/' => 'Helpers are registered to you application. You may add as many helpers as you like in <info>app\Support</info> directory.', |
32
|
|
|
], |
33
|
|
|
'model' => [ |
34
|
|
|
'app/Models' => 'All models moved to <info>app/Models</info> and added <info>app/Models/Base</info>. Do update your <info>config/auth.php</info>. You may want to remove or update your existing User model in <info>app/</info>.', |
35
|
|
|
'stubs' => '<info>Model stub updated.</info>', |
36
|
|
|
], |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Configure the command options. |
41
|
|
|
*/ |
42
|
|
|
protected function configure() |
43
|
|
|
{ |
44
|
|
|
$this |
45
|
|
|
->setName('install') |
46
|
|
|
->setDescription('Install Ark component to existing Laravel project') |
47
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'Component name') |
48
|
|
|
->addArgument('path', InputArgument::REQUIRED, 'Path of the project to install the component'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Execute the command. |
53
|
|
|
*/ |
54
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
55
|
|
|
{ |
56
|
|
|
$this->name = $name = $input->getArgument('name'); |
57
|
|
|
$this->path = $path = rtrim($input->getArgument('path'), '/') . '/'; |
|
|
|
|
58
|
|
|
|
59
|
|
|
$this->stub_path = $stub_path = __DIR__ . '/../../stubs/'; |
60
|
|
|
|
61
|
|
|
if (! $this->filesystem->exists($path)) { |
62
|
|
|
$output->writeln('<comment>' . $path . ' does not exists!</comment>'); |
63
|
|
|
|
64
|
|
|
return 1; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (! $this->configs($name)) { |
68
|
|
|
throw new \Exception('Config not available.', 1); |
69
|
|
|
|
70
|
|
|
return 1; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$messages = []; |
74
|
|
|
foreach ($this->configs($name) as $file => $message) { |
75
|
|
|
$location = $stub_path . $file; |
76
|
|
|
|
77
|
|
|
if ($this->filesystem->isDirectory($location)) { |
78
|
|
|
$this->filesystem->copyDirectory($location, $path . $file); |
79
|
|
|
$messages[] = $message; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if ($this->filesystem->isFile($location)) { |
83
|
|
|
$this->filesystem->copy($location, $path . $file); |
84
|
|
|
$messages[] = $message; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$method = 'handle' . ucfirst($name); |
|
|
|
|
88
|
|
|
if (method_exists($this, $method)) { |
89
|
|
|
$this->{$method}(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$output->writeln('<comment>' . join($messages, PHP_EOL) . '</comment>'); |
|
|
|
|
94
|
|
|
|
95
|
|
|
return 0; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private function configs($name) |
99
|
|
|
{ |
100
|
|
|
if (! isset($this->configs[$name])) { |
101
|
|
|
return false; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $this->configs[$name]; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
private function handleSupport() |
108
|
|
|
{ |
109
|
|
|
$json = $this->getComposerConfig(rtrim($this->path, '/')); |
110
|
|
|
$json->autoload->files = ['app/Support/_.php']; |
111
|
|
|
|
112
|
|
|
$composer_file = $this->path . 'composer.json'; |
113
|
|
|
$this->filesystem->put($composer_file, json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
114
|
|
|
|
115
|
|
|
$current_directory = getcwd(); |
116
|
|
|
chdir($this->path); |
117
|
|
|
exec($this->findComposer() . ' dumpautoload -o -q'); |
118
|
|
|
chdir($current_directory); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|