From e03b3f42ab41ce295cc50a869d13db5c02fbba80 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 5 May 2022 13:37:25 +0200 Subject: [PATCH] Hide the install command once it has been run, fix #280 --- src/Commands/HydeInstallCommand.php | 24 +++++++++++++++++++ .../Commands/HydeInstallCommandTest.php | 16 +++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Commands/HydeInstallCommand.php b/src/Commands/HydeInstallCommand.php index c8d860e5..37f4a7fc 100644 --- a/src/Commands/HydeInstallCommand.php +++ b/src/Commands/HydeInstallCommand.php @@ -21,6 +21,15 @@ class HydeInstallCommand extends Command public ?string $siteName = null; public ?string $siteUrl = null; + public function __construct() + { + parent::__construct(); + + if ($this->isInstalled()) { + $this->setHidden(); + } + } + public function handle(): int { $this->title('Welcome to HydePHP!'); @@ -48,6 +57,8 @@ public function handle(): int $this->askToRebuildSite(); + $this->markInstalled(); + $this->newLine(); $this->line(' '); @@ -127,4 +138,17 @@ protected function updateSiteUrl(): void ); file_put_contents(Hyde::path('config/hyde.php'), $config); } + + protected function markInstalled(): void + { + if (! is_dir(Hyde::path('.cache/hyde'))) { + mkdir(Hyde::path('.cache/hyde'), recursive: true); + } + touch(Hyde::path('.cache/hyde/installed')); + } + + protected function isInstalled(): bool + { + return file_exists(Hyde::path('.cache/hyde/installed')); + } } diff --git a/tests/Feature/Commands/HydeInstallCommandTest.php b/tests/Feature/Commands/HydeInstallCommandTest.php index f42d159a..10418786 100644 --- a/tests/Feature/Commands/HydeInstallCommandTest.php +++ b/tests/Feature/Commands/HydeInstallCommandTest.php @@ -2,7 +2,9 @@ namespace Tests\Feature\Commands; +use Hyde\Framework\Commands\HydeInstallCommand; use Hyde\Framework\Hyde; +use Illuminate\Support\Facades\File; use Tests\TestCase; /** @@ -110,4 +112,18 @@ public function test_command_calls_publish_homepage_command() ->expectsQuestion('Would you like to rebuild the site?', false) ->assertExitCode(0); } + + public function test_mark_installed_creates_cache_directory_if_it_doesnt_exist() + { + File::deleteDirectory(Hyde::path('.cache/hyde')); + $this->assertDirectoryDoesNotExist(Hyde::path('.cache/hyde')); + $mock = new Class extends HydeInstallCommand { + public function test() + { + $this->markInstalled(); + } + }; + $mock->test(); + $this->assertDirectoryExists(Hyde::path('.cache/hyde')); + } }