diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 67bdc04a982..1cb87bfa58f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -144,6 +144,7 @@ This serves two purposes: - Simplified the asset file locator to only serve files from the media source directory in https://github.com/hydephp/develop/pull/2012 - Added Vite HMR support in https://github.com/hydephp/develop/pull/2016 +- Added experimental Laravel Herd support in https://github.com/hydephp/develop/pull/2227 #### HydeFront diff --git a/docs/extensions/realtime-compiler.md b/docs/extensions/realtime-compiler.md index fbe487c1390..78bdd2ab3af 100644 --- a/docs/extensions/realtime-compiler.md +++ b/docs/extensions/realtime-compiler.md @@ -121,6 +121,33 @@ The live editor plugin code will not be saved to your static site. ], ``` +### Herd Integration + +#### Usage + +Since HydePHP v2 (Realtime Compiler v4), HydePHP has an experimental integration with [Herd](https://herd.laravel.com/) to provide a seamless development experience. The realtime compiler includes a custom Valet driver that allows Herd to serve your HydePHP site. + +To install the Valet driver for Herd, run the following command: + +```bash +php hyde herd:install +``` + +This will copy the HydeValetDriver to your Herd configuration directory, allowing Herd to automatically serve your HydePHP site. + +#### Features + +When using the Herd integration, you get the following benefits: + +- Automatic site detection for HydePHP projects +- The realtime compiler is used to serve your site +- Proper handling of static files and dynamic routes +- Site information displayed in the Herd UI + +> The Herd integration requires Herd to be installed on your system. + +>warning The Herd integration is experimental and may be unstable. [Report issues at GitHub](https://github.com/hydephp/realtime-compiler/pull/30)! + ### Source code - **GitHub**: [hydephp/realtime-compiler](https://github.com/hydephp/realtime-compiler) diff --git a/packages/realtime-compiler/bin/server.php b/packages/realtime-compiler/bin/server.php index afa3f089c6e..674649aa058 100755 --- a/packages/realtime-compiler/bin/server.php +++ b/packages/realtime-compiler/bin/server.php @@ -1,9 +1,13 @@ [ + 'Hyde Version' => InstalledVersions::isInstalled('hyde/hyde') ? InstalledVersions::getPrettyVersion('hyde/hyde') : 'Unknown', + 'Framework Version' => InstalledVersions::getPrettyVersion('hyde/framework') ?: 'Unknown', + 'Site Name' => $hydeConfig['name'] ?? 'Unknown', + 'Site URL' => $hydeConfig['url'] ?? 'Not set', + 'Site Language' => $hydeConfig['language'] ?? 'en', + 'Output Directory' => $hydeConfig['output_directory'] ?? '_site', + ], + 'Build Info' => [ + 'Pretty URLs' => $hydeConfig['pretty_urls'] ? 'Enabled' : 'Disabled', + 'Generate Sitemap' => $hydeConfig['generate_sitemap'] ? 'Yes' : 'No', + 'RSS Feed' => ($hydeConfig['rss']['enabled'] ?? false) ? 'Enabled' : 'Disabled', + 'Source Root' => $hydeConfig['source_root'] ?: '(Project Root)', + ], + 'Features' => [ + 'Enabled Features' => implode(', ', array_map(function ($feature) { + return $feature->name; + }, $hydeConfig['features'] ?? [])), + ], + 'Server Configuration' => [ + 'Port' => $hydeConfig['server']['port'] ?? 8080, + 'Host' => $hydeConfig['server']['host'] ?? 'localhost', + 'Save Preview' => ($hydeConfig['server']['save_preview'] ?? true) ? 'Yes' : 'No', + 'Live Edit' => ($hydeConfig['server']['live_edit'] ?? false) ? 'Enabled' : 'Disabled', + 'Dashboard' => ($hydeConfig['server']['dashboard']['enabled'] ?? true) ? 'Enabled' : 'Disabled', + ], + ]; + } +} diff --git a/packages/realtime-compiler/src/Console/Commands/HerdInstallCommand.php b/packages/realtime-compiler/src/Console/Commands/HerdInstallCommand.php new file mode 100644 index 00000000000..531dc750622 --- /dev/null +++ b/packages/realtime-compiler/src/Console/Commands/HerdInstallCommand.php @@ -0,0 +1,65 @@ +getDriverTargetPath(); + $driverSourcePath = Hyde::vendorPath('resources/stubs/HydeValetDriver.php', 'realtime-compiler'); + + if (! is_dir(dirname($driverTargetPath))) { + $this->error('Herd Valet drivers directory not found. Is Herd installed?'); + + return Command::FAILURE; + } + + if (file_exists($driverTargetPath) && ! $this->option('force')) { + if (! $this->confirm('The HydePHP Valet driver for Herd already exists. Do you want to overwrite it?', true)) { + $this->info('Installation cancelled.'); + + return Command::SUCCESS; + } + } + + try { + File::copy($driverSourcePath, $driverTargetPath); + $this->info('HydePHP Valet driver for Herd successfully installed!'); + $this->line('Driver path: '.$driverTargetPath); + + return Command::SUCCESS; + } catch (Exception $exception) { + $this->error('Failed to install the HydePHP Valet driver: '.$exception->getMessage()); + + return Command::FAILURE; + } + } + + private function getDriverTargetPath(): string + { + return match (PHP_OS_FAMILY) { + 'Darwin' => $_SERVER['HOME'].'/Library/Application Support/Herd/config/valet/Drivers/HydeValetDriver.php', + 'Windows' => $_SERVER['USERPROFILE'].'\.config\herd\config\valet\Drivers\HydeValetDriver.php', + default => throw new Exception('Herd is not yet supported on Linux.'), + }; + } +} diff --git a/packages/realtime-compiler/src/RealtimeCompilerServiceProvider.php b/packages/realtime-compiler/src/RealtimeCompilerServiceProvider.php index eaac813500d..79f6696ebae 100644 --- a/packages/realtime-compiler/src/RealtimeCompilerServiceProvider.php +++ b/packages/realtime-compiler/src/RealtimeCompilerServiceProvider.php @@ -5,15 +5,22 @@ namespace Hyde\RealtimeCompiler; use Illuminate\Support\ServiceProvider; -use Hyde\RealtimeCompiler\Http\LiveEditController; use Hyde\RealtimeCompiler\Http\DashboardController; +use Hyde\RealtimeCompiler\Http\LiveEditController; use Hyde\RealtimeCompiler\Http\VirtualRouteController; +use Hyde\RealtimeCompiler\Console\Commands\HerdInstallCommand; class RealtimeCompilerServiceProvider extends ServiceProvider { public function register(): void { $this->app->singleton(RealtimeCompiler::class); + + if ($this->app->runningInConsole()) { + $this->commands([ + HerdInstallCommand::class, + ]); + } } public function boot(): void