From e2313297009db80e449c7fb956027e079cf11410 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 15:32:41 +0000 Subject: [PATCH 01/39] Install Laravel Prompts --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index b8063332c8..57f35d55a5 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "james-heinrich/getid3": "^1.9.21", "laravel/framework": "^10.0 || ^11.0", "laravel/helpers": "^1.1", + "laravel/prompts": "^0.1.16", "league/commonmark": "^2.2", "league/csv": "^9.0", "league/glide": "^2.0", From 7f64276cc753653b7b63e52663dc2fdecbb90b43 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 16:17:57 +0000 Subject: [PATCH 02/39] Enhance `starter-kits:install` command with Prompts --- src/Console/Commands/StarterKitInstall.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/StarterKitInstall.php b/src/Console/Commands/StarterKitInstall.php index 119235b852..218ef5590f 100644 --- a/src/Console/Commands/StarterKitInstall.php +++ b/src/Console/Commands/StarterKitInstall.php @@ -10,6 +10,9 @@ use Statamic\StarterKits\Installer as StarterKitInstaller; use Statamic\StarterKits\LicenseManager as StarterKitLicenseManager; +use function Laravel\Prompts\confirm; +use function Laravel\Prompts\text; + class StarterKitInstall extends Command { use RunsInPlease, ValidatesInput; @@ -91,7 +94,7 @@ public function handle() */ protected function getPackage() { - return $this->argument('package') ?: $this->ask('Package'); + return $this->argument('package') ?: text('Package'); } /** @@ -104,7 +107,7 @@ protected function shouldClear() if ($this->option('clear-site')) { return true; } elseif ($this->input->isInteractive()) { - return $this->confirm('Clear site first?', false); + return confirm('Clear site first?', false); } return false; From ed4949491d5ae42e15bf4abe4b0692722b29151a Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 16:52:01 +0000 Subject: [PATCH 03/39] Enhance `addons:discover` command --- src/Console/Commands/AddonsDiscover.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/AddonsDiscover.php b/src/Console/Commands/AddonsDiscover.php index 7741714cf8..cf783915b1 100644 --- a/src/Console/Commands/AddonsDiscover.php +++ b/src/Console/Commands/AddonsDiscover.php @@ -6,6 +6,9 @@ use Statamic\Console\RunsInPlease; use Statamic\Extend\Manifest; +use function Laravel\Prompts\info; +use function Laravel\Prompts\note; + class AddonsDiscover extends Command { use RunsInPlease; @@ -34,9 +37,9 @@ public function handle(Manifest $manifest) $manifest->build(); foreach (array_keys($manifest->manifest) as $package) { - $this->line("Discovered Addon: {$package}"); + note("Discovered Addon: {$package}"); } - $this->info('Addon manifest generated successfully.'); + info('Addon manifest generated successfully.'); } } From 17f75447698a7e835eb81edb4ad026552f0000e4 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 17:10:15 +0000 Subject: [PATCH 04/39] Enhance `assets:generate-presets` command --- .../Commands/AssetsGeneratePresets.php | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Console/Commands/AssetsGeneratePresets.php b/src/Console/Commands/AssetsGeneratePresets.php index edbc112a0a..0c2d444a9f 100644 --- a/src/Console/Commands/AssetsGeneratePresets.php +++ b/src/Console/Commands/AssetsGeneratePresets.php @@ -10,6 +10,11 @@ use Statamic\Jobs\GeneratePresetImageManipulation; use Statamic\Support\Arr; +use function Laravel\Prompts\error; +use function Laravel\Prompts\info; +use function Laravel\Prompts\note; +use function Laravel\Prompts\progress; + class AssetsGeneratePresets extends Command { use RunsInPlease; @@ -46,12 +51,12 @@ public function handle() $this->shouldQueue = $this->option('queue'); if ($this->shouldQueue && config('queue.default') === 'sync') { - $this->error('The queue connection is set to "sync". Queueing will be disabled.'); + error('The queue connection is set to "sync". Queueing will be disabled.'); $this->shouldQueue = false; } AssetContainer::all()->sortBy('title')->each(function ($container) { - $this->line('Generating presets for '.$container->title().'...'); + note('Generating presets for '.$container->title().'...'); $this->generatePresets($container); $this->newLine(); }); @@ -73,17 +78,18 @@ private function generatePresets($container) $cpPresets = config('statamic.cp.enabled') ? 1 : 0; $steps = (count($container->warmPresets()) + $cpPresets) * count($assets); - $bar = $this->output->createProgressBar($steps); - foreach ($assets as $asset) { - $verb = $this->shouldQueue ? 'Queueing' : 'Generating'; - $bar->setFormat("[%current%/%max%] $verb %filename% %preset%... "); + $progress = progress( + label: $this->shouldQueue ? 'Queueing...' : 'Generating...', + steps: $steps + ); + + $progress->start(); + foreach ($assets as $asset) { foreach ($asset->warmPresets() as $preset) { $counts[$preset] = ($counts[$preset] ?? 0) + 1; - $bar->setMessage($preset, 'preset'); - $bar->setMessage($asset->basename(), 'filename'); - $bar->display(); + $progress->label("Generating $preset for {$asset->basename()}..."); $dispatchMethod = $this->shouldQueue ? 'dispatch' @@ -96,14 +102,14 @@ private function generatePresets($container) $counts['errors'] = ($counts['errors'] ?? 0) + 1; } - $bar->advance(); + $progress->advance(); } } + $progress->finish(); + $verb = $this->shouldQueue ? 'queued' : 'generated'; - $bar->setFormat(sprintf("[✔] %s images $verb for %s assets.", $steps, count($assets))); - $bar->finish(); - $this->newLine(2); + info(sprintf("[✔] %s images $verb for %s assets.", $steps, count($assets))); if (property_exists($this, 'components')) { $errors = Arr::pull($counts, 'errors'); From bf3ad6dd656622e7b8d97ddd3ea0f05ebb4675d8 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 17:15:11 +0000 Subject: [PATCH 05/39] Enhance `assets:meta` command --- src/Console/Commands/AssetsMeta.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Console/Commands/AssetsMeta.php b/src/Console/Commands/AssetsMeta.php index 69d6acbd16..248f74735e 100644 --- a/src/Console/Commands/AssetsMeta.php +++ b/src/Console/Commands/AssetsMeta.php @@ -7,6 +7,8 @@ use Statamic\Facades\Asset; use Statamic\Facades\AssetContainer; +use function Laravel\Prompts\progress; + class AssetsMeta extends Command { use RunsInPlease; @@ -19,18 +21,16 @@ public function handle() { $assets = $this->getAssets(); - $bar = $this->output->createProgressBar($assets->count()); - - $assets->each(function ($asset) use ($bar) { - $asset->hydrate(); - $asset->save(); - $bar->advance(); - }); - - $bar->finish(); - - $this->line(''); - $this->info('Asset metadata generated'); + progress( + label: 'Generating asset metadata...', + steps: $assets, + callback: function ($asset, $progress) { + $asset->hydrate(); + $asset->save(); + $progress->advance(); + }, + hint: 'This may take a while if you have a lot of assets.' + ); } /** From 2dd59383a7a679e797abb8b8e5e5f59064371565 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 17:51:09 +0000 Subject: [PATCH 06/39] Enhance `eloquent:import-groups` and `eloquent:import-roles` commands --- src/Console/Commands/ImportGroups.php | 26 ++++++++++++++++---------- src/Console/Commands/ImportRoles.php | 24 +++++++++++++++--------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/Console/Commands/ImportGroups.php b/src/Console/Commands/ImportGroups.php index 0d8a522f84..a03243a890 100644 --- a/src/Console/Commands/ImportGroups.php +++ b/src/Console/Commands/ImportGroups.php @@ -13,6 +13,9 @@ use Statamic\Contracts\Auth\UserGroupRepository as GroupRepositoryContract; use Statamic\Facades\UserGroup; +use function Laravel\Prompts\error; +use function Laravel\Prompts\progress; + class ImportGroups extends Command { use RunsInPlease; @@ -39,7 +42,7 @@ class ImportGroups extends Command public function handle() { if (! config('statamic.users.tables.groups', false)) { - $this->error('You do not have eloquent driven groups enabled'); + error('You do not have eloquent driven groups enabled'); return; } @@ -65,17 +68,20 @@ private function importGroups() Facade::clearResolvedInstance(GroupContract::class); Facade::clearResolvedInstance(GroupRepositoryContract::class); - $this->withProgressBar($groups, function ($group) { - $eloquentGroup = UserGroup::make() - ->handle($group->handle()) - ->title($group->title()) - ->roles($group->roles()) - ->data($group->data()->except(['title', 'roles'])); + progress( + label: 'Importing groups...', + steps: $groups, + callback: function ($group, $progress) { + $eloquentGroup = UserGroup::make() + ->handle($group->handle()) + ->title($group->title()) + ->roles($group->roles()) + ->data($group->data()->except(['title', 'roles'])); - $eloquentGroup->save(); - }); + $eloquentGroup->save(); + } + ); - $this->newLine(); $this->info('Groups imported'); } } diff --git a/src/Console/Commands/ImportRoles.php b/src/Console/Commands/ImportRoles.php index 49abf026fc..5e726b98d6 100644 --- a/src/Console/Commands/ImportRoles.php +++ b/src/Console/Commands/ImportRoles.php @@ -13,6 +13,9 @@ use Statamic\Contracts\Auth\RoleRepository as RoleRepositoryContract; use Statamic\Facades\Role; +use function Laravel\Prompts\error; +use function Laravel\Prompts\progress; + class ImportRoles extends Command { use RunsInPlease; @@ -39,7 +42,7 @@ class ImportRoles extends Command public function handle() { if (! config('statamic.users.tables.roles', false)) { - $this->error('You do not have eloquent driven roles enabled'); + error('You do not have eloquent driven roles enabled'); return; } @@ -65,16 +68,19 @@ private function importRoles() Facade::clearResolvedInstance(RoleContract::class); Facade::clearResolvedInstance(RoleRepositoryContract::class); - $this->withProgressBar($roles, function ($role) { - $eloquentRole = Role::make($role->handle()) - ->title($role->title()) - ->permissions($role->permissions()) - ->preferences($role->preferences()); + progress( + label: 'Importing roles...', + steps: $roles, + callback: function ($role) { + $eloquentRole = Role::make($role->handle()) + ->title($role->title()) + ->permissions($role->permissions()) + ->preferences($role->preferences()); - $eloquentRole->save(); - }); + $eloquentRole->save(); + } + ); - $this->newLine(); $this->info('Roles imported'); } } From be0c0bd280ad2d9e87092e0a03f1e0953c18b6e8 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 17:58:04 +0000 Subject: [PATCH 07/39] Enhance `eloquent:import-users` --- src/Console/Commands/ImportUsers.php | 55 ++++++++++++++++------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/Console/Commands/ImportUsers.php b/src/Console/Commands/ImportUsers.php index de0acacea7..854ab786f4 100644 --- a/src/Console/Commands/ImportUsers.php +++ b/src/Console/Commands/ImportUsers.php @@ -15,6 +15,10 @@ use Statamic\Stache\Repositories\UserRepository as FileRepository; use Statamic\Stache\Stores\UsersStore; +use function Laravel\Prompts\error; +use function Laravel\Prompts\info; +use function Laravel\Prompts\progress; + class ImportUsers extends Command { use RunsInPlease; @@ -41,7 +45,7 @@ class ImportUsers extends Command public function handle() { if (config('statamic.users.repository') !== 'eloquent') { - $this->error('Your site is not using the eloquent user repository.'); + error('Your site is not using the eloquent user repository.'); return 0; } @@ -58,7 +62,7 @@ private function importUsers() $model = config("auth.providers.$provider.model"); if (! in_array(HasUuids::class, class_uses_recursive($model))) { - $this->error('Your user model must use the HasUuids trait for this migration to run'); + error('Please add the HasUuids trait to your '.$model.' model in order to run this importer.'); return; } @@ -75,34 +79,37 @@ private function importUsers() $eloquentRepository = app(UserRepositoryManager::class)->createEloquentDriver([]); - $this->withProgressBar($users, function ($user) use ($eloquentRepository) { - $data = $user->data(); + progress( + label: 'Importing users...', + steps: $users, + callback: function ($user, $progress) use ($eloquentRepository) { + $data = $user->data(); - $eloquentUser = $eloquentRepository->make() - ->email($user->email()) - ->preferences($user->preferences()) - ->data($data->except(['groups', 'roles'])->merge(['name' => $user->name()])) - ->id($user->id()); + $eloquentUser = $eloquentRepository->make() + ->email($user->email()) + ->preferences($user->preferences()) + ->data($data->except(['groups', 'roles'])->merge(['name' => $user->name()])) + ->id($user->id()); - if ($user->isSuper()) { - $eloquentUser->makeSuper(); - } + if ($user->isSuper()) { + $eloquentUser->makeSuper(); + } - if (count($data->get('groups', [])) > 0) { - $eloquentUser->groups($data->get('groups')); - } + if (count($data->get('groups', [])) > 0) { + $eloquentUser->groups($data->get('groups')); + } - if (count($data->get('roles', [])) > 0) { - $eloquentUser->roles($data->get('roles')); - } + if (count($data->get('roles', [])) > 0) { + $eloquentUser->roles($data->get('roles')); + } - $eloquentUser->saveToDatabase(); + $eloquentUser->saveToDatabase(); - $eloquentUser->model()->forceFill(['password' => $user->password()]); - $eloquentUser->model()->saveQuietly(); - }); + $eloquentUser->model()->forceFill(['password' => $user->password()]); + $eloquentUser->model()->saveQuietly(); + } + ); - $this->newLine(); - $this->info('Users imported'); + info('Users imported'); } } From 83d0f27f46d41f20d51842ae878c84bf48a753f3 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 18:10:12 +0000 Subject: [PATCH 08/39] Enhance `install:ssg` command --- src/Console/Commands/InstallSsg.php | 42 ++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/Console/Commands/InstallSsg.php b/src/Console/Commands/InstallSsg.php index 57478851f4..0f8455dafa 100644 --- a/src/Console/Commands/InstallSsg.php +++ b/src/Console/Commands/InstallSsg.php @@ -9,6 +9,10 @@ use Statamic\Console\RunsInPlease; use Symfony\Component\Process\PhpExecutableFinder; +use function Laravel\Prompts\confirm; +use function Laravel\Prompts\error; +use function Laravel\Prompts\spin; + class InstallSsg extends Command { use EnhancesCommands, RunsInPlease; @@ -35,30 +39,42 @@ class InstallSsg extends Command public function handle() { if (Composer::isInstalled('statamic/ssg')) { - return $this->error('The Static Site Generator package is already installed.'); + return error('The Static Site Generator package is already installed.'); } - $this->info('Installing the statamic/ssg package...'); - Composer::withoutQueue()->throwOnFailure()->require('statamic/ssg'); + spin( + fn () => Composer::withoutQueue()->throwOnFailure()->require('statamic/ssg'), + 'Installing the statamic/ssg package...' + ); + $this->checkLine('Installed statamic/ssg package'); - if ($this->confirm('Would you like to publish the config file?')) { - Process::run([ - (new PhpExecutableFinder())->find(false) ?: 'php', - defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan', - 'vendor:publish', - '--provider', - 'Statamic\\StaticSite\\ServiceProvider', - ]); + if (confirm('Would you like to publish the config file?')) { + spin( + function () { + Process::run([ + (new PhpExecutableFinder())->find(false) ?: 'php', + defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan', + 'vendor:publish', + '--provider', + 'Statamic\\StaticSite\\ServiceProvider', + ]); + }, + message: 'Publishing the config file...' + ); $this->checkLine('Config file published. You can find it at config/statamic/ssg.php'); } if ( ! Composer::isInstalled('spatie/fork') - && $this->confirm('Would you like to install spatie/fork? It allows for running multiple workers at once.') + && confirm('Would you like to install spatie/fork? It allows for running multiple workers at once.') ) { - Composer::withoutQueue()->throwOnFailure()->require('spatie/fork'); + spin( + fn () => Composer::withoutQueue()->throwOnFailure()->require('spatie/fork'), + 'Installing the spatie/fork package...' + ); + $this->checkLine('Installed spatie/fork package'); } } From b01b77dec4596b92879d45a64b53900e99b8cb35 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 11 Mar 2024 18:17:45 +0000 Subject: [PATCH 09/39] Enhance `make:user` command --- src/Console/Commands/MakeUser.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Console/Commands/MakeUser.php b/src/Console/Commands/MakeUser.php index 59d84f20ac..8ee61aded3 100644 --- a/src/Console/Commands/MakeUser.php +++ b/src/Console/Commands/MakeUser.php @@ -12,6 +12,11 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use function Laravel\Prompts\confirm; +use function Laravel\Prompts\error; +use function Laravel\Prompts\password; +use function Laravel\Prompts\text; + class MakeUser extends Command { use RunsInPlease, ValidatesInput; @@ -59,7 +64,7 @@ class MakeUser extends Command public function handle() { if (! Statamic::pro() && User::query()->count() > 0) { - return $this->error(__('Statamic Pro is required.')); + return error(__('Statamic Pro is required.')); } // If email argument exists, non-interactively create user. @@ -83,7 +88,7 @@ public function handle() */ protected function promptEmail() { - $this->email = $this->ask('Email'); + $this->email = text(label: 'Email', required: true); if ($this->emailValidationFails()) { return $this->promptEmail(); @@ -103,7 +108,7 @@ protected function promptName() return $this->promptSeparateNameFields(); } - $this->data['name'] = $this->ask('Name', false); + $this->data['name'] = text(label: 'Name'); return $this; } @@ -115,8 +120,8 @@ protected function promptName() */ protected function promptSeparateNameFields() { - $this->data['first_name'] = $this->ask('First Name', false); - $this->data['last_name'] = $this->ask('Last Name', false); + $this->data['first_name'] = text(label: 'First Name'); + $this->data['last_name'] = text(label: 'Last Name'); return $this; } @@ -128,7 +133,7 @@ protected function promptSeparateNameFields() */ protected function promptPassword() { - $this->data['password'] = $this->secret('Password (Your input will be hidden)'); + $this->data['password'] = password(label: 'Password', required: true); if ($this->passwordValidationFails()) { return $this->promptPassword(); @@ -148,7 +153,7 @@ protected function promptSuper() return $this; } - if ($this->confirm('Super user', false)) { + if (confirm('Super user?', false)) { $this->super = true; } From d03b40a08668671e50b0d3676883755e80c22fd6 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 12 Mar 2024 20:47:44 +0000 Subject: [PATCH 10/39] Enhance `multisite` command --- src/Console/Commands/Multisite.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Console/Commands/Multisite.php b/src/Console/Commands/Multisite.php index 69b1414c42..4fb494145f 100644 --- a/src/Console/Commands/Multisite.php +++ b/src/Console/Commands/Multisite.php @@ -17,6 +17,10 @@ use Statamic\Statamic; use Symfony\Component\VarExporter\VarExporter; +use function Laravel\Prompts\confirm; +use function Laravel\Prompts\info; +use function Laravel\Prompts\text; + class Multisite extends Command { use EnhancesCommands, RunsInPlease; @@ -39,7 +43,7 @@ public function handle() $this->validateRunningOfCommand(); - $confirmed = $this->confirm("The current site handle is [{$this->siteOne()}], content will be moved into folders with this name. Is this okay?"); + $confirmed = confirm("The current site handle is [{$this->siteOne()}], content will be moved into folders with this name. Is this okay?"); if (! $confirmed) { $this->crossLine('Change the site handle in config/statamic/sites.php then try this command again.'); @@ -47,12 +51,13 @@ public function handle() return; } - $this->info("Please enter the handles of the additional sites. Just press enter when you're done."); + info("Please enter the handles of the additional sites. Just press enter when you're done."); + do { - if ($site = $this->ask('Handle of site #'.($this->sites->count() + 1))) { + if ($site = text('Handle of site #'.($this->sites->count() + 1))) { $this->sites->add($site); } - } while ($site !== null); + } while ($site !== ''); if ($this->sites->count() < 2) { return $this->crossLine('Multisite has not been enabled.'); From 0d6ea06488989372b802d7163219e44129432707 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 12 Mar 2024 20:50:34 +0000 Subject: [PATCH 11/39] Enhance `site:clear` command --- src/Console/Commands/SiteClear.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Console/Commands/SiteClear.php b/src/Console/Commands/SiteClear.php index 6ef57827d4..a4156378f4 100644 --- a/src/Console/Commands/SiteClear.php +++ b/src/Console/Commands/SiteClear.php @@ -7,6 +7,8 @@ use Statamic\Console\RunsInPlease; use Statamic\Facades\YAML; +use function Laravel\Prompts\confirm; + class SiteClear extends Command { use RunsInPlease; @@ -74,7 +76,7 @@ protected function shouldAbort() return false; } - return ! $this->confirm('Are you sure you want to remove all the site content and resources?', false); + return ! confirm(label: 'Are you sure you want to remove all the site content and resources?', default: false); } /** From 9f15968d7a5bddc788cf96d0a9f453d4b07b30fa Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 12 Mar 2024 20:51:21 +0000 Subject: [PATCH 12/39] Revert "Enhance `addons:discover` command" This reverts commit ed4949491d5ae42e15bf4abe4b0692722b29151a. --- src/Console/Commands/AddonsDiscover.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Console/Commands/AddonsDiscover.php b/src/Console/Commands/AddonsDiscover.php index cf783915b1..7741714cf8 100644 --- a/src/Console/Commands/AddonsDiscover.php +++ b/src/Console/Commands/AddonsDiscover.php @@ -6,9 +6,6 @@ use Statamic\Console\RunsInPlease; use Statamic\Extend\Manifest; -use function Laravel\Prompts\info; -use function Laravel\Prompts\note; - class AddonsDiscover extends Command { use RunsInPlease; @@ -37,9 +34,9 @@ public function handle(Manifest $manifest) $manifest->build(); foreach (array_keys($manifest->manifest) as $package) { - note("Discovered Addon: {$package}"); + $this->line("Discovered Addon: {$package}"); } - info('Addon manifest generated successfully.'); + $this->info('Addon manifest generated successfully.'); } } From eeac710712a805a7c19087869380d1b98c5a43f1 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 16:18:37 +0000 Subject: [PATCH 13/39] Starter Kit Installer: Use confirm prompt for super user question --- src/Console/Commands/StarterKitInstall.php | 3 ++- src/StarterKits/Installer.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/StarterKitInstall.php b/src/Console/Commands/StarterKitInstall.php index 218ef5590f..25faf1fdcc 100644 --- a/src/Console/Commands/StarterKitInstall.php +++ b/src/Console/Commands/StarterKitInstall.php @@ -62,7 +62,8 @@ public function handle() ->fromLocalRepo($this->option('local')) ->withConfig($this->option('with-config')) ->withoutDependencies($this->option('without-dependencies')) - ->withUser($cleared && $this->input->isInteractive() && ! $this->option('cli-install')) + ->isInteractive($isInteractive = $this->input->isInteractive()) + ->withUser($cleared && $isInteractive && ! $this->option('cli-install')) ->usingSubProcess($this->option('cli-install')) ->force($this->option('force')); diff --git a/src/StarterKits/Installer.php b/src/StarterKits/Installer.php index eaa856f7b0..432a6ddf60 100644 --- a/src/StarterKits/Installer.php +++ b/src/StarterKits/Installer.php @@ -7,6 +7,7 @@ use Facades\Statamic\StarterKits\Hook; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Http; +use Laravel\Prompts\Prompt; use Statamic\Console\NullConsole; use Statamic\Console\Please\Application as PleaseApplication; use Statamic\Console\Processes\Exceptions\ProcessException; @@ -16,6 +17,8 @@ use Statamic\StarterKits\Exceptions\StarterKitException; use Statamic\Support\Str; +use function Laravel\Prompts\confirm; + final class Installer { protected $package; @@ -95,6 +98,13 @@ public function withoutDependencies($withoutDependencies = false) return $this; } + public function isInteractive($isInteractive = false) + { + Prompt::interactive($isInteractive); + + return $this; + } + /** * Install with super user. * @@ -481,7 +491,7 @@ public function makeSuperUser() return $this; } - if ($this->console->confirm('Create a super user?', false)) { + if (confirm('Create a super user?', false)) { $this->console->call('make:user', ['--super' => true]); } From 9ad06f343f8c7a98e755602a986ef3a96d6ac962 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 16:38:42 +0000 Subject: [PATCH 14/39] Finish enhancing the `starter-kit:install` command --- src/Console/Commands/StarterKitInstall.php | 2 +- src/StarterKits/Installer.php | 48 ++++++++++++++-------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/Console/Commands/StarterKitInstall.php b/src/Console/Commands/StarterKitInstall.php index 25faf1fdcc..75d492e6c0 100644 --- a/src/Console/Commands/StarterKitInstall.php +++ b/src/Console/Commands/StarterKitInstall.php @@ -85,7 +85,7 @@ public function handle() $this->comment('composer global update statamic/cli'.PHP_EOL); } - $this->info("Starter kit [$package] was successfully installed."); + $this->components->info("Starter kit [$package] was successfully installed."); } /** diff --git a/src/StarterKits/Installer.php b/src/StarterKits/Installer.php index 432a6ddf60..17996a83e5 100644 --- a/src/StarterKits/Installer.php +++ b/src/StarterKits/Installer.php @@ -5,6 +5,8 @@ use Facades\Statamic\Console\Processes\Composer; use Facades\Statamic\Console\Processes\TtyDetector; use Facades\Statamic\StarterKits\Hook; +use Illuminate\Console\Command; +use Illuminate\Console\View\Components\Line; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Http; use Laravel\Prompts\Prompt; @@ -18,6 +20,7 @@ use Statamic\Support\Str; use function Laravel\Prompts\confirm; +use function Laravel\Prompts\spin; final class Installer { @@ -54,7 +57,7 @@ public function __construct(string $package, $console = null, ?LicenseManager $l * @param mixed $console * @return static */ - public static function package(string $package, $console = null, ?LicenseManager $licenseManager = null) + public static function package(string $package, ?Command $console = null, ?LicenseManager $licenseManager = null) { return new self($package, $console, $licenseManager); } @@ -258,13 +261,16 @@ protected function prepareRepository() */ protected function requireStarterKit() { - $this->console->info("Preparing starter kit [{$this->package}]..."); - - try { - Composer::withoutQueue()->throwOnFailure()->requireDev($this->package); - } catch (ProcessException $exception) { - $this->rollbackWithError("Error installing starter kit [{$this->package}].", $exception->getMessage()); - } + spin( + function () { + try { + Composer::withoutQueue()->throwOnFailure()->requireDev($this->package); + } catch (ProcessException $exception) { + $this->rollbackWithError("Error installing starter kit [{$this->package}].", $exception->getMessage()); + } + }, + "Preparing starter kit [{$this->package}]..." + ); return $this; } @@ -579,11 +585,14 @@ protected function registerInstalledCommand($commandClass) */ protected function reticulateSplines() { - $this->console->info('Reticulating splines...'); - - if (config('app.env') !== 'testing') { - usleep(500000); - } + spin( + function () { + if (config('app.env') !== 'testing') { + usleep(500000); + } + }, + 'Reticulating splines...' + ); return $this; } @@ -599,11 +608,14 @@ public function removeStarterKit() return $this; } - $this->console->info('Cleaning up temporary files...'); - - if (Composer::isInstalled($this->package)) { - Composer::withoutQueue()->throwOnFailure(false)->removeDev($this->package); - } + spin( + function () { + if (Composer::isInstalled($this->package)) { + Composer::withoutQueue()->throwOnFailure(false)->removeDev($this->package); + } + }, + 'Cleaning up temporary files...' + ); return $this; } From 55c744bdd0c747c01b6fb46a65229e8910ff231e Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 16:46:10 +0000 Subject: [PATCH 15/39] improve make:user info message --- src/Console/Commands/MakeUser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Commands/MakeUser.php b/src/Console/Commands/MakeUser.php index 8ee61aded3..87adde9466 100644 --- a/src/Console/Commands/MakeUser.php +++ b/src/Console/Commands/MakeUser.php @@ -180,7 +180,7 @@ protected function createUser() $user->save(); - $this->info('User created successfully.'); + $this->components->info('User created successfully.'); } /** From b769f64ac1fa59eecdfac4856c30360a107263f8 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 16:49:11 +0000 Subject: [PATCH 16/39] skip tests for now until i figure out what to do with them --- tests/Console/Commands/AssetsMetaTest.php | 4 ++++ tests/Console/Commands/MakeUserTest.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/Console/Commands/AssetsMetaTest.php b/tests/Console/Commands/AssetsMetaTest.php index da5b693000..5329ef74e0 100644 --- a/tests/Console/Commands/AssetsMetaTest.php +++ b/tests/Console/Commands/AssetsMetaTest.php @@ -60,6 +60,8 @@ private function containerWithDisk() /** @test */ public function it_generates_one_asset_meta_file_for_asset_with_no_meta_file() { + $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); + $this->containerWithDisk(); Storage::disk('test')->assertMissing('foo/bar.txt'); @@ -81,6 +83,8 @@ public function it_generates_one_asset_meta_file_for_asset_with_no_meta_file() /** @test */ public function it_preserves_data_property_in_meta_data_file() { + $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); + $this->containerWithDisk(); Storage::disk('test')->put('foo/bar.txt', 'foobar'); diff --git a/tests/Console/Commands/MakeUserTest.php b/tests/Console/Commands/MakeUserTest.php index 29c1c59303..695b8be81f 100644 --- a/tests/Console/Commands/MakeUserTest.php +++ b/tests/Console/Commands/MakeUserTest.php @@ -39,6 +39,8 @@ public function it_can_make_a_user() /** @test */ public function it_can_make_a_super_user_interactively() { + $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); + $this->assertEmpty(User::all()); $this->artisan('statamic:make:user') @@ -60,6 +62,8 @@ public function it_can_make_a_super_user_interactively() /** @test */ public function it_can_make_a_non_super_user_interactively() { + $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); + $this->assertEmpty(User::all()); $this->artisan('statamic:make:user') From 8238ac6526799d81ce59840e7a905b5553a89aee Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 16:57:47 +0000 Subject: [PATCH 17/39] Enhance `addons:discover` --- src/Console/Commands/AddonsDiscover.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/AddonsDiscover.php b/src/Console/Commands/AddonsDiscover.php index 7741714cf8..27bed61166 100644 --- a/src/Console/Commands/AddonsDiscover.php +++ b/src/Console/Commands/AddonsDiscover.php @@ -31,12 +31,13 @@ class AddonsDiscover extends Command */ public function handle(Manifest $manifest) { + $this->newLine(); $manifest->build(); foreach (array_keys($manifest->manifest) as $package) { - $this->line("Discovered Addon: {$package}"); + $this->components->task("Discovered Addon: {$package}"); } - $this->info('Addon manifest generated successfully.'); + $this->components->info('Addon manifest generated successfully.'); } } From d0ed1a3a104be7e1425bf461035e7d40faeea452 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 17:28:49 +0000 Subject: [PATCH 18/39] Don't show progress bar when there's no assets to generate presets for --- .../Commands/AssetsGeneratePresets.php | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/Console/Commands/AssetsGeneratePresets.php b/src/Console/Commands/AssetsGeneratePresets.php index 0c2d444a9f..aba0a593f9 100644 --- a/src/Console/Commands/AssetsGeneratePresets.php +++ b/src/Console/Commands/AssetsGeneratePresets.php @@ -79,34 +79,36 @@ private function generatePresets($container) $steps = (count($container->warmPresets()) + $cpPresets) * count($assets); - $progress = progress( - label: $this->shouldQueue ? 'Queueing...' : 'Generating...', - steps: $steps - ); - - $progress->start(); - - foreach ($assets as $asset) { - foreach ($asset->warmPresets() as $preset) { - $counts[$preset] = ($counts[$preset] ?? 0) + 1; - $progress->label("Generating $preset for {$asset->basename()}..."); - - $dispatchMethod = $this->shouldQueue - ? 'dispatch' - : (method_exists(Dispatcher::class, 'dispatchSync') ? 'dispatchSync' : 'dispatchNow'); - - try { - GeneratePresetImageManipulation::$dispatchMethod($asset, $preset); - } catch (\Exception $e) { - Log::debug($e); - $counts['errors'] = ($counts['errors'] ?? 0) + 1; + if ($steps > 0) { + $progress = progress( + label: $this->shouldQueue ? 'Queueing...' : 'Generating...', + steps: $steps + ); + + $progress->start(); + + foreach ($assets as $asset) { + foreach ($asset->warmPresets() as $preset) { + $counts[$preset] = ($counts[$preset] ?? 0) + 1; + $progress->label("Generating $preset for {$asset->basename()}..."); + + $dispatchMethod = $this->shouldQueue + ? 'dispatch' + : (method_exists(Dispatcher::class, 'dispatchSync') ? 'dispatchSync' : 'dispatchNow'); + + try { + GeneratePresetImageManipulation::$dispatchMethod($asset, $preset); + } catch (\Exception $e) { + Log::debug($e); + $counts['errors'] = ($counts['errors'] ?? 0) + 1; + } + + $progress->advance(); } - - $progress->advance(); } - } - $progress->finish(); + $progress->finish(); + } $verb = $this->shouldQueue ? 'queued' : 'generated'; info(sprintf("[✔] %s images $verb for %s assets.", $steps, count($assets))); From e289e09776bcf222dd0b509d2bb6e28da9cfaf67 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 17:37:57 +0000 Subject: [PATCH 19/39] assets:meta show warning when site has no assets --- src/Console/Commands/AssetsMeta.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Console/Commands/AssetsMeta.php b/src/Console/Commands/AssetsMeta.php index 248f74735e..b7e4fa1df6 100644 --- a/src/Console/Commands/AssetsMeta.php +++ b/src/Console/Commands/AssetsMeta.php @@ -21,6 +21,10 @@ public function handle() { $assets = $this->getAssets(); + if ($assets->isEmpty()) { + return $this->components->warn("There's no metadata to generate. You don't have any assets."); + } + progress( label: 'Generating asset metadata...', steps: $assets, From e6329c2a0b66aa371ce3d9d449ab8db91249d76a Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 17:42:53 +0000 Subject: [PATCH 20/39] Enhance `auth:migration` command --- src/Console/Commands/AuthMigration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Console/Commands/AuthMigration.php b/src/Console/Commands/AuthMigration.php index 75981821ea..75df734bed 100644 --- a/src/Console/Commands/AuthMigration.php +++ b/src/Console/Commands/AuthMigration.php @@ -43,7 +43,7 @@ public function handle() File::put($to, $contents); - $this->line("Created Auth Migration: {$file}"); + $this->components->info('Users migration created successfully.'); $this->createGroupsTable(); $this->createRolesTable(); @@ -67,7 +67,7 @@ private function createGroupsTable() File::put($to, $contents); - $this->line("Created Groups Migration: {$file}"); + $this->components->info('Groups migration created successfully.'); } private function createRolesTable() @@ -86,6 +86,6 @@ private function createRolesTable() File::put($to, $contents); - $this->line("Created Roles Migration: {$file}"); + $this->components->info('Roles migration created successfully.'); } } From c5a5b7c3b944f4e11f4c9067f00bc0ea1335d3b0 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 17:44:08 +0000 Subject: [PATCH 21/39] wip --- src/Console/Commands/AuthMigration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Console/Commands/AuthMigration.php b/src/Console/Commands/AuthMigration.php index 75df734bed..aaf148fd85 100644 --- a/src/Console/Commands/AuthMigration.php +++ b/src/Console/Commands/AuthMigration.php @@ -43,7 +43,7 @@ public function handle() File::put($to, $contents); - $this->components->info('Users migration created successfully.'); + $this->components->info("Migration [$file] created successfully."); $this->createGroupsTable(); $this->createRolesTable(); @@ -67,7 +67,7 @@ private function createGroupsTable() File::put($to, $contents); - $this->components->info('Groups migration created successfully.'); + $this->components->info("Migration [$file] created successfully."); } private function createRolesTable() @@ -86,6 +86,6 @@ private function createRolesTable() File::put($to, $contents); - $this->components->info('Roles migration created successfully.'); + $this->components->info("Migration [$file] created successfully."); } } From 9870008390db22eed77e81b0c855dec445e1f31c Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 18:06:16 +0000 Subject: [PATCH 22/39] Enhance `make:addon` --- src/Console/Commands/MakeAddon.php | 115 ++++++++++++++++------------- 1 file changed, 62 insertions(+), 53 deletions(-) diff --git a/src/Console/Commands/MakeAddon.php b/src/Console/Commands/MakeAddon.php index bada10e715..66b7737ca5 100644 --- a/src/Console/Commands/MakeAddon.php +++ b/src/Console/Commands/MakeAddon.php @@ -11,6 +11,8 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use function Laravel\Prompts\spin; + class MakeAddon extends GeneratorCommand { use EnhancesCommands, RunsInPlease, ValidatesInput; @@ -90,9 +92,15 @@ public function handle() $relativePath = $this->getRelativePath($this->addonPath()); - $this->output->newLine(); - $this->info("🎉 Your addon package is ready: {$relativePath}"); - $this->line('Learn how to build addons in our docs: https://statamic.dev/extending/addons'); + $this->components->info('Your addon is ready! 🎉'); + + $this->components->bulletList([ + "You find your addon in {$relativePath}", + 'Learn how to build addons in our docs: https://statamic.dev/extending/addons', + "When you're ready, setup as a seller to publish your addon on the Marketplace: https://statamic.com/sell", + ]); + + $this->newLine(); } /** @@ -132,30 +140,31 @@ protected function generateComposerJson() */ protected function generateAddonFiles() { - $this->line('Creating addon...'); - - $this->generateComposerJson(); - - $files = [ - 'addon/provider.php.stub' => 'src/ServiceProvider.php', - 'addon/TestCase.php.stub' => 'tests/TestCase.php', - 'addon/ExampleTest.php.stub' => 'tests/ExampleTest.php', - 'addon/.gitignore.stub' => '.gitignore', - 'addon/README.md.stub' => 'README.md', - 'addon/phpunit.xml.stub' => 'phpunit.xml', - ]; - - $data = [ - 'name' => $this->addonTitle(), - 'package' => $this->package, - 'namespace' => $this->addonNamespace(), - ]; - - foreach ($files as $stub => $file) { - $this->createFromStub($stub, $this->addonPath($file), $data); - } - - $this->checkInfo('Addon boilerplate created successfully.'); + spin( + function () { + $this->generateComposerJson(); + + $files = [ + 'addon/provider.php.stub' => 'src/ServiceProvider.php', + 'addon/TestCase.php.stub' => 'tests/TestCase.php', + 'addon/ExampleTest.php.stub' => 'tests/ExampleTest.php', + 'addon/.gitignore.stub' => '.gitignore', + 'addon/README.md.stub' => 'README.md', + 'addon/phpunit.xml.stub' => 'phpunit.xml', + ]; + + $data = [ + 'name' => $this->addonTitle(), + 'package' => $this->package, + 'namespace' => $this->addonNamespace(), + ]; + + foreach ($files as $stub => $file) { + $this->createFromStub($stub, $this->addonPath($file), $data); + } + }, + 'Creating addon...' + ); return $this; } @@ -195,19 +204,18 @@ protected function generateOptional() */ protected function installComposerDependencies() { - $this->output->newLine(); - - $this->line("Installing your addon's Composer dependencies. This may take a moment..."); - - try { - Composer::withoutQueue()->throwOnFailure()->install($this->addonPath()); - } catch (ProcessException $exception) { - $this->line($exception->getMessage()); - $this->output->newLine(); - throw new \Exception("An error was encountered while installing your addon's Composer dependencies!"); - } - - $this->checkInfo('Composer dependencies installed successfully.'); + spin( + function () { + try { + Composer::withoutQueue()->throwOnFailure()->install($this->addonPath()); + } catch (ProcessException $exception) { + $this->components->error("An error was encountered while installing your addon's Composer dependencies."); + $this->line($exception->getMessage()); + exit(1); + } + }, + "Installing your addon's Composer dependencies..." + ); return $this; } @@ -242,19 +250,20 @@ protected function addRepositoryPath() */ protected function installAddon() { - $this->output->newLine(); - $this->line('Installing your addon with Composer. This may take a moment...'); - $this->addRepositoryPath(); - - try { - Composer::withoutQueue()->throwOnFailure()->require($this->package); - } catch (ProcessException $exception) { - $this->line($exception->getMessage()); - $this->output->newLine(); - throw new \Exception('An error was encountered while installing your addon!'); - } - - $this->checkInfo('Addon installed successfully.'); + spin( + function () { + $this->addRepositoryPath(); + + try { + Composer::withoutQueue()->throwOnFailure()->require($this->package); + } catch (ProcessException $exception) { + $this->components->error('An error was encountered while installing your addon.'); + $this->line($exception->getMessage()); + exit(1); + } + }, + 'Installing your addon with Composer...' + ); return $this; } From 82e73de39f3f71b6d361dbe074944fd65ade5ea9 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 18:07:09 +0000 Subject: [PATCH 23/39] Remove duplicate info Laravel *also* seems to display info after a "thing" has been generated. --- src/Console/Commands/GeneratorCommand.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Console/Commands/GeneratorCommand.php b/src/Console/Commands/GeneratorCommand.php index 9de87901c9..c497d6ed8f 100644 --- a/src/Console/Commands/GeneratorCommand.php +++ b/src/Console/Commands/GeneratorCommand.php @@ -28,15 +28,7 @@ public function handle() : $addon; } - if (parent::handle() === false) { - return false; - } - - $relativePath = $this->getRelativePath($this->getPath($this->qualifyClass($this->getNameInput()))); - - if (! $addon) { - $this->line("Your {$this->typeLower} class awaits: {$relativePath}"); - } + return parent::handle(); } /** From 511b093b1f11fb0f760f3439227a2eaee42226bd Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 18:10:34 +0000 Subject: [PATCH 24/39] Console validation errors should display nicer --- src/Console/ValidatesInput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/ValidatesInput.php b/src/Console/ValidatesInput.php index f219643f4a..92b250f285 100644 --- a/src/Console/ValidatesInput.php +++ b/src/Console/ValidatesInput.php @@ -21,7 +21,7 @@ private function validationFails($input, $rules) return false; } - $this->error($validator->errors()->first()); + $this->components->error($validator->errors()->first()); return true; } From 979a97633bea7e778888db0995d8bfe711084f4b Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 18:40:16 +0000 Subject: [PATCH 25/39] wip --- src/Console/Commands/MakeFieldtype.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/MakeFieldtype.php b/src/Console/Commands/MakeFieldtype.php index 64dd08c02e..c3af3944cc 100644 --- a/src/Console/Commands/MakeFieldtype.php +++ b/src/Console/Commands/MakeFieldtype.php @@ -75,8 +75,14 @@ protected function generateVueComponent() if ($addon = $this->argument('addon')) { $this->wireUpAddonJs($addon); } else { - $this->line("Your {$this->typeLower} Vue component awaits: {$relativePath}"); - $this->comment("Don't forget to import and register your Fieldtype component in resources/js/addon.js"); + $this->components->info("Fieldtype Vue component [{$relativePath}] created successfully."); + + $this->components->bulletList([ + "Don't forget to import and register your fieldtype's Vue component in resources/js/addon.js", + 'For more information, see the documentation: https://statamic.dev/fieldtypes#vue-components', + ]); + + $this->newLine(); } } From 7d631f87de5a1b3cf9749e53aac55fdcbdd03884 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 19:21:44 +0000 Subject: [PATCH 26/39] Enhance some more things --- src/Console/Commands/StacheClear.php | 2 +- src/Console/Commands/StacheRefresh.php | 12 +++++------- src/Console/Commands/StacheWarm.php | 11 ++++------- src/Console/Commands/StarterKitExport.php | 12 +++++++----- .../Commands/StarterKitRunPostInstall.php | 6 +++--- src/Console/Commands/StaticClear.php | 6 ++++-- src/Console/Commands/StaticWarm.php | 16 ++++++++-------- src/Console/Commands/SupportZipBlueprint.php | 7 +++---- src/Console/Commands/UpdatesRun.php | 4 ++-- src/Stache/Stache.php | 5 ----- 10 files changed, 37 insertions(+), 44 deletions(-) diff --git a/src/Console/Commands/StacheClear.php b/src/Console/Commands/StacheClear.php index 25e7d4505e..038ba23bee 100644 --- a/src/Console/Commands/StacheClear.php +++ b/src/Console/Commands/StacheClear.php @@ -33,6 +33,6 @@ public function handle() { Stache::clear(); - $this->info('You have trimmed the Stache. It looks dashing.'); + $this->components->info('You have trimmed the Stache. It looks dashing.'); } } diff --git a/src/Console/Commands/StacheRefresh.php b/src/Console/Commands/StacheRefresh.php index e103b8c2e8..aaa98bebd7 100644 --- a/src/Console/Commands/StacheRefresh.php +++ b/src/Console/Commands/StacheRefresh.php @@ -5,7 +5,8 @@ use Illuminate\Console\Command; use Statamic\Console\RunsInPlease; use Statamic\Facades\Stache; -use Wilderborn\Partyline\Facade as Partyline; + +use function Laravel\Prompts\spin; class StacheRefresh extends Command { @@ -16,12 +17,9 @@ class StacheRefresh extends Command public function handle() { - Partyline::bind($this); - - $this->line('Please wait. This may take a while if you have a lot of content.'); - - Stache::refresh(); + spin(callback: fn () => Stache::clear(), message: 'Clearing the Stache...'); + spin(callback: fn () => Stache::warm(), message: 'Warming the Stache...'); - $this->info('You have trimmed and polished the Stache. It is handsome, warm, and ready.'); + $this->components->info('You have trimmed and polished the Stache. It is handsome, warm, and ready.'); } } diff --git a/src/Console/Commands/StacheWarm.php b/src/Console/Commands/StacheWarm.php index 7df4777b2d..0a6965c744 100644 --- a/src/Console/Commands/StacheWarm.php +++ b/src/Console/Commands/StacheWarm.php @@ -5,7 +5,8 @@ use Illuminate\Console\Command; use Statamic\Console\RunsInPlease; use Statamic\Facades\Stache; -use Wilderborn\Partyline\Facade as Partyline; + +use function Laravel\Prompts\spin; class StacheWarm extends Command { @@ -16,12 +17,8 @@ class StacheWarm extends Command public function handle() { - Partyline::bind($this); - - $this->line('Please wait. This may take a while if you have a lot of content.'); - - Stache::warm(); + spin(callback: fn () => Stache::warm(), message: 'Warming the Stache...'); - $this->info('You have poured oil over the Stache and polished it until it shines. It is warm and ready'); + $this->components->info('You have poured oil over the Stache and polished it until it shines. It is warm and ready'); } } diff --git a/src/Console/Commands/StarterKitExport.php b/src/Console/Commands/StarterKitExport.php index a31321f93e..3760878701 100644 --- a/src/Console/Commands/StarterKitExport.php +++ b/src/Console/Commands/StarterKitExport.php @@ -9,6 +9,8 @@ use Statamic\Facades\Path; use Statamic\StarterKits\Exceptions\StarterKitException; +use function Laravel\Prompts\confirm; + class StarterKitExport extends Command { use RunsInPlease; @@ -43,12 +45,12 @@ public function handle() try { StarterKitExporter::export($path); } catch (StarterKitException $exception) { - $this->error($exception->getMessage()); + $this->components->error($exception->getMessage()); return 1; } - $this->info("Starter kit was successfully exported to [$path]."); + $this->components->info("Starter kit was successfully exported to [$path]."); } /** @@ -60,7 +62,7 @@ protected function askToStubStarterKitConfig() $newPath = base_path($config = 'starter-kit.yaml'); if ($this->input->isInteractive()) { - if (! $this->confirm("Config [{$config}] does not exist. Would you like to create it now?", true)) { + if (! confirm("Config [{$config}] does not exist. Would you like to create it now?", true)) { return; } } @@ -93,13 +95,13 @@ protected function getAbsolutePath() protected function askToCreateExportPath($path) { if ($this->input->isInteractive()) { - if (! $this->confirm("Path [{$path}] does not exist. Would you like to create it now?", true)) { + if (! confirm("Path [{$path}] does not exist. Would you like to create it now?", true)) { return; } } File::makeDirectory($path, 0755, true); - $this->comment("A new directory has been created at [{$path}]."); + $this->components->info("A new directory has been created at [{$path}]."); } } diff --git a/src/Console/Commands/StarterKitRunPostInstall.php b/src/Console/Commands/StarterKitRunPostInstall.php index 3eee3dea8d..0db823cb58 100644 --- a/src/Console/Commands/StarterKitRunPostInstall.php +++ b/src/Console/Commands/StarterKitRunPostInstall.php @@ -37,7 +37,7 @@ public function handle() } if (! app('files')->exists(base_path("vendor/{$package}"))) { - $this->error("Cannot find starter kit [{$package}] in vendor."); + $this->components->error("Cannot find starter kit [{$package}] in vendor."); return 1; } @@ -47,11 +47,11 @@ public function handle() try { $installer->runPostInstallHook(true)->removeStarterKit(); } catch (StarterKitException $exception) { - $this->error($exception->getMessage()); + $this->components->error($exception->getMessage()); return 1; } - $this->info("Starter kit [$package] was successfully installed."); + $this->components->info("Starter kit [$package] was successfully installed."); } } diff --git a/src/Console/Commands/StaticClear.php b/src/Console/Commands/StaticClear.php index a6bc6bf7fb..98732f7812 100644 --- a/src/Console/Commands/StaticClear.php +++ b/src/Console/Commands/StaticClear.php @@ -6,6 +6,8 @@ use Statamic\Console\RunsInPlease; use Statamic\Facades\StaticCache; +use function Laravel\Prompts\spin; + class StaticClear extends Command { use RunsInPlease; @@ -31,8 +33,8 @@ class StaticClear extends Command */ public function handle() { - StaticCache::flush(); + spin(callback: fn () => StaticCache::flush(), message: 'Clearing the static page cache...'); - $this->info('Your static page cache is now so very, very empty.'); + $this->components->info('Your static page cache is now so very, very empty.'); } } diff --git a/src/Console/Commands/StaticWarm.php b/src/Console/Commands/StaticWarm.php index ad9a8b1975..44aae3e699 100644 --- a/src/Console/Commands/StaticWarm.php +++ b/src/Console/Commands/StaticWarm.php @@ -44,7 +44,7 @@ class StaticWarm extends Command public function handle() { if (! config('statamic.static_caching.strategy')) { - $this->error('Static caching is not enabled.'); + $this->components->error('Static caching is not enabled.'); return 1; } @@ -52,7 +52,7 @@ public function handle() $this->shouldQueue = $this->option('queue'); if ($this->shouldQueue && config('queue.default') === 'sync') { - $this->error('The queue connection is set to "sync". Queueing will be disabled.'); + $this->components->error('The queue connection is set to "sync". Queueing will be disabled.'); $this->shouldQueue = false; } @@ -60,10 +60,10 @@ public function handle() $this->warm(); - $this->output->newLine(); - $this->info($this->shouldQueue - ? 'All requests to warm the static cache have been added to the queue.' - : 'The static cache has been warmed.' + $this->components->info( + $this->shouldQueue + ? 'All requests to warm the static cache have been added to the queue.' + : 'The static cache has been warmed.' ); return 0; @@ -116,7 +116,7 @@ private function concurrency(): int public function outputSuccessLine(Response $response, $index): void { - $this->checkLine($this->getRelativeUri($index)); + $this->components->twoColumnDetail($this->getRelativeUri($index), "✓ Cached"); } public function outputFailureLine($exception, $index): void @@ -135,7 +135,7 @@ public function outputFailureLine($exception, $index): void $message = $exception->getMessage(); } - $this->crossLine("$uri → $message"); + $this->components->twoColumnDetail($uri, "$message"); } private function getRelativeUri(int $index): string diff --git a/src/Console/Commands/SupportZipBlueprint.php b/src/Console/Commands/SupportZipBlueprint.php index bf402ae381..9d0608a74c 100644 --- a/src/Console/Commands/SupportZipBlueprint.php +++ b/src/Console/Commands/SupportZipBlueprint.php @@ -26,8 +26,7 @@ public function handle() return 1; } - $this->info('Zip created successfully.'); - $this->comment("Your zip file awaits: {$filename}"); + $this->components->info("Zip [{$filename}] created successfully."); } protected function createZip($blueprint) @@ -37,7 +36,7 @@ protected function createZip($blueprint) $zip = new ZipArchive(); if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) { - $this->error("Unable to create zip file \"$filename\""); + $this->components->error("Unable to create zip file: [$filename]"); return false; } @@ -58,7 +57,7 @@ protected function getBlueprint() $handle = $this->argument('blueprint'); if (! $blueprint = Blueprint::find($handle)) { - $this->error("Blueprint \"$handle\" not found"); + $this->components->error("Blueprint [$handle] not found."); return null; } diff --git a/src/Console/Commands/UpdatesRun.php b/src/Console/Commands/UpdatesRun.php index ba29f611ea..20d39742f5 100644 --- a/src/Console/Commands/UpdatesRun.php +++ b/src/Console/Commands/UpdatesRun.php @@ -39,7 +39,7 @@ public function handle() $success = UpdateScriptManager::runUpdatesForSpecificPackageVersion($package, $this->argument('version'), $this); $success - ? $this->info('Update scripts were run successfully!') - : $this->comment('There were no update scripts for this version.'); + ? $this->components->info('Update scripts were run successfully!') + : $this->components->warn('There were no update scripts for this version.'); } } diff --git a/src/Stache/Stache.php b/src/Stache/Stache.php index 1bfab301e9..29e164c817 100644 --- a/src/Stache/Stache.php +++ b/src/Stache/Stache.php @@ -10,7 +10,6 @@ use Statamic\Support\Str; use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\LockInterface; -use Wilderborn\Partyline\Facade as Partyline; class Stache { @@ -82,8 +81,6 @@ public function generateId() public function clear() { - Partyline::comment('Clearing Stache...'); - $this->stores()->reverse()->each->clear(); $this->duplicates()->clear(); @@ -100,8 +97,6 @@ public function refresh() public function warm() { - Partyline::comment('Warming Stache...'); - $lock = tap($this->lock('stache-warming'))->acquire(true); $this->startTimer(); From b25a2b8fc125570fd93befeedf71932f43d85c6a Mon Sep 17 00:00:00 2001 From: duncanmcclean Date: Thu, 14 Mar 2024 19:23:18 +0000 Subject: [PATCH 27/39] Fix styling --- src/Console/Commands/StaticWarm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Commands/StaticWarm.php b/src/Console/Commands/StaticWarm.php index 44aae3e699..c1010af209 100644 --- a/src/Console/Commands/StaticWarm.php +++ b/src/Console/Commands/StaticWarm.php @@ -116,7 +116,7 @@ private function concurrency(): int public function outputSuccessLine(Response $response, $index): void { - $this->components->twoColumnDetail($this->getRelativeUri($index), "✓ Cached"); + $this->components->twoColumnDetail($this->getRelativeUri($index), '✓ Cached'); } public function outputFailureLine($exception, $index): void From e8b6d1dfb7e9f974c88dc3f0dbfc0a8ec16b8fcc Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 20:36:04 +0000 Subject: [PATCH 28/39] wip --- src/Console/Commands/Multisite.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/Multisite.php b/src/Console/Commands/Multisite.php index 4fb494145f..06f4c11190 100644 --- a/src/Console/Commands/Multisite.php +++ b/src/Console/Commands/Multisite.php @@ -19,6 +19,7 @@ use function Laravel\Prompts\confirm; use function Laravel\Prompts\info; +use function Laravel\Prompts\spin; use function Laravel\Prompts\text; class Multisite extends Command @@ -46,7 +47,7 @@ public function handle() $confirmed = confirm("The current site handle is [{$this->siteOne()}], content will be moved into folders with this name. Is this okay?"); if (! $confirmed) { - $this->crossLine('Change the site handle in config/statamic/sites.php then try this command again.'); + $this->components->error('Change the site handle in config/statamic/sites.php then try this command again.'); return; } @@ -60,7 +61,7 @@ public function handle() } while ($site !== ''); if ($this->sites->count() < 2) { - return $this->crossLine('Multisite has not been enabled.'); + return $this->components->error('Multisite has not been enabled.'); } $this->clearStache(); From d09bf9766a314082aa5606354daeaca7e4f0bb9a Mon Sep 17 00:00:00 2001 From: duncanmcclean Date: Thu, 14 Mar 2024 20:40:02 +0000 Subject: [PATCH 29/39] Fix styling --- src/Console/Commands/Multisite.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Console/Commands/Multisite.php b/src/Console/Commands/Multisite.php index 06f4c11190..a54e351bec 100644 --- a/src/Console/Commands/Multisite.php +++ b/src/Console/Commands/Multisite.php @@ -19,7 +19,6 @@ use function Laravel\Prompts\confirm; use function Laravel\Prompts\info; -use function Laravel\Prompts\spin; use function Laravel\Prompts\text; class Multisite extends Command From 254117052bf1b23feede46e22a7c4ba53e62de0a Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 20:42:24 +0000 Subject: [PATCH 30/39] skip make:addon tests for now --- tests/Console/Commands/MakeAddonTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Console/Commands/MakeAddonTest.php b/tests/Console/Commands/MakeAddonTest.php index 6b02194c9f..8a5321818f 100644 --- a/tests/Console/Commands/MakeAddonTest.php +++ b/tests/Console/Commands/MakeAddonTest.php @@ -16,6 +16,7 @@ public function setUp(): void { parent::setUp(); + $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); $this->markTestSkippedInWindows(); $this->files = app(Filesystem::class); From 9d354a70f28c87dc03ed7a13f5e876d5eb6de07d Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 20:46:42 +0000 Subject: [PATCH 31/39] does this fix the tests? (wish they were broken locally too) one can only dream --- src/Console/Commands/MakeAddon.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/MakeAddon.php b/src/Console/Commands/MakeAddon.php index 66b7737ca5..a835b8b1f5 100644 --- a/src/Console/Commands/MakeAddon.php +++ b/src/Console/Commands/MakeAddon.php @@ -211,7 +211,7 @@ function () { } catch (ProcessException $exception) { $this->components->error("An error was encountered while installing your addon's Composer dependencies."); $this->line($exception->getMessage()); - exit(1); + // exit(1); } }, "Installing your addon's Composer dependencies..." @@ -259,7 +259,7 @@ function () { } catch (ProcessException $exception) { $this->components->error('An error was encountered while installing your addon.'); $this->line($exception->getMessage()); - exit(1); + // exit(1); } }, 'Installing your addon with Composer...' From 74151b00fb8913a49a08bf84499bb6966bda497e Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 20:55:54 +0000 Subject: [PATCH 32/39] don't skip these tests --- tests/Console/Commands/AssetsMetaTest.php | 4 ---- tests/Console/Commands/MakeAddonTest.php | 1 - tests/Console/Commands/MakeUserTest.php | 4 ---- 3 files changed, 9 deletions(-) diff --git a/tests/Console/Commands/AssetsMetaTest.php b/tests/Console/Commands/AssetsMetaTest.php index 5329ef74e0..da5b693000 100644 --- a/tests/Console/Commands/AssetsMetaTest.php +++ b/tests/Console/Commands/AssetsMetaTest.php @@ -60,8 +60,6 @@ private function containerWithDisk() /** @test */ public function it_generates_one_asset_meta_file_for_asset_with_no_meta_file() { - $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); - $this->containerWithDisk(); Storage::disk('test')->assertMissing('foo/bar.txt'); @@ -83,8 +81,6 @@ public function it_generates_one_asset_meta_file_for_asset_with_no_meta_file() /** @test */ public function it_preserves_data_property_in_meta_data_file() { - $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); - $this->containerWithDisk(); Storage::disk('test')->put('foo/bar.txt', 'foobar'); diff --git a/tests/Console/Commands/MakeAddonTest.php b/tests/Console/Commands/MakeAddonTest.php index 8a5321818f..6b02194c9f 100644 --- a/tests/Console/Commands/MakeAddonTest.php +++ b/tests/Console/Commands/MakeAddonTest.php @@ -16,7 +16,6 @@ public function setUp(): void { parent::setUp(); - $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); $this->markTestSkippedInWindows(); $this->files = app(Filesystem::class); diff --git a/tests/Console/Commands/MakeUserTest.php b/tests/Console/Commands/MakeUserTest.php index 695b8be81f..29c1c59303 100644 --- a/tests/Console/Commands/MakeUserTest.php +++ b/tests/Console/Commands/MakeUserTest.php @@ -39,8 +39,6 @@ public function it_can_make_a_user() /** @test */ public function it_can_make_a_super_user_interactively() { - $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); - $this->assertEmpty(User::all()); $this->artisan('statamic:make:user') @@ -62,8 +60,6 @@ public function it_can_make_a_super_user_interactively() /** @test */ public function it_can_make_a_non_super_user_interactively() { - $this->markTestSkipped("The test doesn't work now we've switched to Laravel Prompts."); - $this->assertEmpty(User::all()); $this->artisan('statamic:make:user') From ed874803065e641b310f7c61bb655f6d6f493d89 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 21:28:23 +0000 Subject: [PATCH 33/39] turns out prompts works fine with tests, i just needed to tweak some assertions --- src/Console/Commands/AssetsMeta.php | 2 ++ tests/Console/Commands/AssetsMetaTest.php | 4 ++-- tests/Console/Commands/MakeAddonTest.php | 4 ++-- tests/Console/Commands/MakeUserTest.php | 15 ++++++++------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Console/Commands/AssetsMeta.php b/src/Console/Commands/AssetsMeta.php index b7e4fa1df6..88c81b3016 100644 --- a/src/Console/Commands/AssetsMeta.php +++ b/src/Console/Commands/AssetsMeta.php @@ -35,6 +35,8 @@ public function handle() }, hint: 'This may take a while if you have a lot of assets.' ); + + $this->components->info("Generated metadata for {$assets->count()} " . str_plural('asset', $assets->count()) . '.'); } /** diff --git a/tests/Console/Commands/AssetsMetaTest.php b/tests/Console/Commands/AssetsMetaTest.php index da5b693000..0e894104e1 100644 --- a/tests/Console/Commands/AssetsMetaTest.php +++ b/tests/Console/Commands/AssetsMetaTest.php @@ -72,7 +72,7 @@ public function it_generates_one_asset_meta_file_for_asset_with_no_meta_file() Storage::disk('test')->assertMissing('foo/.meta/bar.txt.yaml'); $this->artisan('statamic:assets:meta test_container') - ->expectsOutput('Asset metadata generated'); + ->expectsOutputToContain('Generated metadata for 1 asset.'); Storage::disk('test')->assertExists('foo/bar.txt'); Storage::disk('test')->assertExists('foo/.meta/bar.txt.yaml'); @@ -90,7 +90,7 @@ public function it_preserves_data_property_in_meta_data_file() ); $this->artisan('statamic:assets:meta test_container') - ->expectsOutput('Asset metadata generated'); + ->expectsOutputToContain('Generated metadata for 1 asset.'); $this->assertEquals( Arr::get(YAML::parse(Storage::disk('test')->get('foo/.meta/bar.txt.yaml')), 'data.foo'), diff --git a/tests/Console/Commands/MakeAddonTest.php b/tests/Console/Commands/MakeAddonTest.php index 6b02194c9f..0e89bfc64b 100644 --- a/tests/Console/Commands/MakeAddonTest.php +++ b/tests/Console/Commands/MakeAddonTest.php @@ -56,10 +56,10 @@ public function it_can_generate_an_addon() public function it_cannot_make_addon_with_invalid_composer_package_name() { $this->artisan('statamic:make:addon', ['addon' => 'deaths-tar-vulnerability']) - ->expectsOutput('Please enter a valid composer package name (eg. hasselhoff/kung-fury).'); + ->expectsOutputToContain('Please enter a valid composer package name (eg. hasselhoff/kung-fury).'); $this->artisan('statamic:make:addon', ['addon' => 'some/path/deaths-tar-vulnerability']) - ->expectsOutput('Please enter a valid composer package name (eg. hasselhoff/kung-fury).'); + ->expectsOutputToContain('Please enter a valid composer package name (eg. hasselhoff/kung-fury).'); $this->assertFileDoesNotExist(base_path('addons/erso/deaths-tar-vulnerability')); } diff --git a/tests/Console/Commands/MakeUserTest.php b/tests/Console/Commands/MakeUserTest.php index 29c1c59303..ad5742eacd 100644 --- a/tests/Console/Commands/MakeUserTest.php +++ b/tests/Console/Commands/MakeUserTest.php @@ -3,6 +3,7 @@ namespace Tests\Console\Commands; use Illuminate\Filesystem\Filesystem; +use Statamic\Console\Commands\MakeUser; use Statamic\Facades\User; use Tests\TestCase; @@ -44,8 +45,8 @@ public function it_can_make_a_super_user_interactively() $this->artisan('statamic:make:user') ->expectsQuestion('Email', 'jason@ifyoucantescapeit.org') ->expectsQuestion('Name', 'Jason') - ->expectsQuestion('Password (Your input will be hidden)', 'midnight') - ->expectsQuestion('Super user', true) + ->expectsQuestion('Password', 'midnight') + ->expectsQuestion('Super user?', true) ->assertExitCode(0); $user = User::all()->first(); @@ -65,8 +66,8 @@ public function it_can_make_a_non_super_user_interactively() $this->artisan('statamic:make:user') ->expectsQuestion('Email', 'jesses.girl@springfield.com') ->expectsQuestion('Name', 'Gertrude') - ->expectsQuestion('Password (Your input will be hidden)', 'iloverickie') - ->expectsQuestion('Super user', false) + ->expectsQuestion('Password', 'iloverickie') + ->expectsQuestion('Super user?', false) ->assertExitCode(0); $user = User::all()->first(); @@ -82,13 +83,13 @@ public function it_validates_email() $this->assertEmpty(User::all()); $this->artisan('statamic:make:user', ['email' => 'jason']) - ->expectsOutput(trans('validation.email', ['attribute' => 'input'])); + ->expectsOutputToContain(trans('validation.email', ['attribute' => 'input'])); $this->artisan('statamic:make:user', ['email' => 'jason@keeponrunnin.com']) - ->expectsOutput('User created successfully.'); + ->expectsOutputToContain('User created successfully.'); $this->artisan('statamic:make:user', ['email' => 'jason@keeponrunnin.com']) - ->expectsOutput('A user with this email already exists.'); + ->expectsOutputToContain('A user with this email already exists.'); } /** @test */ From c17481b8a8134990238278c42a2a17d5d83de710 Mon Sep 17 00:00:00 2001 From: duncanmcclean Date: Thu, 14 Mar 2024 21:30:09 +0000 Subject: [PATCH 34/39] Fix styling --- src/Console/Commands/AssetsMeta.php | 2 +- tests/Console/Commands/MakeUserTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Console/Commands/AssetsMeta.php b/src/Console/Commands/AssetsMeta.php index 88c81b3016..8e990ed5c6 100644 --- a/src/Console/Commands/AssetsMeta.php +++ b/src/Console/Commands/AssetsMeta.php @@ -36,7 +36,7 @@ public function handle() hint: 'This may take a while if you have a lot of assets.' ); - $this->components->info("Generated metadata for {$assets->count()} " . str_plural('asset', $assets->count()) . '.'); + $this->components->info("Generated metadata for {$assets->count()} ".str_plural('asset', $assets->count()).'.'); } /** diff --git a/tests/Console/Commands/MakeUserTest.php b/tests/Console/Commands/MakeUserTest.php index ad5742eacd..3c01dfa0dc 100644 --- a/tests/Console/Commands/MakeUserTest.php +++ b/tests/Console/Commands/MakeUserTest.php @@ -3,7 +3,6 @@ namespace Tests\Console\Commands; use Illuminate\Filesystem\Filesystem; -use Statamic\Console\Commands\MakeUser; use Statamic\Facades\User; use Tests\TestCase; From c367259dc7ffa7c721c218942d981c380b053471 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 21:37:04 +0000 Subject: [PATCH 35/39] fix more expectations --- tests/StarterKits/RunPostInstallTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/StarterKits/RunPostInstallTest.php b/tests/StarterKits/RunPostInstallTest.php index 3efcff0dae..83efc82b3b 100644 --- a/tests/StarterKits/RunPostInstallTest.php +++ b/tests/StarterKits/RunPostInstallTest.php @@ -79,7 +79,7 @@ public function it_errors_gracefully_if_post_install_hook_cannot_be_found() ->artisan('statamic:starter-kit:run-post-install', [ 'package' => 'statamic/cool-runnings', ]) - ->expectsOutput('Cannot find post-install hook for [statamic/cool-runnings].') + ->expectsOutputToContain('Cannot find post-install hook for [statamic/cool-runnings].') ->assertExitCode(1); $this->assertFalse(Blink::has('post-install-hook-run')); @@ -97,7 +97,7 @@ public function it_errors_gracefully_if_starter_kit_package_doesnt_exist_in_vend ->artisan('statamic:starter-kit:run-post-install', [ 'package' => 'statamic/non-existent', ]) - ->expectsOutput('Cannot find starter kit [statamic/non-existent] in vendor.') + ->expectsOutputToContain('Cannot find starter kit [statamic/non-existent] in vendor.') ->assertExitCode(1); $this->assertFalse(Blink::has('post-install-hook-run')); From 3216fd8c2f1d5a88ba55e32c0820fc19549f1d9f Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 14 Mar 2024 21:43:23 +0000 Subject: [PATCH 36/39] these shouldn't be commented out --- src/Console/Commands/MakeAddon.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/MakeAddon.php b/src/Console/Commands/MakeAddon.php index a835b8b1f5..66b7737ca5 100644 --- a/src/Console/Commands/MakeAddon.php +++ b/src/Console/Commands/MakeAddon.php @@ -211,7 +211,7 @@ function () { } catch (ProcessException $exception) { $this->components->error("An error was encountered while installing your addon's Composer dependencies."); $this->line($exception->getMessage()); - // exit(1); + exit(1); } }, "Installing your addon's Composer dependencies..." @@ -259,7 +259,7 @@ function () { } catch (ProcessException $exception) { $this->components->error('An error was encountered while installing your addon.'); $this->line($exception->getMessage()); - // exit(1); + exit(1); } }, 'Installing your addon with Composer...' From f16211fe7be43e2910a835dbef6252eff54b3d4c Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 15 Mar 2024 15:24:17 +0000 Subject: [PATCH 37/39] Refactor error handling in make:addon command When we were doing `exit(1)`, it was causing the test suite to not complete running. --- src/Console/Commands/MakeAddon.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Console/Commands/MakeAddon.php b/src/Console/Commands/MakeAddon.php index 66b7737ca5..e4432aa9ff 100644 --- a/src/Console/Commands/MakeAddon.php +++ b/src/Console/Commands/MakeAddon.php @@ -3,6 +3,7 @@ namespace Statamic\Console\Commands; use Facades\Statamic\Console\Processes\Composer; +use function Laravel\Prompts\spin; use Statamic\Console\EnhancesCommands; use Statamic\Console\Processes\Exceptions\ProcessException; use Statamic\Console\RunsInPlease; @@ -11,8 +12,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; -use function Laravel\Prompts\spin; - class MakeAddon extends GeneratorCommand { use EnhancesCommands, RunsInPlease, ValidatesInput; @@ -85,7 +84,7 @@ public function handle() ->generateOptional() ->installComposerDependencies(); } catch (\Exception $e) { - $this->error($e->getMessage()); + $this->components->error($e->getMessage()); return 1; } @@ -209,9 +208,8 @@ function () { try { Composer::withoutQueue()->throwOnFailure()->install($this->addonPath()); } catch (ProcessException $exception) { - $this->components->error("An error was encountered while installing your addon's Composer dependencies."); $this->line($exception->getMessage()); - exit(1); + throw new \Exception("An error was encountered while installing your addon's Composer dependencies."); } }, "Installing your addon's Composer dependencies..." @@ -257,9 +255,9 @@ function () { try { Composer::withoutQueue()->throwOnFailure()->require($this->package); } catch (ProcessException $exception) { - $this->components->error('An error was encountered while installing your addon.'); + $this->newLine(); $this->line($exception->getMessage()); - exit(1); + throw new \Exception('An error was encountered while installing your addon.'); } }, 'Installing your addon with Composer...' From 1fd4b00e795f61b6e806491fc6a6692343e00766 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 15 Mar 2024 15:51:41 +0000 Subject: [PATCH 38/39] Fix prompts interactivity in tests When running the test suite on Laravel 10.0.0, Prompts would show me the interactive prompt, meaning the assertions wouldn't take place. Related: https://github.com/laravel/framework/pull/48468 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 589d2a93e2..90bd8b07f4 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "facade/ignition-contracts": "^1.0", "guzzlehttp/guzzle": "^6.3 || ^7.0", "james-heinrich/getid3": "^1.9.21", - "laravel/framework": "^10.0 || ^11.0", + "laravel/framework": "^10.25.0 || ^11.0", "laravel/helpers": "^1.1", "laravel/prompts": "^0.1.16", "league/commonmark": "^2.2", From 5342049baeadac643ce6aa39462282f348faeef1 Mon Sep 17 00:00:00 2001 From: duncanmcclean Date: Fri, 15 Mar 2024 15:53:16 +0000 Subject: [PATCH 39/39] Fix styling --- src/Console/Commands/MakeAddon.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Console/Commands/MakeAddon.php b/src/Console/Commands/MakeAddon.php index e4432aa9ff..71ca01628a 100644 --- a/src/Console/Commands/MakeAddon.php +++ b/src/Console/Commands/MakeAddon.php @@ -3,7 +3,6 @@ namespace Statamic\Console\Commands; use Facades\Statamic\Console\Processes\Composer; -use function Laravel\Prompts\spin; use Statamic\Console\EnhancesCommands; use Statamic\Console\Processes\Exceptions\ProcessException; use Statamic\Console\RunsInPlease; @@ -12,6 +11,8 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; +use function Laravel\Prompts\spin; + class MakeAddon extends GeneratorCommand { use EnhancesCommands, RunsInPlease, ValidatesInput;