|
1
|
|
|
<?php |
|
2
|
|
|
namespace Prateekkarki\Laragen\Commands; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Console\Command; |
|
5
|
|
|
use Prateekkarki\Laragen\Models\LaragenOptions; |
|
6
|
|
|
use Prateekkarki\Laragen\Models\FileSystem; |
|
7
|
|
|
|
|
8
|
|
|
class Generate extends Command |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The name and signature of the console command. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $signature = 'laragen:make'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The console command description. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $description = 'Generate code for your project'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Execute the console command. |
|
26
|
|
|
* |
|
27
|
|
|
* @return mixed |
|
28
|
|
|
*/ |
|
29
|
|
|
public function handle() |
|
30
|
|
|
{ |
|
31
|
|
|
$laragen = LaragenOptions::getInstance(); |
|
32
|
|
|
$modules = $laragen->getModules(); |
|
33
|
|
|
$generators = $laragen->getGenerators(); |
|
34
|
|
|
$generatedFiles = []; |
|
35
|
|
|
$fileSystem = new FileSystem(); |
|
36
|
|
|
|
|
37
|
|
|
$this->line(" |
|
38
|
|
|
██▓ ▄▄▄ ██▀███ ▄▄▄ ▄████ ▓█████ ███▄ █ |
|
39
|
|
|
▓██▒ ▒████▄ ▓██ ▒ ██▒▒████▄ ██▒ ▀█▒▓█ ▀ ██ ▀█ █ |
|
40
|
|
|
▒██░ ▒██ ▀█▄ ▓██ ░▄█ ▒▒██ ▀█▄ ▒██░▄▄▄░▒███ ▓██ ▀█ ██▒ |
|
41
|
|
|
▒██░ ░██▄▄▄▄██ ▒██▀▀█▄ ░██▄▄▄▄██ ░▓█ ██▓▒▓█ ▄ ▓██▒ ▐▌██▒ |
|
42
|
|
|
░██████▒▓█ ▓██▒░██▓ ▒██▒ ▓█ ▓██▒░▒▓███▀▒░▒████▒▒██░ ▓██░ |
|
43
|
|
|
░ ▒░▓ ░▒▒ ▓▒█░░ ▒▓ ░▒▓░ ▒▒ ▓▒█░ ░▒ ▒ ░░ ▒░ ░░ ▒░ ▒ ▒ |
|
44
|
|
|
░ ░ ▒ ░ ▒ ▒▒ ░ ░▒ ░ ▒░ ▒ ▒▒ ░ ░ ░ ░ ░ ░░ ░░ ░ ▒░ |
|
45
|
|
|
░ ░ ░ ▒ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ |
|
46
|
|
|
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ |
|
47
|
|
|
"); |
|
48
|
|
|
|
|
49
|
|
|
$this->line("Cleaning code directory ..."); |
|
50
|
|
|
|
|
51
|
|
|
foreach ([base_path('laragen/app'), base_path('laragen/database')] as $dir) { |
|
52
|
|
|
if(file_exists($dir)){ |
|
53
|
|
|
$fileSystem->removeDir($dir); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->line("Generating code..."); |
|
58
|
|
|
$bar = $this->output->createProgressBar(count($modules) * count($generators)); |
|
59
|
|
|
$bar->setOverwrite(true); |
|
60
|
|
|
$bar->start(); |
|
61
|
|
|
|
|
62
|
|
|
foreach ($modules as $module) { |
|
63
|
|
|
|
|
64
|
|
|
foreach ($generators as $generator) { |
|
65
|
|
|
$itemGenerator = new $generator($module); |
|
66
|
|
|
$returnedFiles = $itemGenerator->generate(); |
|
67
|
|
|
|
|
68
|
|
|
if (!is_array($returnedFiles)) |
|
69
|
|
|
$generatedFiles[] = $returnedFiles; |
|
70
|
|
|
else |
|
71
|
|
|
$generatedFiles = array_merge($generatedFiles, $returnedFiles); |
|
72
|
|
|
|
|
73
|
|
|
$bar->advance(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
$bar->finish(); |
|
77
|
|
|
|
|
78
|
|
|
$this->line("\n"); |
|
79
|
|
|
|
|
80
|
|
|
foreach ($generatedFiles as $key => $file) { |
|
81
|
|
|
\Log::info("Generated file: ".str_replace(base_path()."\\", "", $file)); |
|
82
|
|
|
} |
|
83
|
|
|
$this->info((isset($key) ? ++$key : 0)." files generated. Check log for details."); |
|
84
|
|
|
$this->info("Cheers!!!"); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|