Skip to content

Commit

Permalink
Allow screenshots to be loaded from a folder (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky authored Dec 22, 2023
1 parent 060327b commit 0bc6a6b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 22 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"symfony/config": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/filesystem": "^6.4|^7.0",
"symfony/finder": "^6.4",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/mime": "^6.4|^7.0",
"symfony/routing": "^6.4|^7.0"
Expand Down
36 changes: 36 additions & 0 deletions src/Command/GenerateManifestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Mime\MimeTypes;
use Symfony\Component\Routing\RouterInterface;
use function count;
Expand Down Expand Up @@ -243,7 +244,20 @@ private function processScreenshots(SymfonyStyle $io, array $manifest): array|in
$progressBar = $io->createProgressBar(count($this->config['screenshots']));
$progressBar->start();
$io->info('Processing screenshots');
$config = [];
foreach ($this->config['screenshots'] as $screenshot) {
$src = $screenshot['src'];
if (! $this->filesystem->exists($src)) {
continue;
}
foreach ($this->findImages($src) as $image) {
$data = $screenshot;
$data['src'] = $image;
$config[] = $data;
}
}

foreach ($config as $screenshot) {
$this->processProgressBar($progressBar, 'screenshot', $screenshot['src']);
$data = $this->loadFileAndConvert($screenshot['src'], null, $screenshot['format'] ?? null);
if ($data === null) {
Expand Down Expand Up @@ -391,4 +405,26 @@ private function processActions(SymfonyStyle $io, array $manifest): array|int

return $manifest;
}

/**
* @return iterable<string}>
*/
private function findImages(string $src): iterable
{
$finder = new Finder();
if (is_file($src)) {
yield $src;
return;
}
$files = $finder->in($src)
->files()
->name('/\.(png|jpg|jpeg|gif|webp|svg)$/i');
foreach ($files as $file) {
if ($file->isFile()) {
yield $file->getRealPath();
} else {
yield from $this->findImages($file->getRealPath());
}
}
}
}
23 changes: 1 addition & 22 deletions tests/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,10 @@
'theme_color' => 'red',
'screenshots' => [
[
'src' => sprintf('%s/images/360x800.svg', __DIR__),
'label' => 'Homescreen of Awesome App',
'src' => sprintf('%s/images/screenshots', __DIR__),
'platform' => 'android',
'format' => 'png',
],
[
'src' => sprintf('%s/images/390x844.svg', __DIR__),
'label' => 'List of Awesome Resources available in Awesome App',
'platform' => 'windows',
'format' => 'jpeg',
],
[
'src' => sprintf('%s/images/600x400.svg', __DIR__),
'label' => 'Awesome App in action (1)',
'format' => 'webp',
],
[
'src' => sprintf('%s/images/780x360.svg', __DIR__),
'label' => 'Awesome App in action (2)',
'format' => 'webp',
],
[
'src' => sprintf('%s/images/915x412.svg', __DIR__),
'label' => 'Awesome App in action (3)',
],
],
'share_target' => [
'action' => '/shared-content-receiver/',
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 0bc6a6b

Please sign in to comment.