helper commands

This commit is contained in:
2024-09-07 00:03:11 +03:00
parent 6fc0a65b6f
commit cf3d621587
3 changed files with 88 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace Lucent\Commands;
use Illuminate\Console\Command;
use Lucent\Primitive\Collection;
use Lucent\Schema\CollectionSchema;
class GenerateCollectionSchema extends Command
{
protected $signature = 'lucent:generate:collection {name}';
protected $description = 'Generate a lucent collection';
public function handle()
{
$name = $this->argument('name');
$schema = new CollectionSchema(
name: $name,
label: $name,
visible: [],
groups: [],
fields: Collection::make(),
);
$json = json_encode($schema, JSON_PRETTY_PRINT);
$configDir = base_path(config('lucent.schemas_path'));
$schemaPath = $configDir . "/" . $name . '.json';
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.");
}
}
+42
View File
@@ -0,0 +1,42 @@
<?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(),
path: "",
groups: []
);
$json = json_encode($schema, JSON_PRETTY_PRINT);
$configDir = base_path(config('lucent.schemas_path'));
$schemaPath = $configDir . "/" . $name . '.json';
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.");
}
}
+4
View File
@@ -9,6 +9,8 @@ use Illuminate\Support\ServiceProvider;
use Intervention\Image\ImageManager;
use Lucent\Channel\ChannelService;
use Lucent\Commands\CompileSchemas;
use Lucent\Commands\GenerateCollectionSchema;
use Lucent\Commands\GenerateFileSchema;
use Lucent\Commands\LiveLink;
use Lucent\Commands\RebuildThumbnails;
use Lucent\Commands\RemoveOrphanEdges;
@@ -75,6 +77,8 @@ class LucentServiceProvider extends ServiceProvider
LiveLink::class,
RemoveOrphanEdges::class,
SetupDatabase::class,
GenerateCollectionSchema::class,
GenerateFileSchema::class,
]);
}