1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Prateekkarki\Laragen\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Prateekkarki\Laragen\Models\Module; |
7
|
|
|
use Prateekkarki\Laragen\Models\FileSystem; |
8
|
|
|
|
9
|
|
|
class Generate extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'laragen:make'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Generate code for your project'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Files to publish in development |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $filesToPublish = [ |
31
|
|
|
'css' => 'public', |
32
|
|
|
'js' => 'public', |
33
|
|
|
'fonts' => 'public', |
34
|
|
|
'stubs/Views/layouts/backend/app.stub' => 'resources/views/backend/layouts/app.blade.php', |
35
|
|
|
'stubs/Views/layouts/backend/login.stub' => 'resources/views/backend/auth/login.blade.php', |
36
|
|
|
'stubs/Controllers/backend/LoginController.stub' => 'app/Http/Controllers/Backend/Auth/LoginController.php', |
37
|
|
|
'stubs/Controllers/backend/DashboardController.stub' => 'app/Http/Controllers/Backend/DashboardController.php' |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Execute the console command. |
42
|
|
|
* |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function handle() |
46
|
|
|
{ |
47
|
|
|
$options = config('laragen')['options']; |
48
|
|
|
$modules = config('laragen')['modules']; |
49
|
|
|
|
50
|
|
|
$generatedFiles = []; |
51
|
|
|
$itemsToGenerate = array_diff($options['generated_by_default'], $options['skip_generators']); |
52
|
|
|
|
53
|
|
|
$bar = $this->output->createProgressBar(count($modules) * (count($itemsToGenerate) + count($this->filesToPublish))); |
54
|
|
|
$bar->setOverwrite(true); |
55
|
|
|
$bar->start(); |
56
|
|
|
|
57
|
|
|
$fs = new FileSystem(); |
58
|
|
|
|
59
|
|
|
foreach ($this->filesToPublish as $src => $dest) { |
60
|
|
|
$fs->clone($src, $dest); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
foreach ($modules as $moduleName => $moduleArray) { |
64
|
|
|
$moduleArray['name'] = $moduleName; |
65
|
|
|
$module = new Module($moduleArray); |
66
|
|
|
|
67
|
|
|
foreach ($itemsToGenerate as $item) { |
68
|
|
|
$generator = "\\Prateekkarki\\Laragen\\Generators\\{$item}"; |
69
|
|
|
$itemGenerator = new $generator($module); |
70
|
|
|
$returnedFiles = $itemGenerator->generate(); |
71
|
|
|
|
72
|
|
|
if (!is_array($returnedFiles)) |
73
|
|
|
$generatedFiles[] = $returnedFiles; |
74
|
|
|
else |
75
|
|
|
$generatedFiles = array_merge($generatedFiles, $returnedFiles); |
76
|
|
|
|
77
|
|
|
$bar->advance(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$bar->finish(); |
82
|
|
|
|
83
|
|
|
$this->line("\n"); |
84
|
|
|
|
85
|
|
|
foreach ($generatedFiles as $file) { |
86
|
|
|
$this->info("Generated file: ".str_replace(base_path()."\\", "", $file)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|