46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Lucent\Commands;
|
|
|
|
use DirectoryIterator;
|
|
use Illuminate\Console\Command;
|
|
use Lucent\Schema\Schema;
|
|
use Lucent\Schema\SchemaService;
|
|
use Lucent\Schema\Type;
|
|
use Yosymfony\Toml\Toml;
|
|
|
|
class CompileSchemas extends Command
|
|
{
|
|
protected $signature = "lucent:schemas";
|
|
|
|
protected $description = "Compiles schemas";
|
|
|
|
public function handle(SchemaService $schemaService)
|
|
{
|
|
$configDir = base_path(config("lucent.schemas_path"));
|
|
$schemasDirIterator = new DirectoryIterator($configDir);
|
|
$schemas = [];
|
|
|
|
foreach ($schemasDirIterator as $file) {
|
|
if ($file->getExtension() !== "toml") {
|
|
continue;
|
|
}
|
|
$schemaData = Toml::ParseFile(
|
|
$configDir . "/" . $file->getFilename(),
|
|
);
|
|
|
|
$schemas[] = $schemaData;
|
|
}
|
|
|
|
$schemas = collect($schemas)->sortBy("label")->values();
|
|
|
|
if (!file_exists(storage_path("lucent"))) {
|
|
mkdir(storage_path("lucent"));
|
|
}
|
|
|
|
file_put_contents(schemas_path(), json_encode($schemas));
|
|
|
|
$this->info("Lucent Schemas were updated");
|
|
}
|
|
}
|