From de1c1faaa761a9d61f2fa78edc5e86c62639b955 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sun, 23 May 2021 00:40:12 +0200 Subject: [PATCH 1/5] register component in AppServiceProvider automatically --- src/Commands/Component.php | 12 ++++++++++++ src/Commands/ComponentCommand.php | 6 ++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/Commands/Component.php diff --git a/src/Commands/Component.php b/src/Commands/Component.php new file mode 100644 index 0000000..f1c0db8 --- /dev/null +++ b/src/Commands/Component.php @@ -0,0 +1,12 @@ +line("✨ Component app/Airwire/{$name}.php has been created!\n"); - - $this->warn("🚧 Don't forget to register the component! Add the following line to AppServiceProvider:"); - $this->line("\n\n Airwire::component('" . Str::snake($name) . "', {$name}::class);\n\n"); + Component::register($name); + $this->line("✨ Component app/Airwire/{$name}.php has been created and registered!\n"); } } From d75007dfe91348bc5d9fefec65dfbe35e7302ad7 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sun, 23 May 2021 15:17:42 +0200 Subject: [PATCH 2/5] Make requested changes --- src/Commands/Component.php | 12 ------------ src/Commands/ComponentCommand.php | 25 ++++++++++++++++++++++--- 2 files changed, 22 insertions(+), 15 deletions(-) delete mode 100644 src/Commands/Component.php diff --git a/src/Commands/Component.php b/src/Commands/Component.php deleted file mode 100644 index f1c0db8..0000000 --- a/src/Commands/Component.php +++ /dev/null @@ -1,12 +0,0 @@ -argument('name')); - if (! is_dir($path = app_path('Airwire'))) { + if (!is_dir($path = app_path('Airwire'))) { mkdir($path); } @@ -33,7 +33,26 @@ class ComponentCommand extends Command } PHP); - Component::register($name); - $this->line("✨ Component app/Airwire/{$name}.php has been created and registered!\n"); + $this->register($name); + } + + protected function register($name) + { + try { + $path = app_path('Providers/AppServiceProvider.php'); + + $snake = Str::snake($name); + + file_put_contents($path, str_replace( + "function boot()\n {", + "function boot()\n {\n \Airwire\Airwire::component('{$snake}', {$name}::class);", + file_get_contents($path) + )); + + $this->line("✨ Component app/Airwire/{$name}.php has been created and registered!"); + } catch (Exception $exception) + { + $this->error('The component could not be registered. Please check your app/Providers/AppServiceProvider.php'); + } } } From 2aa22cba9077fd752a4ed37a0833eb1dfb8e7332 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sun, 23 May 2021 17:13:51 +0200 Subject: [PATCH 3/5] Update src/Commands/ComponentCommand.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Samuel Štancl --- src/Commands/ComponentCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/ComponentCommand.php b/src/Commands/ComponentCommand.php index 96b8a3f..f9761ef 100644 --- a/src/Commands/ComponentCommand.php +++ b/src/Commands/ComponentCommand.php @@ -15,7 +15,7 @@ class ComponentCommand extends Command { $name = Str::studly($this->argument('name')); - if (!is_dir($path = app_path('Airwire'))) { + if (! is_dir($path = app_path('Airwire'))) { mkdir($path); } From 3b66320134369dafaf0313ec84bf66d00a06b910 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sun, 23 May 2021 17:14:00 +0200 Subject: [PATCH 4/5] Update src/Commands/ComponentCommand.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Samuel Štancl --- src/Commands/ComponentCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Commands/ComponentCommand.php b/src/Commands/ComponentCommand.php index f9761ef..51e1a8a 100644 --- a/src/Commands/ComponentCommand.php +++ b/src/Commands/ComponentCommand.php @@ -50,8 +50,7 @@ class ComponentCommand extends Command )); $this->line("✨ Component app/Airwire/{$name}.php has been created and registered!"); - } catch (Exception $exception) - { + } catch (Exception $exception) { $this->error('The component could not be registered. Please check your app/Providers/AppServiceProvider.php'); } } From 774591f6df2704bd5a9300e7e1cb99bb9ed55a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sun, 23 May 2021 17:34:45 +0200 Subject: [PATCH 5/5] Import Exception --- src/Commands/ComponentCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/ComponentCommand.php b/src/Commands/ComponentCommand.php index 51e1a8a..12fed7b 100644 --- a/src/Commands/ComponentCommand.php +++ b/src/Commands/ComponentCommand.php @@ -2,6 +2,7 @@ namespace Airwire\Commands; +use Exception; use Illuminate\Support\Str; use Illuminate\Console\Command;