From c15a4acdf76e71221f3ba4c8d028ce2d0a7e3b0a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 25 Mar 2022 12:52:45 +0100 Subject: [PATCH] Rework installer prompts and fix wrong directory --- src/Commands/HydeInstallerCommand.php | 86 ++++++++++++++------------- src/Services/HydeInstaller.php | 12 +--- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/src/Commands/HydeInstallerCommand.php b/src/Commands/HydeInstallerCommand.php index bd26a3e6..394b4812 100644 --- a/src/Commands/HydeInstallerCommand.php +++ b/src/Commands/HydeInstallerCommand.php @@ -31,14 +31,8 @@ public function handle(): int $this->line('The installer will guide you through the process of setting up your new Hyde site!'); $this->installer->name = $this->ask('What is the name of your site?', $this->installer->name); - $this->installer->site_url = $this->installer->setSiteUrl( - $this->ask('What is the name of your site?', $this->installer->site_url) - ); - if (isset($this->installer->warnings['site_url_warning'])) { - $this->warn($this->installer->warnings['site_url_warning']['message']); - // Unset the warning so it is not shown again later - unset($this->installer->warnings['site_url_warning']); - } + + $this->promptForUrl(); $this->promptForHomepage(); @@ -63,45 +57,55 @@ public function handle(): int return 0; } + private function promptForUrl() + { + if ($this->choice('Do you have a domain name you\'d like to set up?', [ + 'no', + 'yes', + ], 'no') === 'yes') { + $this->installer->site_url = $this->installer->setSiteUrl( + $this->ask('What is the url of your site?', $this->installer->site_url) + ); + if (isset($this->installer->warnings['site_url_warning'])) { + $this->warn($this->installer->warnings['site_url_warning']['message']); + // Unset the warning so it is not shown again later + unset($this->installer->warnings['site_url_warning']); + } + } else { + $this->comment('Okay, skipping setting up URL.'); + } + + } + private function promptForHomepage() { + $this->newLine(); $this->info('Hyde has a couple different homepages to choose from.'); - - $options = [ - 'welcome' => 'Default Welcome Page', - 'post-feed' => 'Feed of Latest Posts', - 'blank' => 'A Blank Layout Page', - ]; - $default = 'welcome'; - - if (file_exists(Hyde::path('resources/views/index.blade.php'))) { - $this->line('Note: You already have an index.blade.php file.'); - $options = array_merge([ - 'current' => 'Keep Current Page' - ], $options); - $default = 'current'; + if (file_exists(Hyde::path('resources/views/pages/index.blade.php'))) { + $this->warn('Warning: You already have a homepage file (resources/views/pages/index.blade.php). If you select \'yes\' it will be overwritten.'); } - $this->installer->homepage = $this->choice( - 'Which homepage would you like to use?', - $options, - $default - ); - - if (($this->installer->homepage !== null) - && ($this->installer->homepage !== 'current') - && file_exists(Hyde::path('resources/views/index.blade.php')) - ) { - if ($this->choice('Would you like to overwrite existing files?', [ - 'no', - 'yes', - ], 'no') === 'yes') { - $this->installer->allowFileOverwrites = true; - $this->warn('Okay, allowing files to be overwritten.'); - } else { - $this->info('Okay, files will not be overwritten.'); - } + if ($this->choice('Would you like to set the index.blade.php file?', [ + 'no', + 'yes', + ], 'no') === 'yes') { + + $options = [ + 'welcome: Default Welcome Page', + 'post-feed: Feed of Latest Posts', + 'blank: A Blank Layout Page', + ]; + + $this->installer->homepage = strtok($this->choice( + 'Which homepage would you like to use?', + $options, + 0 + ), ':'); + + } else { + $this->comment('Okay, skipping setting up a homepage.'); } + } private function printInstallerProperties() diff --git a/src/Services/HydeInstaller.php b/src/Services/HydeInstaller.php index 56ebac8a..32e482b1 100644 --- a/src/Services/HydeInstaller.php +++ b/src/Services/HydeInstaller.php @@ -17,7 +17,6 @@ class HydeInstaller public string|null $homepage; public array $warnings = []; - public bool $allowFileOverwrites = false; public function __construct() { @@ -138,18 +137,9 @@ private function ensureDotEnvIsSetup() */ private function publishHomepage(): void { - if (file_exists(Hyde::path('resources/views/index.blade.php')) && $this->allowFileOverwrites !== true) { - $this->warnings[] = [ - 'level' => 'warn', - 'message' => 'Refusing to publish homepage as an index.blade.php already exists.', - 'context' => 'You can force the file to overwritten using php hyde publish:homepage --force.' - ]; - return; - } - copy( Hyde::path("vendor/hyde/framework/resources/views/homepages/$this->homepage.blade.php"), - Hyde::path("resources/views/index.blade.php") + Hyde::path("resources/views/pages/index.blade.php") ); } }