|
3 | 3 | namespace Codebuddyphp\Codebuddy\Commands; |
4 | 4 |
|
5 | 5 | use Illuminate\Console\Command; |
6 | | -use Illuminate\Filesystem\Filesystem; |
7 | | -use function Termwind\render; |
| 6 | +use Illuminate\Support\Facades\Config; |
| 7 | +use Illuminate\Support\Facades\File; |
8 | 8 |
|
9 | | -class Configure extends Command |
| 9 | +use function Laravel\Prompts\confirm; |
| 10 | +use function Laravel\Prompts\spin; |
| 11 | + |
| 12 | +final class Configure extends Command |
10 | 13 | { |
11 | | - protected $signature = 'codebuddy:configure'; |
| 14 | + protected $signature = 'cb:configure'; |
12 | 15 |
|
13 | | - protected $description = 'Configure Rector, Larastan (PHPStan) & Pint'; |
| 16 | + protected $description = 'Configures essential packages for your project'; |
14 | 17 |
|
15 | 18 | public function handle(): void |
16 | 19 | { |
17 | | - $filesystem = new Filesystem(); |
18 | | - |
19 | | - $configs = [ |
20 | | - 'rector.php', |
21 | | - 'phpstan.neon', |
22 | | - 'pint.json', |
23 | | - ]; |
24 | | - |
25 | | - foreach ($configs as $file) { |
26 | | - $sourceFile = __DIR__ . "/../../config/laravel/{$file}"; |
27 | | - $destinationFile = base_path($file); |
28 | | - |
29 | | - if (!$filesystem->exists($sourceFile)) { |
30 | | - $this->error("Source file not found: {$sourceFile}"); |
31 | | - continue; |
32 | | - } |
33 | | - |
34 | | - if ($filesystem->exists($destinationFile)) { |
35 | | - $overwrite = $this->confirmOverwrite($destinationFile); |
36 | | - if (!$overwrite) { |
37 | | - $this->warn("Skipped: {$destinationFile} already exists"); |
38 | | - continue; |
39 | | - } |
40 | | - } |
| 20 | + $packages = Config::get('codebuddy.checks'); |
| 21 | + |
| 22 | + foreach ($packages as $package) { |
| 23 | + $this->configurePackage($package); |
| 24 | + } |
| 25 | + |
| 26 | + $confirmed = confirm('Setup completed. Do you want to review codebase?'); |
41 | 27 |
|
42 | | - $filesystem->copy($sourceFile, $destinationFile); |
43 | | - $this->info("Copied: {$file} to project root"); |
44 | | - $this->newLine(); |
| 28 | + if ($confirmed) { |
| 29 | + $this->call(Review::class); |
45 | 30 | } |
46 | 31 | } |
47 | 32 |
|
48 | | - private function confirmOverwrite(string $file): bool |
| 33 | + private function configurePackage(array $package): void |
49 | 34 | { |
50 | | - $this->info( |
51 | | - sprintf('%s already exists. Do you want to overwrite it?', $file) |
52 | | - ); |
| 35 | + $this->newLine(); |
| 36 | + |
| 37 | + spin( |
| 38 | + callback: function () use ($package): void { |
| 39 | + sleep(1); |
| 40 | + $result = File::copy( |
| 41 | + __DIR__.'/../../stubs/'.$package['stub_file'], |
| 42 | + base_path($package['config_file']) |
| 43 | + ); |
| 44 | + if (! $result) { |
| 45 | + self::fail( |
| 46 | + sprintf('%s: failed to configure', $package['package']) |
| 47 | + ); |
| 48 | + } |
| 49 | + }, |
| 50 | + message: sprintf('🚀 Configuring %s...', $package['package'])); |
53 | 51 |
|
54 | | - return $this->ask('Overwrite?', false); |
| 52 | + $this->info(sprintf('✅ %s: configured', $package['package'])); |
55 | 53 | } |
56 | 54 | } |
0 commit comments