From a8fa4949cfeaa4b904c0564771ce3adf98aa2099 Mon Sep 17 00:00:00 2001 From: YoussefACHCHIRAJ Date: Wed, 26 Nov 2025 18:21:13 +0100 Subject: [PATCH 1/2] feat: add a feat to the init command --- src/Commands/SheafInitCommand.php | 27 +++++++++++++++++++++++++++ src/Services/ComponentHttpClient.php | 18 ++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/Commands/SheafInitCommand.php b/src/Commands/SheafInitCommand.php index 1374f07..c0073eb 100644 --- a/src/Commands/SheafInitCommand.php +++ b/src/Commands/SheafInitCommand.php @@ -5,6 +5,7 @@ use Sheaf\Cli\Services\PackageInitializationService; use Sheaf\Cli\Support\InitializationConfig; use Illuminate\Console\Command; +use Sheaf\Cli\Services\ComponentHttpClient; use function Laravel\Prompts\confirm; use function Laravel\Prompts\text; @@ -64,6 +65,7 @@ public function handle() if ($result) { $this->displaySuccess($configuration); $this->displayNextStep($configuration); + $this->subscribeToNewsletter(); return Command::SUCCESS; } @@ -206,6 +208,31 @@ protected function validateCssFileName(?string $input): ?string return null; } + /** + * Ask user to subscribe to the news letter + */ + protected function subscribeToNewsletter() + { + + $email = text( + label: 'Get notified when we release new components', + placeholder: 'your.email@example.com', + hint: 'No spam, just useful updates', + validate: fn($input) => $input && !filter_var($input, FILTER_VALIDATE_EMAIL) + ? 'Please enter a valid email address' + : null + ); + + if (empty($email)) { + return; + } + try { + new ComponentHttpClient()->subscribeUserToNewsletter($email); + $this->info("✓ Thanks for subscribing! We'll keep you updated with new components and features."); + } catch (\Throwable $th) { + $this->warn("We couldn't subscribe your email right now, but you can always subscribe later at https://sheafui.dev"); + } + } /** * Display the Sheaf package banner diff --git a/src/Services/ComponentHttpClient.php b/src/Services/ComponentHttpClient.php index 114fe01..eeb92cf 100644 --- a/src/Services/ComponentHttpClient.php +++ b/src/Services/ComponentHttpClient.php @@ -17,7 +17,8 @@ public function __construct() $this->token = SheafConfig::getUserToken(); } - public function fetchComponentFilesPath(string $name) { + public function fetchComponentFilesPath(string $name) + { $url = "{$this->baseUrl}/api/cli/components/$name/files"; $response = Http::asJson()->get($url); @@ -33,7 +34,6 @@ public function fetchComponentFilesPath(string $name) { 'success' => true, 'data' => $response->collect() ]; - } public function fetchResources(string $componentName) { @@ -59,4 +59,18 @@ public function fetchResources(string $componentName) ]; } + public function subscribeUserToNewsletter(string $email) + { + try { + $url = "{$this->baseUrl}/api/cli/newsletter/subscribe?email={$email}"; + + $result = Http::asJson()->get($url); + + if (!$result['success']) { + throw new Exception("Failed to subscribe to the news letter"); + } + } catch (\Throwable $th) { + throw new Exception("Failed to subscribe to the news letter"); + } + } } From 44a66af3503fce35efb5b25a2586fdfc8e40ba82 Mon Sep 17 00:00:00 2001 From: YoussefACHCHIRAJ Date: Wed, 26 Nov 2025 18:28:59 +0100 Subject: [PATCH 2/2] fix: fixing init tests --- tests/Feature/Commands/InitCommandTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Feature/Commands/InitCommandTest.php b/tests/Feature/Commands/InitCommandTest.php index 7ec2cc6..023fb3b 100644 --- a/tests/Feature/Commands/InitCommandTest.php +++ b/tests/Feature/Commands/InitCommandTest.php @@ -39,6 +39,8 @@ $command->expectsQuestion("The $mainJsFile is not exists, do you want to create it?", true); } + $command->expectsQuestion("Get notified when we release new components", null); + $command->assertExitCode(0); $command->run();