deInternetJongens /
Lighthouse-Utils
| 1 | <?php |
||
| 2 | |||
| 3 | namespace DeInternetJongens\LighthouseUtils\Console; |
||
| 4 | |||
| 5 | use DeInternetJongens\LighthouseUtils\Generators\SchemaGenerator; |
||
| 6 | use Illuminate\Console\Command; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @codeCoverageIgnore |
||
| 10 | */ |
||
| 11 | class GenerateSchemaCommand extends Command |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * The name and signature of the console command. |
||
| 15 | * |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | protected $signature = 'lighthouse-utils:generate-schema'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * The console command description. |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $description = 'Generates a new schema from seperate files and validate the generated schema.'; |
||
| 26 | |||
| 27 | /** @var SchemaGenerator */ |
||
| 28 | private $schemaGenerator; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param SchemaGenerator $schemaGenerator |
||
| 32 | */ |
||
| 33 | public function __construct(SchemaGenerator $schemaGenerator) |
||
| 34 | { |
||
| 35 | $this->schemaGenerator = $schemaGenerator; |
||
| 36 | parent::__construct(); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Execute the console command. |
||
| 41 | * |
||
| 42 | * @throws \Exception |
||
| 43 | */ |
||
| 44 | public function handle() |
||
| 45 | { |
||
| 46 | // Clear the Lighthouse cached schema |
||
| 47 | $this->call('lighthouse:clear-cache'); |
||
| 48 | |||
| 49 | $schemaFilePath = config('lighthouse.schema.register'); |
||
| 50 | $this->askWithCompletion( |
||
| 51 | sprintf( |
||
| 52 | 'Generating schema in location: "%s", do you want to continue?', |
||
| 53 | $schemaFilePath |
||
| 54 | ), |
||
| 55 | ['yes', 'no'], |
||
| 56 | 'yes' |
||
| 57 | ); |
||
| 58 | |||
| 59 | $schemaFilesPaths = config('lighthouse-utils.schema_paths'); |
||
| 60 | $generatedSchema = $this->schemaGenerator->generate($schemaFilesPaths); |
||
| 61 | |||
| 62 | $schemaFile = fopen($schemaFilePath, 'wb'); |
||
| 63 | fwrite($schemaFile, $generatedSchema); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 64 | |||
| 65 | $this->info('Generation complete.'); |
||
| 66 | } |
||
| 67 | } |
||
| 68 |