Skip to content

Commit

Permalink
Hide the install command once it has been run, fix #280
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 5, 2022
1 parent 8f9547c commit e03b3f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Commands/HydeInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
Expand Down Expand Up @@ -48,6 +57,8 @@ public function handle(): int

$this->askToRebuildSite();

$this->markInstalled();

$this->newLine();

$this->line('<bg=blue;fg=white> </>');
Expand Down Expand Up @@ -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'));
}
}
16 changes: 16 additions & 0 deletions tests/Feature/Commands/HydeInstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit e03b3f4

Please sign in to comment.