Skip to content

Commit 4684091

Browse files
committed
MooxInstaller
1 parent 85df599 commit 4684091

File tree

12 files changed

+746
-1033
lines changed

12 files changed

+746
-1033
lines changed

packages/core/src/Console/Commands/MooxInstaller.php

Lines changed: 241 additions & 148 deletions
Large diffs are not rendered by default.

packages/core/src/Console/Commands/UpdatePanelDependencies.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,34 @@
44

55
use Illuminate\Console\Command;
66
use Moox\Core\Console\Traits\SelectFilamentPanel;
7-
87
use function Laravel\Prompts\select;
98

109
class UpdatePanelDependencies extends Command
1110
{
1211
use SelectFilamentPanel;
1312

1413
protected $signature = 'moox:update-panel-dependencies {panel? : The panel to update dependencies for}';
15-
1614
protected $description = 'Update composer dependencies for panel packages based on their plugins';
1715

1816
public function handle(): int
1917
{
2018
$panel = $this->argument('panel');
2119

22-
if (! $panel) {
20+
if (!$panel) {
2321
$availablePanels = array_keys($this->panelMap);
2422
$panel = select(
2523
label: '🛠️ Which panel do you want to update dependencies for?',
2624
options: $availablePanels
2725
);
2826
}
2927

30-
if (! isset($this->panelMap[$panel])) {
28+
if (!isset($this->panelMap[$panel])) {
3129
$this->error("❌ Panel '{$panel}' not found.");
32-
3330
return 1;
3431
}
3532

3633
$this->updatePanelDependencies($panel);
3734

3835
return 0;
3936
}
40-
}
37+
}

packages/core/src/Console/Traits/CheckForFilament.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,49 @@ trait CheckForFilament
1414
{
1515
protected string $providerPath = 'app/Providers/Filament/AdminPanelProvider.php';
1616

17-
public function checkForFilament(): bool
17+
18+
public function checkForFilament(bool $silent = false): bool
1819
{
19-
if (! class_exists(\Filament\PanelProvider::class, false)) {
20+
if (!class_exists(\Filament\PanelProvider::class, false)) {
21+
2022
$panelProviderPath = base_path('vendor/filament/filament/src/PanelProvider.php');
2123

22-
if (! file_exists($panelProviderPath)) {
24+
if (!file_exists($panelProviderPath)) {
2325
error('❌ Filament is not installed. Please run: composer require filament/filament');
2426

25-
if (! confirm('📦 Do you want to install filament/filament now?', true)) {
27+
if (!confirm('📦 Do you want to install filament/filament now?', true)) {
2628
info('⛔ Installation cancelled.');
27-
2829
return false;
2930
}
3031

31-
info('📦 Running: composer require filament/filament...');
32+
if (! $silent) info('📦 Running: composer require filament/filament...');
3233
exec('composer require filament/filament:* 2>&1', $output, $returnVar);
3334
foreach ($output as $line) {
34-
info(' '.$line);
35+
if (! $silent) info(" " . $line);
3536
}
3637

3738
if ($returnVar !== 0) {
3839
error('❌ Composer installation of Filament failed. Please check your setup.');
39-
4040
return false;
4141
}
4242

43-
info('✅ filament/filament successfully installed.');
43+
if (! $silent) info('✅ filament/filament successfully installed.');
4444
} else {
45-
info('✅ Filament is already installed.');
45+
if (! $silent) info('✅ Filament is already installed.');
4646
}
4747
} else {
48-
info('✅ Filament is already installed.');
48+
if (! $silent) info('✅ Filament is already installed.');
4949
}
5050

51-
$this->analyzeFilamentEnvironment();
51+
// Only analyze in panel generation flow. The packages flow should stay clean.
52+
if (! $silent && method_exists($this, 'isPanelGenerationMode') && $this->isPanelGenerationMode()) {
53+
$this->analyzeFilamentEnvironment();
54+
}
5255

5356
return true;
5457
}
5558

59+
5660
public function hasPanelsWithLogin(): bool
5761
{
5862
$panelFiles = $this->getPanelProviderFiles();
@@ -61,14 +65,14 @@ public function hasPanelsWithLogin(): bool
6165
return $panelsWithLogin->isNotEmpty();
6266
}
6367

68+
6469
protected function analyzeFilamentEnvironment(): void
6570
{
6671
info('🔍 Checking existing Filament PanelProviders...');
6772
$panelFiles = $this->getPanelProviderFiles();
6873

6974
if ($panelFiles->isEmpty()) {
7075
warning('⚠️ No PanelProvider files found in your project.');
71-
7276
return;
7377
}
7478

@@ -113,20 +117,19 @@ protected function filterPanelsWithLogin(Collection $panelFiles): Collection
113117
{
114118
return $panelFiles->filter(function ($path) {
115119
$contents = @file_get_contents($path);
116-
117120
return $contents !== false && str_contains($contents, '->login(');
118121
})->values();
119122
}
120123

121124
protected function getProviderClassesFromBootstrap(): array
122125
{
123126
$bootstrapProvidersPath = base_path('bootstrap/providers.php');
124-
if (! File::exists($bootstrapProvidersPath)) {
127+
if (!File::exists($bootstrapProvidersPath)) {
125128
return [];
126129
}
127130

128131
$content = File::get($bootstrapProvidersPath);
129-
if (! preg_match_all('/([\\\\A-Za-z0-9_]+)::class/', $content, $matches)) {
132+
if (!preg_match_all('/([\\\\A-Za-z0-9_]+)::class/', $content, $matches)) {
130133
return [];
131134
}
132135

@@ -136,12 +139,11 @@ protected function getProviderClassesFromBootstrap(): array
136139
protected function getComposerPsr4Mappings(): array
137140
{
138141
$composerPath = base_path('composer.json');
139-
if (! File::exists($composerPath)) {
142+
if (!File::exists($composerPath)) {
140143
return [];
141144
}
142145
$json = json_decode(File::get($composerPath), true);
143146
$psr4 = $json['autoload']['psr-4'] ?? [];
144-
145147
return is_array($psr4) ? $psr4 : [];
146148
}
147149

@@ -161,7 +163,6 @@ protected function resolveClassToPath(string $class, array $psr4): ?string
161163
}
162164
}
163165
}
164-
165166
return null;
166167
}
167168
}

packages/core/src/Console/Traits/CheckForMooxPackages.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ public function checkForMooxPackage(string $package): bool
2020

2121
if (array_key_exists($package, $packages)) {
2222
info("\n✅ Package '{$package}' is already installed. Skipping installation.\n");
23-
2423
return true;
2524
}
2625

2726
error("{$package} is not installed. Please run: composer require {$package}");
2827

29-
if (! confirm("📦 Do you want to install {$package} now?", true)) {
28+
if (!confirm("📦 Do you want to install {$package} now?", true)) {
3029
info('⛔ Installation cancelled.');
31-
3230
return false;
3331
}
3432

@@ -37,17 +35,15 @@ public function checkForMooxPackage(string $package): bool
3735
info("📦 Running: composer require {$package}:* ...");
3836
exec("composer require {$package}:* 2>&1", $output, $returnVar);
3937
foreach ($output as $line) {
40-
info(' '.$line);
38+
info(" " . $line);
4139
}
4240

4341
if ($returnVar !== 0) {
4442
error("❌ Composer installation of {$package} failed. Please check your setup.");
45-
4643
return false;
4744
}
4845

4946
info("{$package} successfully installed.");
50-
5147
return true;
5248
}
5349

packages/core/src/Console/Traits/CheckOrCreateFilamentUser.php

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
namespace Moox\Core\Console\Traits;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Support\Facades\Config;
75
use Illuminate\Support\Facades\Hash;
86
use Illuminate\Support\Facades\Schema;
7+
use Illuminate\Support\Facades\Config;
8+
use Illuminate\Database\Eloquent\Model;
99

1010
use function Laravel\Prompts\alert;
1111
use function Laravel\Prompts\info;
12-
use function Laravel\Prompts\password;
13-
use function Laravel\Prompts\text;
1412
use function Laravel\Prompts\warning;
13+
use function Laravel\Prompts\text;
14+
use function Laravel\Prompts\password;
1515

1616
trait CheckOrCreateFilamentUser
1717
{
18+
1819
public function checkOrCreateFilamentUser(): void
1920
{
2021
/** @var class-string<Model> $userModel */
2122
$userModel = Config::get('filament.auth.providers.users.model') ?? \App\Models\User::class;
2223

2324
if (! class_exists($userModel)) {
2425
warning("⚠️ User model '{$userModel}' does not exist.");
25-
2626
return;
2727
}
2828

@@ -32,52 +32,80 @@ public function checkOrCreateFilamentUser(): void
3232

3333
if (! Schema::hasTable($table)) {
3434
warning("⚠️ Table '{$table}' not found. Did you run migrations?");
35-
3635
return;
3736
}
3837

3938
if ($userModel::count() > 0) {
4039
info("✅ Found existing users in '{$table}'. Skipping user creation.");
41-
4240
return;
4341
}
4442

45-
alert("🚨 No users found in '{$table}'. Let's create the first Filament user.");
43+
alert("🚨 No users found. Let's create the first user");
4644
$this->createFilamentUser($userModel);
4745
}
46+
47+
protected function createFilamentUser(string $userModel): void
48+
{
49+
info("🧑 Creating new admin user for model '{$userModel}'...");
50+
51+
$name = text('Enter name', default: 'Admin');
52+
$email = text('Enter email', default: '[email protected]');
53+
$password = password('Enter password', required: true);
54+
55+
$user = $userModel::create([
56+
'name' => $name,
57+
'email' => $email,
58+
'password' => Hash::make($password),
59+
]);
4860

49-
public function hasFilamentUsers(): bool
61+
info("✅ User '{$user->email}' created successfully.");
62+
}
63+
64+
public function checkOrCreateWpUser(): void
5065
{
51-
/** @var class-string<Model> $userModel */
52-
$userModel = Config::get('filament.auth.providers.users.model') ?? \App\Models\User::class;
66+
$wpUserModel = \Moox\Press\Models\WpUser::class;
5367

54-
if (! class_exists($userModel)) {
55-
return false;
68+
if (! class_exists($wpUserModel)) {
69+
warning("⚠️ WP User model '{$wpUserModel}' does not exist.");
70+
return;
5671
}
5772

58-
$table = (new $userModel)->getTable();
73+
$table = (new $wpUserModel)->getTable();
74+
75+
info("🔍 Checking WP user setup for Press Panel [Model: {$wpUserModel}]...");
5976

6077
if (! Schema::hasTable($table)) {
61-
return false;
78+
warning("⚠️ Table '{$table}' not found. Did you run migrations?");
79+
return;
80+
}
81+
82+
if ($wpUserModel::count() > 0) {
83+
info("✅ Found existing WP users in '{$table}'. Skipping user creation.");
84+
return;
6285
}
6386

64-
return $userModel::count() > 0;
87+
alert("🚨 No WP users found. Let's create the first WP user");
88+
$this->createWpUser($wpUserModel);
6589
}
6690

67-
protected function createFilamentUser(string $userModel): void
91+
protected function createWpUser(string $wpUserModel): void
6892
{
69-
info("🧑 Creating new admin user for model '{$userModel}'...");
93+
info("🧑 Creating new WP user for model '{$wpUserModel}'...");
7094

71-
$name = text('Enter name', default: 'Admin');
72-
$email = text('Enter email', default: 'admin@example.com');
95+
$login = text('Enter login', default: 'wpadmin');
96+
$email = text('Enter email', default: 'wpadmin@example.com');
7397
$password = password('Enter password', required: true);
74-
75-
$user = $userModel::create([
76-
'name' => $name,
77-
'email' => $email,
78-
'password' => Hash::make($password),
98+
$displayName = text('Enter display name', default: $login);
99+
100+
$user = $wpUserModel::create([
101+
'user_login' => $login,
102+
'user_email' => $email,
103+
'user_pass' => $password,
104+
'display_name' => $displayName,
105+
'user_registered' => now(),
79106
]);
80107

81-
info("User '{$user->email}' created successfully.");
108+
info("WP user '{$user->user_login}' created successfully.");
82109
}
110+
83111
}

0 commit comments

Comments
 (0)