1
+ <?php
2
+
3
+ namespace Codingwithrk \RkProjectSetup ;
4
+
5
+ use Composer \Composer ;
6
+ use Composer \IO \IOInterface ;
7
+ use Composer \Plugin \PluginInterface ;
8
+ use Composer \EventDispatcher \EventSubscriberInterface ;
9
+ use Composer \Installer \PackageEvent ;
10
+ use Composer \Installer \PackageEvents ;
11
+
12
+ class ProjectSetupInstaller implements PluginInterface, EventSubscriberInterface
13
+ {
14
+ public function activate (Composer $ composer , IOInterface $ io )
15
+ {
16
+ }
17
+
18
+ public function deactivate (Composer $ composer , IOInterface $ io )
19
+ {
20
+ }
21
+
22
+ public function uninstall (Composer $ composer , IOInterface $ io )
23
+ {
24
+ }
25
+
26
+ public static function getSubscribedEvents (): array
27
+ {
28
+ return [
29
+ PackageEvents::POST_PACKAGE_INSTALL => 'handlePostInstall ' ,
30
+ ];
31
+ }
32
+
33
+ public function handlePostInstall (PackageEvent $ event )
34
+ {
35
+ $ io = $ event ->getIO ();
36
+
37
+ // Run npm install
38
+ $ io ->write ("<info>📦 Running npm install...</info> " );
39
+ shell_exec ("npm install " );
40
+ $ io ->write ("<comment>✅ npm install completed!</comment> " );
41
+
42
+ // Install Livewire
43
+ $ io ->write ("<info>📦 Installing Livewire...</info> " );
44
+ shell_exec ("composer require livewire/livewire " );
45
+ $ io ->write ("<comment>✅ Livewire installed!</comment> " );
46
+
47
+ // Publish Livewire config
48
+ $ io ->write ("<info>⚙️ Publishing Livewire config...</info> " );
49
+ shell_exec ("php artisan livewire:publish --config " );
50
+ $ io ->write ("<comment>✅ Livewire config published!</comment> " );
51
+
52
+ // Generate Livewire layout
53
+ $ io ->write ("<info>🧱 Generating Livewire layout...</info> " );
54
+ shell_exec ("php artisan livewire:layout " );
55
+ $ io ->write ("<comment>✅ Layout generated!</comment> " );
56
+
57
+ // Install Flux
58
+ $ io ->write ("<info>📦 Installing Flux...</info> " );
59
+ shell_exec ("composer require livewire/flux " );
60
+ $ io ->write ("<comment>✅ Flux installed!</comment> " );
61
+
62
+ // Modify layout file
63
+ $ layout = 'resources/views/components/layouts/app.blade.php ' ;
64
+ if (file_exists ($ layout )) {
65
+ $ io ->write ("<info>✏️ Updating layout file...</info> " );
66
+ file_put_contents ($ layout , <<<BLADE
67
+ <!DOCTYPE html>
68
+ <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
69
+ <head>
70
+ <meta charset="utf-8">
71
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
72
+
73
+ <title>{{ \$title ?? 'Page Title' }}</title>
74
+ @vite(['resources/css/app.css', 'resources/js/app.js'])
75
+ @fluxAppearance
76
+ </head>
77
+ <body>
78
+ {{ \$slot }}
79
+ @fluxScripts
80
+ </body>
81
+ </html>
82
+ BLADE
83
+ );
84
+ $ io ->write ("<comment>✅ Layout updated!</comment> " );
85
+ }
86
+
87
+ // Modify app.css
88
+ $ css = 'resources/css/app.css ' ;
89
+ if (file_exists ($ css )) {
90
+ $ io ->write ("<info>🎨 Updating app.css file...</info> " );
91
+ file_put_contents ($ css , <<<CSS
92
+ @import 'tailwindcss';
93
+ @import '../../vendor/livewire/flux/dist/flux.css';
94
+
95
+ @source '../../vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php';
96
+ @source '../../storage/framework/views/*.php';
97
+ @source '../**/*.blade.php';
98
+ @source '../**/*.js';
99
+
100
+ @custom-variant dark (&:where(.dark, .dark *));
101
+ @theme {
102
+ --font-sans: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
103
+ 'Segoe UI Symbol', 'Noto Color Emoji';
104
+ }
105
+ CSS
106
+ );
107
+ $ io ->write ("<comment>✅ app.css updated!</comment> " );
108
+ }
109
+
110
+ $ io ->write ("<info>🎉 rk-project-setup completed successfully!</info> " );
111
+ }
112
+
113
+ }
0 commit comments