scanDir([], $schemasDirIterator); $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)); $this->info("Lucent Schemas were updated"); } private function scanDir(array $schemas, DirectoryIterator $directoryIterator, $dirName = ""): array { foreach ($directoryIterator as $file) { if ($file->isDir()) { if ($file->isDot()) { continue; } $newDirName = $dirName.'.'.$file->getBasename(); $schemas = $this->scanDir($schemas, new DirectoryIterator($file->getPathname()), $newDirName); continue; } if ($file->getExtension() !== "json") { continue; } $schemaJson = file_get_contents($file->getPathname()); $schema = json_decode($schemaJson, true); if (empty($schema)) { $this->error("Invalid JSON " . $file->getFilename()); die; } $schema["folder"] = trim($dirName,"."); $schemas[] = $schema; } return $schemas; } }