Files
Epicnabbo-Catalogus-Updated…/cms update/app/Console/Commands/BuildTheme.php
T
2026-02-02 20:56:28 +01:00

73 lines
1.7 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
class BuildTheme extends Command
{
protected $signature = 'build:theme';
protected $description = 'Build a selected theme assets';
public function handle(): int
{
$themes = $this->getAvailableThemes();
if ($themes->isEmpty()) {
$this->error('No themes found in resources/themes/');
return Command::FAILURE;
}
$selectedTheme = $this->choice(
'Which theme would you like to build?',
$themes->toArray(),
0,
);
$this->info("Building {$selectedTheme} theme...");
if (is_array($selectedTheme)) {
$selectedTheme = $selectedTheme[0] ?? '';
}
$this->runBuildCommand((string) $selectedTheme);
return Command::SUCCESS;
}
private function getAvailableThemes(): \Illuminate\Support\Collection
{
$themesPath = resource_path('themes');
if (! File::exists($themesPath)) {
return collect();
}
return collect(File::directories($themesPath))
->map(fn ($path) => basename((string) $path))
->sort();
}
private function runBuildCommand(string $theme): void
{
$command = escapeshellcmd("npm run build:{$theme}");
$output = [];
$returnCode = 0;
exec($command, $output, $returnCode);
foreach ($output as $line) {
$this->line($line);
}
if ($returnCode === 0) {
$this->info("Theme {$theme} built successfully!");
} else {
$this->error("Failed to build theme {$theme}");
}
}
}