diff --git a/src/Command/GenerateIconsCommand.php b/src/Command/CreateIconsCommand.php similarity index 95% rename from src/Command/GenerateIconsCommand.php rename to src/Command/CreateIconsCommand.php index b5ad9a4..5cdc6ff 100644 --- a/src/Command/GenerateIconsCommand.php +++ b/src/Command/CreateIconsCommand.php @@ -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, @@ -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'); diff --git a/src/Command/TakeScreenshotCommand.php b/src/Command/CreateScreenshotCommand.php similarity index 94% rename from src/Command/TakeScreenshotCommand.php rename to src/Command/CreateScreenshotCommand.php index 19064c3..e96f347 100644 --- a/src/Command/TakeScreenshotCommand.php +++ b/src/Command/CreateScreenshotCommand.php @@ -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; @@ -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'); @@ -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'); diff --git a/src/Command/GenerateServiceWorkerCommand.php b/src/Command/CreateServiceWorkerCommand.php similarity index 97% rename from src/Command/GenerateServiceWorkerCommand.php rename to src/Command/CreateServiceWorkerCommand.php index 09d9d76..64c49ab 100644 --- a/src/Command/GenerateServiceWorkerCommand.php +++ b/src/Command/CreateServiceWorkerCommand.php @@ -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, diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index b927072..59de6ee 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -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; @@ -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 { @@ -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', [