From 1a11931fa842a2f5d9391125a179e8fae1df8dab Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 18 Mar 2024 15:32:25 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Add=20`Mani?= =?UTF-8?q?fest`=20and=20`SkipProvider`=20solutions=20to=20Ignition=20(Fix?= =?UTF-8?q?es=20#204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/DefaultProviders.php | 1 + .../Exceptions/ExceptionServiceProvider.php | 41 +++++++++++ .../Solutions/ManifestSolutionProvider.php | 71 +++++++++++++++++++ .../SkipProviderSolutionProvider.php | 30 ++++++++ 4 files changed, 143 insertions(+) create mode 100644 src/Roots/Acorn/Exceptions/ExceptionServiceProvider.php create mode 100644 src/Roots/Acorn/Exceptions/Solutions/ManifestSolutionProvider.php create mode 100644 src/Roots/Acorn/Exceptions/Solutions/SkipProviderSolutionProvider.php diff --git a/src/Roots/Acorn/DefaultProviders.php b/src/Roots/Acorn/DefaultProviders.php index a677608e..651dc539 100644 --- a/src/Roots/Acorn/DefaultProviders.php +++ b/src/Roots/Acorn/DefaultProviders.php @@ -13,6 +13,7 @@ class DefaultProviders extends DefaultProvidersBase * @var array */ protected $acornProviders = [ + \Roots\Acorn\Exceptions\ExceptionServiceProvider::class, \Roots\Acorn\Assets\AssetsServiceProvider::class, \Roots\Acorn\Filesystem\FilesystemServiceProvider::class, \Roots\Acorn\Providers\AcornServiceProvider::class, diff --git a/src/Roots/Acorn/Exceptions/ExceptionServiceProvider.php b/src/Roots/Acorn/Exceptions/ExceptionServiceProvider.php new file mode 100644 index 00000000..ff2eaa82 --- /dev/null +++ b/src/Roots/Acorn/Exceptions/ExceptionServiceProvider.php @@ -0,0 +1,41 @@ +registerSolutions(); + } + + /** + * Register the exception solutions. + */ + protected function registerSolutions() + { + $this->app->make(SolutionProviderRepository::class)->registerSolutionProviders($this->solutions); + } +} diff --git a/src/Roots/Acorn/Exceptions/Solutions/ManifestSolutionProvider.php b/src/Roots/Acorn/Exceptions/Solutions/ManifestSolutionProvider.php new file mode 100644 index 00000000..51f99d30 --- /dev/null +++ b/src/Roots/Acorn/Exceptions/Solutions/ManifestSolutionProvider.php @@ -0,0 +1,71 @@ + 'https://roots.io/sage/docs/installation/', + 'Bud Documentation' => 'https://bud.js.org/learn/getting-started', + ]; + + /** + * Determine if the provider can solve the given throwable. + */ + public function canSolve(Throwable $throwable): bool + { + return Str::startsWith($throwable->getMessage(), 'The asset manifest'); + } + + /** + * Get the solutions for the given throwable. + */ + public function getSolutions(Throwable $throwable): array + { + return [$this->getSolution()]; + } + + /** + * Get the solutions for the given throwable. + */ + public function getSolution(): Solution + { + $baseCommand = collect([ + 'pnpm-lock.yaml' => 'pnpm', + 'yarn.lock' => 'yarn', + ])->first(fn ($_, $lockfile) => file_exists(base_path($lockfile)), 'npm run'); + + return app()->environment('development', 'testing', 'local') + ? $this->getLocalSolution($baseCommand) + : $this->getProductionSolution($baseCommand); + } + + /** + * Get the local solution. + */ + protected function getLocalSolution(string $baseCommand): Solution + { + return BaseSolution::create('Start the development server') + ->setSolutionDescription("Run `{$baseCommand} dev` in your terminal and refresh the page.") + ->setDocumentationLinks($this->links); + } + + /** + * Get the production solution. + */ + protected function getProductionSolution(string $baseCommand): Solution + { + return BaseSolution::create('Build the production assets') + ->setSolutionDescription("Run `{$baseCommand} build` in your deployment script.") + ->setDocumentationLinks($this->links); + } +} diff --git a/src/Roots/Acorn/Exceptions/Solutions/SkipProviderSolutionProvider.php b/src/Roots/Acorn/Exceptions/Solutions/SkipProviderSolutionProvider.php new file mode 100644 index 00000000..42882f17 --- /dev/null +++ b/src/Roots/Acorn/Exceptions/Solutions/SkipProviderSolutionProvider.php @@ -0,0 +1,30 @@ +setSolutionDescription('Run `wp acorn optimize:clear` in your terminal and refresh the page.'), + ]; + } +}