Skip to content

Commit 97bb7f9

Browse files
committed
feat: support multiple theme codes for build and clean commands
1 parent cd33ab0 commit 97bb7f9

4 files changed

Lines changed: 37 additions & 18 deletions

File tree

docs/commands.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ bin/magento mageforge:theme:build [<themeCodes>...]
5656

5757
**Implementation Details**:
5858

59+
- `themeCodes` accepts single themes (`Vendor/theme`) or just the vendor name (`Vendor`) to target all themes of a specific vendor.
5960
- If no theme codes are provided, displays an interactive prompt to select themes
6061
- For each selected theme:
6162
1. Resolves the theme path
@@ -109,11 +110,13 @@ bin/magento mageforge:theme:watch [--theme=THEME]
109110
**Usage**:
110111

111112
```bash
112-
bin/magento mageforge:theme:clean [<themename>]
113+
bin/magento mageforge:theme:clean [<themename>...]
113114
```
114115

115116
**Implementation Details**:
116117

118+
- Can accept multiple themes like `Vendor/theme1 Vendor/theme2`.
119+
- Accepts simply the vendor name `Vendor` to clean all registered themes for a vendor.
117120
- If no theme name is provided:
118121
- In interactive terminals, displays an interactive prompt to select the theme to clean
119122
- In non-interactive environments, prints the list of available themes and exits, requiring an explicit theme name

src/Console/Command/AbstractCommand.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,21 +481,25 @@ private function removeSecureEnvironmentValue(string $name): void
481481
}
482482

483483
/**
484-
* Resolve wildcard theme codes (e.g., Vendor/* to all underlying vendor themes)
484+
* Resolve vendor theme codes (e.g., Vendor to all underlying vendor themes)
485485
*
486486
* @param array<string> $themeCodes
487487
* @param ThemeList $themeList
488488
* @return array<string>
489489
*/
490-
protected function resolveWildcardThemes(
490+
protected function resolveVendorThemes(
491491
array $themeCodes,
492492
ThemeList $themeList
493493
): array {
494494
$resolved = [];
495495
$availableThemes = null;
496496

497497
foreach ($themeCodes as $code) {
498-
if (\str_ends_with($code, '/*')) {
498+
// Check if it's explicitly a wildcard OR just a vendor name without a slash
499+
$isExplicitWildcard = \str_ends_with($code, '/*');
500+
$isVendorOnly = !\str_contains($code, '/');
501+
502+
if ($isExplicitWildcard || $isVendorOnly) {
499503
// Lazy-load themes only when needed
500504
if ($availableThemes === null) {
501505
$availableThemes = array_map(
@@ -504,25 +508,37 @@ protected function resolveWildcardThemes(
504508
);
505509
}
506510

507-
$prefix = substr($code, 0, -1); // Keeps the trailing slash, e.g. "Vendor/"
508-
511+
if ($isExplicitWildcard) {
512+
$prefix = substr($code, 0, -1); // Keeps the trailing slash, e.g. "Vendor/"
513+
} else {
514+
$prefix = $code . '/'; // e.g. "Vendor" -> "Vendor/"
515+
}
516+
509517
$matched = array_filter(
510518
$availableThemes,
511519
fn(string $availableCode) => \str_starts_with($availableCode, $prefix)
512520
);
513521

514522
if (empty($matched)) {
515-
$this->io->warning(sprintf("No themes found for prefix '%s'", $prefix));
523+
$this->io->warning(sprintf("No themes found for vendor/prefix '%s'", $prefix));
524+
525+
// If they typed just a word and it wasn't a vendor,
526+
// we still add it so standard Magento validation kicks in later.
527+
if ($isVendorOnly) {
528+
$resolved[] = $code;
529+
}
516530
} else {
517531
$this->io->note(sprintf(
518-
"Resolved '%s' to %d theme(s): %s",
532+
"Resolved vendor '%s' to %d theme(s): %s",
519533
$code,
520534
count($matched),
521535
implode(', ', $matched)
522536
));
523-
}
524537

525-
array_push($resolved, ...$matched);
538+
foreach ($matched as $match) {
539+
$resolved[] = $match;
540+
}
541+
}
526542
} else {
527543
$resolved[] = $code;
528544
}

src/Console/Command/Theme/BuildCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function configure(): void
5151
->addArgument(
5252
'themeCodes',
5353
InputArgument::IS_ARRAY,
54-
'Theme codes to build (format: Vendor/theme, Vendor/theme 2, ...)',
54+
'Theme codes to build (format: Vendor/theme, Vendor, ...)',
5555
)
5656
->setAliases(['frontend:build']);
5757
}
@@ -69,8 +69,8 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
6969

7070
// Allow wildcards using the AbstractCommand helper
7171
if (!empty($themeCodes)) {
72-
$themeCodes = $this->resolveWildcardThemes($themeCodes, $this->themeList);
73-
72+
$themeCodes = $this->resolveVendorThemes($themeCodes, $this->themeList);
73+
7474
// If wildcards matched nothing and no other explicit themes remain
7575
if (empty($themeCodes)) {
7676
return Command::SUCCESS;
@@ -348,9 +348,9 @@ private function processTheme(
348348
private function displayBuildSummary(SymfonyStyle $io, array $successList, float $duration): void
349349
{
350350
$io->newLine();
351-
351+
352352
$successCount = count($successList);
353-
353+
354354
if ($successCount > 0) {
355355
$io->success(sprintf(
356356
'🚀 Successfully built %d theme(s). Build process completed in %.2f seconds.',

src/Console/Command/Theme/CleanCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function configure(): void
4949
->addArgument(
5050
'themeCodes',
5151
InputArgument::IS_ARRAY,
52-
'Theme codes to clean (format: Vendor/theme, Vendor/theme 2, ...)',
52+
'Theme codes to clean (format: Vendor/theme, Vendor, ...)',
5353
)
5454
->addOption('all', 'a', InputOption::VALUE_NONE, 'Clean all themes')
5555
->addOption(
@@ -106,8 +106,8 @@ private function resolveThemeCodes(InputInterface $input, OutputInterface $outpu
106106
}
107107

108108
if (!empty($themeCodes)) {
109-
$themeCodes = $this->resolveWildcardThemes($themeCodes, $this->themeList);
110-
109+
$themeCodes = $this->resolveVendorThemes($themeCodes, $this->themeList);
110+
111111
// If wildcards matched nothing and no other explicit themes remain
112112
if (empty($themeCodes)) {
113113
return null;

0 commit comments

Comments
 (0)