Skip to content

Commit

Permalink
Update Component publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed May 8, 2024
1 parent ad488b7 commit 410dc97
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions packages/admin/src/Console/ComponentPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace Shopper\Console;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Finder\Finder;

use function Laravel\Prompts\select;

#[AsCommand(name: 'shopper:component:publish')]
final class ComponentPublishCommand extends Command
{
Expand All @@ -30,13 +33,35 @@ final class ComponentPublishCommand extends Command

/**
* Execute the console command.
*
* @return int|void
*/
public function handle(): int
public function handle()
{
$config = $this->getBaseConfigurationFiles();
dd($config);

return 1;
if (is_null($this->argument('name')) && $this->option('all')) {
foreach ($config as $key => $file) {
$this->publish($key, $file, $this->getShopperComponentsConfigFolder().'/'.$key.'.php');
}

return;
}

$name = (string) (is_null($this->argument('name')) ? select(
label: 'Which components configuration file would you like to publish?',
options: collect($config)->map(function (string $path) {
return basename($path, '.php');
}),
) : $this->argument('name'));

if (! is_null($name) && ! isset($config[$name])) {
$this->components->error('Unrecognized component configuration file.');

return 1;
}

$this->publish($name, $config[$name], $this->getShopperComponentsConfigFolder().'/'.$name.'.php');
}

/**
Expand All @@ -50,9 +75,13 @@ protected function publish(string $name, string $file, string $destination): voi
return;
}

if (! File::exists($this->getShopperComponentsConfigFolder())) {
File::makeDirectory($this->getShopperComponentsConfigFolder());
}

copy($file, $destination);

$this->components->info("Published '{$name}' configuration file.");
$this->components->info("Published '{$name}' components configuration file.");
}

/**
Expand All @@ -70,4 +99,9 @@ protected function getBaseConfigurationFiles(): array

return collect($config)->sortKeys()->all();
}

protected function getShopperComponentsConfigFolder(): string
{
return $this->laravel->configPath().'/shopper/components';
}
}

0 comments on commit 410dc97

Please sign in to comment.