From cf3d6215875b0b06db5fa9a7ab22609c5c4e3d39 Mon Sep 17 00:00:00 2001 From: lexx Date: Sat, 7 Sep 2024 00:03:11 +0300 Subject: [PATCH] helper commands --- src/Commands/GenerateCollectionSchema.php | 42 +++++++++++++++++++++++ src/Commands/GenerateFileSchema.php | 42 +++++++++++++++++++++++ src/LucentServiceProvider.php | 4 +++ 3 files changed, 88 insertions(+) create mode 100644 src/Commands/GenerateCollectionSchema.php create mode 100644 src/Commands/GenerateFileSchema.php diff --git a/src/Commands/GenerateCollectionSchema.php b/src/Commands/GenerateCollectionSchema.php new file mode 100644 index 0000000..bf8a845 --- /dev/null +++ b/src/Commands/GenerateCollectionSchema.php @@ -0,0 +1,42 @@ +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."); + + } + +} diff --git a/src/Commands/GenerateFileSchema.php b/src/Commands/GenerateFileSchema.php new file mode 100644 index 0000000..9d014bf --- /dev/null +++ b/src/Commands/GenerateFileSchema.php @@ -0,0 +1,42 @@ +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."); + + } + +} diff --git a/src/LucentServiceProvider.php b/src/LucentServiceProvider.php index f3884cb..eb4cda1 100644 --- a/src/LucentServiceProvider.php +++ b/src/LucentServiceProvider.php @@ -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, ]); }