Files
lucent-laravel/src/Commands/CompileConfig.php
T

53 lines
1.3 KiB
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php
namespace Lucent\Commands;
use DirectoryIterator;
use Illuminate\Console\Command;
class CompileConfig extends Command
{
2023-10-04 13:32:30 +03:00
protected $signature = 'lucent:config';
2023-10-02 23:10:49 +03:00
protected $description = 'Compiles Config';
public function __construct()
{
parent::__construct();
}
public function handle()
{
2023-10-04 13:32:30 +03:00
$configDir = base_path(config('lucent.config_path'));
2023-10-02 23:10:49 +03:00
2023-10-04 13:32:30 +03:00
$configJson = file_get_contents($configDir . "/lucent.json");
2023-10-02 23:10:49 +03:00
$config = json_decode($configJson, true);
2023-10-04 13:32:30 +03:00
$schemasDirIterator = new DirectoryIterator($configDir . "/Schemas");
2023-10-02 23:10:49 +03:00
$schemas = [];
foreach ($schemasDirIterator as $file) {
if ($file->getExtension() !== "json") {
continue;
}
2023-10-04 13:32:30 +03:00
$schemaJson = file_get_contents($configDir . "/Schemas/" . $file->getFilename());
2023-10-02 23:10:49 +03:00
$schema = json_decode($schemaJson, true);
if (empty($schema)) {
$this->error("Invalid JSON " . $file->getFilename());
return 0;
}
$schemas[] = $schema;
}
$config["schemas"] = collect($schemas)->sortBy("label")->values()->toArray();
$configOuputJson = json_encode($config);
file_put_contents(storage_path("lucent.config.json"), $configOuputJson);
$this->info("Lucent JSON update");
}
}