crazy stuff
This commit is contained in:
@@ -7,61 +7,39 @@ 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 $signature = 'lucent:schemas';
|
||||
|
||||
protected $description = 'Compiles schemas';
|
||||
|
||||
protected $description = "Compiles schemas";
|
||||
|
||||
public function handle(SchemaService $schemaService)
|
||||
{
|
||||
|
||||
$configDir = base_path(config('lucent.schemas_path'));
|
||||
$configDir = base_path(config("lucent.schemas_path"));
|
||||
$schemasDirIterator = new DirectoryIterator($configDir);
|
||||
$schemas = [];
|
||||
|
||||
foreach ($schemasDirIterator as $file) {
|
||||
if ($file->getExtension() !== "json") {
|
||||
if ($file->getExtension() !== "toml") {
|
||||
continue;
|
||||
}
|
||||
$schemaData = Toml::ParseFile(
|
||||
$configDir . "/" . $file->getFilename(),
|
||||
);
|
||||
|
||||
$schemaJson = file_get_contents($configDir . "/" . $file->getFilename());
|
||||
$schema = json_decode($schemaJson, true);
|
||||
if (empty($schema)) {
|
||||
$this->error("Invalid JSON " . $file->getFilename());
|
||||
return 0;
|
||||
}
|
||||
$schemas[] = $schema;
|
||||
|
||||
$schemas[] = $schemaData;
|
||||
}
|
||||
|
||||
$schemas = collect($schemas)->sortBy("label")->values();
|
||||
$roles = $schemas
|
||||
->map([$schemaService, 'fromArray'])
|
||||
->whereIn("type", [Type::COLLECTION, Type::FILES])
|
||||
->reduce(fn($carry, Schema $schema) => array_merge(
|
||||
$carry,
|
||||
$schema->read,
|
||||
$schema->write,
|
||||
config("lucent.canInvite") ?? [],
|
||||
config("lucent.canBuild") ?? [],
|
||||
), []);
|
||||
|
||||
$json = [
|
||||
"schemas" => $schemas->toArray(),
|
||||
"roles" => collect($roles)->push("admin")->push("removed")->unique()->values()->toArray()
|
||||
];
|
||||
|
||||
if (!file_exists(storage_path("lucent"))) {
|
||||
mkdir(storage_path("lucent"));
|
||||
}
|
||||
|
||||
file_put_contents(schemas_path(), json_encode($json));
|
||||
file_put_contents(schemas_path(), json_encode($schemas));
|
||||
|
||||
$this->info("Lucent Schemas were updated");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user