Skip to content

Commit

Permalink
Command renamed and Minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Jan 20, 2024
1 parent fb542c6 commit 3f1a2be
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Command/GenerateIconsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\Mime\MimeTypes;
use function count;

#[AsCommand(name: 'pwa:generate-icons', description: 'Generate icons for your PWA')]
#[AsCommand(name: 'pwa:create:icons', description: 'Generate icons for your PWA')]
final class GenerateIconsCommand extends Command
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GenerateServiceWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\HttpKernel\Config\FileLocator;
use function count;

#[AsCommand(name: 'pwa:sw', description: 'Generate a basic Service Worker')]
#[AsCommand(name: 'pwa:create:sw', description: 'Generate a basic Service Worker')]
final class GenerateServiceWorkerCommand extends Command
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TakeScreenshotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use function count;

#[AsCommand(
name: 'pwa:take-screenshot',
name: 'pwa:create:screenshot',
description: 'Take a screenshot of the application store it in your asset folder'
)]
final class TakeScreenshotCommand extends Command
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SpomkyLabs\PwaBundle\Dto\Manifest;
use SpomkyLabs\PwaBundle\ImageProcessor\GDImageProcessor;
use SpomkyLabs\PwaBundle\ImageProcessor\ImagickImageProcessor;
use SpomkyLabs\PwaBundle\Service\Builder;
use SpomkyLabs\PwaBundle\Service\ManifestBuilder;
use SpomkyLabs\PwaBundle\Service\ServiceWorkerBuilder;
use SpomkyLabs\PwaBundle\Subscriber\AssetsCompileEventListener;
use SpomkyLabs\PwaBundle\Subscriber\PwaDevServerSubscriber;
Expand All @@ -23,13 +23,13 @@
->autowire()
;

$container->set(Builder::class)
$container->set(ManifestBuilder::class)
->args([
'$config' => '%spomky_labs_pwa.config%',
])
;
$container->set(Manifest::class)
->factory([service(Builder::class), 'createManifest'])
->factory([service(ManifestBuilder::class), 'createManifest'])
;

$container->load('SpomkyLabs\\PwaBundle\\Command\\', '../../Command/*');
Expand Down
13 changes: 4 additions & 9 deletions src/Resources/workbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ importScripts(
// *** Recipes ***
// You are free to change or remove any of these presets as you wish.
// See https://developer.chrome.com/docs/workbox/modules/workbox-recipes for more information.

const {
pageCache,
imageCache,
staticResourceCache,
googleFontsCache,
} = workbox.recipes;

// => Cache pages with a network-first strategy.
pageCache();
// => Cache CSS, JS, and Web Worker requests with a cache-first strategy.
staticResourceCache();
// => Cache images with a cache-first strategy.
imageCache();
// => Cache the underlying font files with a cache-first strategy.
googleFontsCache();
pageCache();// => Cache pages with a network-first strategy.
staticResourceCache();// => Cache CSS, JS, and Web Worker requests with a cache-first strategy.
imageCache();// => Cache images with a cache-first strategy.
googleFontsCache();// => Cache the underlying font files with a cache-first strategy.

// *** Bundle rules ***
//PRECACHING_PLACEHOLDER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use function assert;

final class Builder
final class ManifestBuilder
{
private null|Manifest $manifest = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
/**
* @internal
*/
final class ManifestFileDevServerTest extends WebTestCase
final class DevServerTest extends WebTestCase
{
#[Test]
public static function aScreenshotIsCorrectlyTake(): void
public static function theManifestIsServed(): void
{
// Given
$client = static::createClient();
Expand All @@ -24,6 +24,19 @@ public static function aScreenshotIsCorrectlyTake(): void
// Then
static::assertResponseIsSuccessful();
static::assertResponseHeaderSame('Content-Type', 'application/manifest+json');
dump($client->getResponse()->getContent());
}

#[Test]
public static function theServiceWorkerIsServed(): void
{
// Given
$client = static::createClient();

// When
$client->request('GET', '/sw.js');

// Then
static::assertResponseIsSuccessful();
static::assertResponseHeaderSame('Content-Type', 'application/javascript');
}
}
4 changes: 2 additions & 2 deletions tests/Functional/GenerateIconsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
final class GenerateIconsCommandTest extends AbstractPwaTestCase
{
#[Test]
public static function aScreenshotIsCorrectlyTake(): void
public static function iconsAreCorrectlyCreated(): void
{
// Given
$command = self::$application->find('pwa:generate-icons');
$command = self::$application->find('pwa:create:icons');
$commandTester = new CommandTester($command);
$output = sprintf('%s/samples/icons', self::$kernel->getCacheDir());

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/ServiceWorkerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ServiceWorkerCommandTest extends AbstractPwaTestCase
public static function theCommandCanGenerateTheServiceWorker(): void
{
// Given
$command = self::$application->find('pwa:sw');
$command = self::$application->find('pwa:create:sw');
$commandTester = new CommandTester($command);
$output = sprintf('%s/samples/my-sw.js', self::$kernel->getCacheDir());

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/TakeScreenshotCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class TakeScreenshotCommandTest extends AbstractPwaTestCase
public static function aScreenshotIsCorrectlyTake(): void
{
// Given
$command = self::$application->find('pwa:take-screenshot');
$command = self::$application->find('pwa:create:screenshot');
$commandTester = new CommandTester($command);
$output = sprintf('%s/samples/screenshots/', self::$kernel->getCacheDir());

Expand Down
2 changes: 1 addition & 1 deletion tests/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
],
'handle_links' => 'auto',
'serviceworker' => [
'src' => '/sw/my-sw.js',
'src' => __DIR__ . '/sw.js',
'scope' => '/',
'use_cache' => true,
],
Expand Down
24 changes: 24 additions & 0 deletions tests/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
importScripts(
'https://storage.googleapis.com/workbox-cdn/releases/7.0.0/workbox-sw.js'
);

// *** Recipes ***
// You are free to change or remove any of these presets as you wish.
// See https://developer.chrome.com/docs/workbox/modules/workbox-recipes for more information.
const {
pageCache,
imageCache,
staticResourceCache,
googleFontsCache,
} = workbox.recipes;

pageCache();// => Cache pages with a network-first strategy.
staticResourceCache();// => Cache CSS, JS, and Web Worker requests with a cache-first strategy.
imageCache();// => Cache images with a cache-first strategy.
googleFontsCache();// => Cache the underlying font files with a cache-first strategy.

// *** Bundle rules ***
//PRECACHING_PLACEHOLDER
//WARM_CACHE_URLS_PLACEHOLDER
//OFFLINE_FALLBACK_PLACEHOLDER
//WIDGETS_PLACEHOLDER

0 comments on commit 3f1a2be

Please sign in to comment.