|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PrismX\Generators\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use PrismX\Generators\Blueprint; |
|
7
|
|
|
use PrismX\Generators\Support\CSFixer; |
|
8
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
9
|
|
|
use PrismX\Generators\Generators\SeedGenerator; |
|
10
|
|
|
use PrismX\Generators\Generators\ModelGenerator; |
|
11
|
|
|
use PrismX\Generators\Generators\FactoryGenerator; |
|
12
|
|
|
use PrismX\Generators\Generators\MigrationGenerator; |
|
13
|
|
|
use PrismX\Generators\Generators\NovaResourceGenerator; |
|
14
|
|
|
|
|
15
|
|
|
class Build extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
protected $signature = 'generator:build {blueprint=blueprint.yml}'; |
|
18
|
|
|
|
|
19
|
|
|
protected $description = 'Command description'; |
|
20
|
|
|
protected $blueprint = []; |
|
21
|
|
|
|
|
22
|
|
|
public function handle() |
|
23
|
|
|
{ |
|
24
|
|
|
$file = (string) $this->argument('blueprint'); |
|
25
|
|
|
if (! file_exists($file)) { |
|
26
|
|
|
$this->error("Blueprint file could not be found: {$file}"); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$this->blueprint = Blueprint::make($file); |
|
30
|
|
|
|
|
31
|
|
|
collect($this->blueprint)->mapWithKeys(function ($model) { |
|
32
|
|
|
return [ |
|
33
|
|
|
$model->name() => collect([ |
|
34
|
|
|
(new FactoryGenerator($model))->run(), |
|
35
|
|
|
(new MigrationGenerator($model))->run(), |
|
36
|
|
|
(new ModelGenerator($model))->run(), |
|
37
|
|
|
(new SeedGenerator($model))->run(), |
|
38
|
|
|
config('generators.nova_resources') ? (new NovaResourceGenerator($model))->run() : null, |
|
39
|
|
|
])->filter()->values(), |
|
40
|
|
|
]; |
|
41
|
|
|
})->filter(function ($model) { |
|
42
|
|
|
return ! $model->isEmpty(); |
|
43
|
|
|
})->each(function ($values, $model) { |
|
44
|
|
|
$table = new Table($this->output); |
|
45
|
|
|
$table->setHeaders([$model]); |
|
46
|
|
|
|
|
47
|
|
|
$table->setRows($values->map(function ($value) { |
|
48
|
|
|
return [$value]; |
|
49
|
|
|
})->toArray()); |
|
50
|
|
|
|
|
51
|
|
|
// Render the table to the output. |
|
52
|
|
|
$table->render(); |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
if (config('generators.cs_fixer')) { |
|
56
|
|
|
$this->info('Running CS Fixer...'); |
|
57
|
|
|
new CSFixer(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->info('Done.'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|