diff --git a/src/Console/Commands/InstallCommand.php b/src/Console/Commands/InstallCommand.php index c45d280..70a32eb 100644 --- a/src/Console/Commands/InstallCommand.php +++ b/src/Console/Commands/InstallCommand.php @@ -3,6 +3,7 @@ namespace Saucebase\Installer\Console\Commands; use Illuminate\Console\Command; +use Illuminate\Console\View\TaskResult; use Illuminate\Support\Facades\Process; use Illuminate\Support\Str; use Laravel\Prompts\Elements\Element; @@ -318,7 +319,7 @@ public function install(): int $this->generateApplicationKey(); $installed = false; - $this->components->task('Installing Saucebase', function () use (&$installed) { + $this->task('Installing Saucebase', function () use (&$installed) { return $installed = $this->installCore(); }); @@ -351,8 +352,8 @@ protected function handleCIInstallation(): int $envOk = $this->ensureEnvFile(); $keyOk = $this->envHasAppKey(); - $this->components->task('Verifying .env', fn () => $envOk); - $this->components->task('Verifying app key', fn () => $keyOk); + $this->task('Verifying .env', fn () => $envOk); + $this->task('Verifying app key', fn () => $keyOk); if (! $envOk || ! $keyOk) { return self::FAILURE; @@ -540,7 +541,7 @@ public function envHasAppKey(): bool protected function generateApplicationKey(): void { - $this->components->task('Generating application key', function () { + $this->task('Generating application key', function () { if ($this->envHasAppKey()) { return true; } @@ -556,7 +557,7 @@ protected function setupDatabase(): bool $command = $fresh ? 'migrate:fresh' : 'migrate'; $ok = false; - $this->components->task($label, function () use ($command, &$ok) { + $this->task($label, function () use ($command, &$ok) { return $ok = $this->runArtisan([$command, '--seed', '--force'], 300); }); @@ -620,9 +621,11 @@ public function doInstallModules(array $selected, ?\Closure $run = null): bool $this->newLine(); $ok = false; - $this->components->task('Installing modules', function () use ($selected, $run, &$ok) { + $this->task('Installing modules', function () use ($selected, $run, &$ok) { return $ok = $run([ - 'php', 'artisan', 'saucebase:module-install', + 'php', + 'artisan', + 'saucebase:module-install', ...array_map(fn (string $package) => Str::after($package, '/'), $selected), '--no-interaction', ...($this->option('demo') ? ['--demo'] : []), @@ -677,12 +680,28 @@ protected function resolveModuleSelection(array $available): array protected function createStorageLink(): void { - $this->components->task('Creating storage link', fn () => $this->runArtisan(['storage:link'])); + $this->task('Creating storage link', fn () => $this->runArtisan(['storage:link'])); } protected function clearCaches(): void { - $this->components->task('Clearing caches', fn () => $this->runArtisan(['optimize:clear'])); + $this->task('Clearing caches', fn () => $this->runArtisan(['optimize:clear'])); + } + + /** + * A progress line for one step. Laravel shows FAIL only for its own failure value + * and DONE for anything else, `false` included, so a failed step looked done. + */ + protected function task(string $label, callable $step): bool + { + $ok = false; + $this->components->task($label, function () use ($step, &$ok) { + return ($ok = (bool) $step()) + ? TaskResult::Success->value + : TaskResult::Failure->value; + }); + + return $ok; } protected function isCI(): bool diff --git a/src/Console/Commands/NewCommand.php b/src/Console/Commands/NewCommand.php index c843a88..452360c 100644 --- a/src/Console/Commands/NewCommand.php +++ b/src/Console/Commands/NewCommand.php @@ -88,7 +88,8 @@ public function handle(): int return self::FAILURE; } - $this->line(' Setup continues below - see the final summary for the real next steps.'); + // Laravel's installer has just printed its own next steps; ours come at the end. + $this->line(' Laravel is ready. Now setting up Saucebase…'); $arguments = $this->installArguments($name, $driver, $stack, $ssl, $modules, $domain, $appName, $demo); $result = $this->call('install', $arguments); diff --git a/src/Environments/Environment.php b/src/Environments/Environment.php index 6bb3ab9..29f0556 100644 --- a/src/Environments/Environment.php +++ b/src/Environments/Environment.php @@ -135,9 +135,14 @@ protected function demoStep(InstallCommand $command): array { $password = $command->optionOrNull('demo') ? $this->readEnvValue($command, 'DEMO_PASSWORD') : null; - return $password === null ? [] : [ - "Sign in to any demo account with the password `{$password}`. It is DEMO_PASSWORD in .env, used when demo data is seeded", - ]; + if ($password === null) { + return []; + } + + // Auth's demo data has the one account that sees everything. + return [is_dir($command->path('modules/auth')) + ? "Sign in as `chef@saucebase.dev` (admin) with the password `{$password}`. Every demo account uses it; it is saved in .env as DEMO_PASSWORD" + : "Demo accounts use the password `{$password}`, saved in .env as DEMO_PASSWORD"]; } /** Hook: perform driver-specific steps before the module prompt. Return an exit code to abort, null to continue. */ diff --git a/src/Environments/HerdEnvironment.php b/src/Environments/HerdEnvironment.php index 0295fe8..6b39a09 100644 --- a/src/Environments/HerdEnvironment.php +++ b/src/Environments/HerdEnvironment.php @@ -59,7 +59,7 @@ protected function nextSteps(InstallCommand $command): array return [ ...($this->frontendBuilt ? [] : ['Install frontend dependencies: `npm install`']), $this->frontendBuilt ? 'For live reload while you edit: `npm run dev`' : 'Start Vite: `npm run dev`', - 'Open your app: `'.($this->readEnvValue($command, 'APP_URL') ?? '').'`', + 'Herd already serves your app: `'.($this->readEnvValue($command, 'APP_URL') ?? '').'`', ]; } diff --git a/tests/Feature/Environments/EnvironmentHelpersTest.php b/tests/Feature/Environments/EnvironmentHelpersTest.php index 33a1b56..8d127f1 100644 --- a/tests/Feature/Environments/EnvironmentHelpersTest.php +++ b/tests/Feature/Environments/EnvironmentHelpersTest.php @@ -98,6 +98,16 @@ public function test_a_demo_install_tells_the_user_the_demo_password(): void $this->assertStringContainsString('`s3cret`', $steps[0]); } + public function test_with_auth_it_names_the_admin_account_to_sign_in_with(): void + { + file_put_contents($this->tmp.'/.env', "DEMO_PASSWORD=s3cret\n"); + mkdir($this->tmp.'/modules/auth', recursive: true); + + $steps = $this->environment()->exposedDemoStep($this->command(demo: true)); + + $this->assertSame(['Sign in as `chef@saucebase.dev` (admin) with the password `s3cret`. Every demo account uses it; it is saved in .env as DEMO_PASSWORD'], $steps); + } + public function test_without_demo_content_no_password_is_shown(): void { file_put_contents($this->tmp.'/.env', "DEMO_PASSWORD=s3cret\n"); diff --git a/tests/Feature/Environments/HerdEnvironmentTest.php b/tests/Feature/Environments/HerdEnvironmentTest.php index edb96bd..f049cd1 100644 --- a/tests/Feature/Environments/HerdEnvironmentTest.php +++ b/tests/Feature/Environments/HerdEnvironmentTest.php @@ -55,6 +55,22 @@ public function test_it_links_and_secures_the_app_after_installing_it(): void $this->assertStringContainsString('APP_HOST=shop.test', (string) file_get_contents($this->app.'/.env')); } + public function test_the_summary_says_herd_already_serves_the_app(): void + { + $command = $this->command(installs: true, domain: 'shop.test'); + $env = new class extends HerdEnvironment + { + /** @return string[] */ + public function steps(InstallCommand $command): array + { + return $this->nextSteps($command); + } + }; + $env->run($command); + + $this->assertContains('Herd already serves your app: `https://shop.test`', $env->steps($command)); + } + public function test_without_ssl_it_only_links_and_serves_over_http(): void { $command = $this->command(installs: true, ssl: 'no'); diff --git a/tests/Unit/TaskResultTest.php b/tests/Unit/TaskResultTest.php new file mode 100644 index 0000000..57d6083 --- /dev/null +++ b/tests/Unit/TaskResultTest.php @@ -0,0 +1,54 @@ +command(); + + $this->assertFalse($command->step(fn () => false)); + $this->assertStringContainsString('FAIL', $output->fetch()); + } + + public function test_a_step_that_succeeds_is_shown_as_done(): void + { + [$command, $output] = $this->command(); + + $this->assertTrue($command->step(fn () => true)); + $this->assertStringContainsString('DONE', $output->fetch()); + } + + /** @return array{0: object, 1: BufferedOutput} */ + private function command(): array + { + $output = new BufferedOutput; + $style = new OutputStyle(new ArrayInput([]), $output); + + $command = new class($style) extends InstallCommand + { + public function __construct(OutputStyle $style) + { + parent::__construct(); + $this->output = $style; + $this->components = new Factory($style); + } + + public function step(callable $task): bool + { + return $this->task('Step', $task); + } + }; + + return [$command, $output]; + } +}