Skip to content

Commit

Permalink
Fix command availability
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Jan 21, 2024
1 parent 83dfb3e commit 6ab1bfc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use function count;

#[AsCommand(name: 'pwa:create:icons', description: 'Generate icons for your PWA')]
final class GenerateIconsCommand extends Command
final class CreateIconsCommand extends Command
{
public function __construct(
private readonly Filesystem $filesystem,
Expand All @@ -26,11 +26,6 @@ public function __construct(
parent::__construct();
}

public function isEnabled(): bool
{
return class_exists(MimeTypes::class);
}

protected function configure(): void
{
$this->addArgument('source', InputArgument::REQUIRED, 'The source image');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
name: 'pwa:create:screenshot',
description: 'Take a screenshot of the application store it in your asset folder'
)]
final class TakeScreenshotCommand extends Command
final class CreateScreenshotCommand extends Command
{
private readonly Client $webClient;

Expand All @@ -38,11 +38,6 @@ public function __construct(
$this->webClient = $webClient;
}

public function isEnabled(): bool
{
return class_exists(Client::class) && class_exists(WebDriverDimension::class) && class_exists(MimeTypes::class);
}

protected function configure(): void
{
$this->addArgument('url', InputArgument::REQUIRED, 'The URL to take a screenshot from');
Expand All @@ -60,6 +55,9 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
if (! $this->isEnabled()) {
return self::FAILURE;
}
$io = new SymfonyStyle($input, $output);
$io->title('PWA - Take a screenshot');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use function count;

#[AsCommand(name: 'pwa:create:sw', description: 'Generate a basic Service Worker')]
final class GenerateServiceWorkerCommand extends Command
final class CreateServiceWorkerCommand extends Command
{
public function __construct(
private readonly Filesystem $filesystem,
Expand Down
14 changes: 13 additions & 1 deletion src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

declare(strict_types=1);

use Facebook\WebDriver\WebDriverDimension;
use SpomkyLabs\PwaBundle\Command\CreateIconsCommand;
use SpomkyLabs\PwaBundle\Command\CreateScreenshotCommand;
use SpomkyLabs\PwaBundle\Command\CreateServiceWorkerCommand;
use SpomkyLabs\PwaBundle\Dto\Manifest;
use SpomkyLabs\PwaBundle\ImageProcessor\GDImageProcessor;
use SpomkyLabs\PwaBundle\ImageProcessor\ImagickImageProcessor;
Expand All @@ -13,6 +17,8 @@
use SpomkyLabs\PwaBundle\Twig\PwaExtension;
use SpomkyLabs\PwaBundle\Twig\PwaRuntime;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Mime\MimeTypes;
use Symfony\Component\Panther\Client;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $container): void {
Expand All @@ -32,7 +38,13 @@
->factory([service(ManifestBuilder::class), 'createManifest'])
;

$container->load('SpomkyLabs\\PwaBundle\\Command\\', '../../Command/*');
$container->set(CreateServiceWorkerCommand::class);
if (class_exists(Client::class) && class_exists(WebDriverDimension::class) && class_exists(MimeTypes::class)) {
$container->set(CreateScreenshotCommand::class);
}
if (class_exists(MimeTypes::class)) {
$container->set(CreateIconsCommand::class);
}

$container->load('SpomkyLabs\\PwaBundle\\Normalizer\\', '../../Normalizer/*')
->tag('serializer.normalizer', [
Expand Down

0 comments on commit 6ab1bfc

Please sign in to comment.