2024-09-07 00:03:11 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Lucent\Commands;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
use Lucent\Primitive\Collection;
|
|
|
|
|
use Lucent\Schema\FilesSchema;
|
|
|
|
|
|
|
|
|
|
class GenerateFileSchema extends Command
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected $signature = 'lucent:generate:file {name}';
|
|
|
|
|
|
|
|
|
|
protected $description = 'Generate a lucent file schema';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
$name = $this->argument('name');
|
|
|
|
|
$schema = new FilesSchema(
|
|
|
|
|
name: $name,
|
|
|
|
|
label: $name,
|
|
|
|
|
fields: Collection::make(),
|
2024-09-19 23:36:43 +03:00
|
|
|
disk: "lucent",
|
|
|
|
|
path: $name,
|
2024-09-07 00:03:11 +03:00
|
|
|
groups: []
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$json = json_encode($schema, JSON_PRETTY_PRINT);
|
|
|
|
|
$configDir = base_path(config('lucent.schemas_path'));
|
2024-10-04 19:26:19 +03:00
|
|
|
|
|
|
|
|
if(!file_exists($configDir)) {
|
|
|
|
|
$this->error("Your config directory \"$configDir\" doesn't exist. Create it first and run again");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-07 00:03:11 +03:00
|
|
|
$schemaPath = $configDir . "/" . $name . '.json';
|
|
|
|
|
|
2024-10-04 19:26:19 +03:00
|
|
|
|
2024-09-07 00:03:11 +03:00
|
|
|
if (file_exists($schemaPath)) {
|
|
|
|
|
$this->error("The schema file already exists.");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file_put_contents($schemaPath, $json);
|
|
|
|
|
$this->info("The schema file has been created.");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|