Skip to content

Commit 35055bb

Browse files
committed
feat: add wildcard theme resolution to build and clean commands
1 parent 414a312 commit 35055bb

3 files changed

Lines changed: 83 additions & 6 deletions

File tree

src/Console/Command/AbstractCommand.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,54 @@ private function removeSecureEnvironmentValue(string $name): void
478478
unset($this->secureEnvStorage[$name]);
479479
$this->clearEnvironmentCache();
480480
}
481+
482+
/**
483+
* Resolve wildcard theme codes (e.g., Vendor/* to all underlying vendor themes)
484+
*
485+
* @param string[] $themeCodes
486+
* @param \OpenForgeProject\MageForge\Model\ThemeList $themeList
487+
* @return string[]
488+
*/
489+
protected function resolveWildcardThemes(array $themeCodes, \OpenForgeProject\MageForge\Model\ThemeList $themeList): array
490+
{
491+
$resolved = [];
492+
$availableThemes = null;
493+
494+
foreach ($themeCodes as $code) {
495+
if (\str_ends_with($code, '/*')) {
496+
// Lazy-load themes only when needed
497+
if ($availableThemes === null) {
498+
$availableThemes = array_map(
499+
fn($theme) => $theme->getCode(),
500+
$themeList->getAllThemes()
501+
);
502+
}
503+
504+
$prefix = substr($code, 0, -1); // Keeps the trailing slash, e.g. "Vendor/"
505+
506+
$matched = array_filter(
507+
$availableThemes,
508+
fn(string $availableCode) => \str_starts_with($availableCode, $prefix)
509+
);
510+
511+
if (empty($matched)) {
512+
$this->io->warning(sprintf("No themes found for prefix '%s'", $prefix));
513+
} else {
514+
$this->io->note(sprintf(
515+
"Resolved '%s' to %d theme(s): %s",
516+
$code,
517+
count($matched),
518+
implode(', ', $matched)
519+
));
520+
}
521+
522+
$resolved = array_merge($resolved, $matched);
523+
} else {
524+
$resolved[] = $code;
525+
}
526+
}
527+
528+
// Return a fresh list without duplicates
529+
return array_values(array_unique($resolved));
530+
}
481531
}

src/Console/Command/Theme/BuildCommand.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ protected function configure(): void
6666
protected function executeCommand(InputInterface $input, OutputInterface $output): int
6767
{
6868
$themeCodes = $input->getArgument('themeCodes');
69+
70+
// Allow wildcards using the AbstractCommand helper
71+
if (!empty($themeCodes)) {
72+
$themeCodes = $this->resolveWildcardThemes($themeCodes, $this->themeList);
73+
74+
// If wildcards matched nothing and no other explicit themes remain
75+
if (empty($themeCodes)) {
76+
return Command::SUCCESS;
77+
}
78+
}
79+
6980
$isVerbose = $this->isVerbose($output);
7081

7182
if (empty($themeCodes)) {
@@ -337,12 +348,19 @@ private function processTheme(
337348
private function displayBuildSummary(SymfonyStyle $io, array $successList, float $duration): void
338349
{
339350
$io->newLine();
340-
$io->success(sprintf('🚀 Build process completed in %.2f seconds with the following results:', $duration));
341-
$io->writeln('Summary:');
342-
$io->newLine();
343-
344-
if (empty($successList)) {
345-
$io->warning('No themes were built successfully.');
351+
352+
$successCount = count($successList);
353+
354+
if ($successCount > 0) {
355+
$io->success(sprintf(
356+
'🚀 Successfully built %d theme(s). Build process completed in %.2f seconds.',
357+
$successCount,
358+
$duration
359+
));
360+
$io->writeln('Summary:');
361+
$io->newLine();
362+
} else {
363+
$io->warning(sprintf('Build process completed in %.2f seconds, but no themes were built successfully.', $duration));
346364
return;
347365
}
348366

src/Console/Command/Theme/CleanCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ private function resolveThemeCodes(InputInterface $input, OutputInterface $outpu
105105
return $this->getAllThemeCodes();
106106
}
107107

108+
if (!empty($themeCodes)) {
109+
$themeCodes = $this->resolveWildcardThemes($themeCodes, $this->themeList);
110+
111+
// If wildcards matched nothing and no other explicit themes remain
112+
if (empty($themeCodes)) {
113+
return null;
114+
}
115+
}
116+
108117
if (empty($themeCodes)) {
109118
return $this->selectThemesInteractively($output);
110119
}

0 commit comments

Comments
 (0)