Skip to content

Commit 46b5c38

Browse files
committed
registy:sync
1 parent 8032db3 commit 46b5c38

171 files changed

Lines changed: 1089 additions & 179 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Registry;
6+
use Illuminate\Console\Attributes\Description;
7+
use Illuminate\Console\Attributes\Signature;
8+
use Illuminate\Console\Command;
9+
use Illuminate\Support\Str;
10+
11+
#[Signature('registry:sync')]
12+
#[Description('Sync registry.json items to the database')]
13+
class RegistrySync extends Command
14+
{
15+
/**
16+
* Execute the console command.
17+
*/
18+
public function handle(): int
19+
{
20+
$path = base_path('registry.json');
21+
22+
if (! file_exists($path)) {
23+
$this->error('registry.json not found at '.$path);
24+
25+
return 1;
26+
}
27+
28+
$json = json_decode(file_get_contents($path), true);
29+
30+
if (! isset($json['items']) || ! is_array($json['items'])) {
31+
$this->error('No items found in registry.json');
32+
33+
return 1;
34+
}
35+
36+
$fillable = (new Registry)->getFillable();
37+
$synced = 0;
38+
39+
foreach ($json['items'] as $item) {
40+
$attributes = [];
41+
42+
foreach ($item as $key => $value) {
43+
$modelKey = $this->mapKey($key);
44+
45+
if (in_array($modelKey, $fillable)) {
46+
$attributes[$modelKey] = $value;
47+
}
48+
}
49+
50+
Registry::updateOrCreate(
51+
['name' => $item['name']],
52+
$attributes
53+
);
54+
55+
$synced++;
56+
}
57+
58+
$this->info("Synced {$synced} items from registry.json");
59+
60+
return 0;
61+
}
62+
63+
protected function mapKey(string $key): string
64+
{
65+
$snake = Str::snake($key);
66+
67+
$camelCaseKeys = [
68+
'dev_dependencies' => 'devDependencies',
69+
'registry_dependencies' => 'registryDependencies',
70+
'env_vars' => 'envVars',
71+
'icon_library' => 'iconLibrary',
72+
'base_color' => 'baseColor',
73+
];
74+
75+
return $camelCaseKeys[$snake] ?? $snake;
76+
}
77+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api\Registries;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Registry;
7+
use Illuminate\Http\JsonResponse;
8+
use Illuminate\Http\Request;
9+
10+
class RegistrySearchController extends Controller
11+
{
12+
public function search(Request $request): JsonResponse
13+
{
14+
$query = $request->query('q', '');
15+
$type = $request->query('type');
16+
17+
$results = Registry::query()
18+
->when($query, fn ($q) => $q->where('name', 'like', "%{$query}%"))
19+
->when($type, fn ($q) => $q->where('type', $type))
20+
->limit(20)
21+
->get()
22+
->map(fn ($item) => [
23+
'name' => $item->name,
24+
'title' => $item->title,
25+
'type' => $item->type,
26+
'category' => $item->meta['category'] ?? null,
27+
'description' => $item->meta['description'] ?? null,
28+
'baseColor' => $item->baseColor ?? null,
29+
]);
30+
31+
return response()->json($results);
32+
}
33+
}

app/Http/Controllers/HomePageController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Models\Registry;
56
use Illuminate\Http\Request;
67
use Inertia\Inertia;
78

@@ -12,6 +13,8 @@ class HomePageController extends Controller
1213
*/
1314
public function __invoke(Request $request)
1415
{
15-
return Inertia::render('home');
16+
return Inertia::render('home', [
17+
'fonts' => Registry::query()->fonts()->get()
18+
]);
1619
}
1720
}

public/build/assets/app-C8l1WpTG.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/app-DlbnZV3L.css

Lines changed: 0 additions & 2 deletions
This file was deleted.

public/build/assets/appearance-a-q-T8RT.js renamed to public/build/assets/appearance-BrZX5eRc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
13.4 KB
Binary file not shown.
10.9 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)