33namespace Codebuddyphp \Codebuddy \Commands ;
44
55use Illuminate \Console \Command ;
6- use Illuminate \Filesystem \Filesystem ;
6+ use Illuminate \Support \Facades \File ;
7+
8+ use function Laravel \Prompts \spin ;
79use function Termwind \render ;
810
911class Configure extends Command
@@ -14,43 +16,54 @@ class Configure extends Command
1416
1517 public function handle (): void
1618 {
17- $ filesystem = new Filesystem ( );
19+ render ( view ( ' codebuddy::banner ' ) );
1820
19- $ configs = [
20- 'rector.php ' ,
21- 'phpstan.neon ' ,
22- 'pint.json ' ,
21+ $ packages = [
22+ [
23+ 'package_name ' => 'driftingly/rector-laravel ' ,
24+ 'stub_file ' => 'rector.php.stub ' ,
25+ 'config_file ' => 'rector.php ' ,
26+ 'description ' => 'Rector makes upgrading and maintaining code easier. ' ,
27+ ],
28+ [
29+ 'package_name ' => 'larastan/larastan ' ,
30+ 'stub_file ' => 'phpstan.neon.stub ' ,
31+ 'config_file ' => 'phpstan.neon ' ,
32+ 'description ' => 'PHPStan helps detect errors at compile time instead of runtime. ' ,
33+ ],
34+ [
35+ 'package_name ' => 'laravel/pint ' ,
36+ 'stub_file ' => 'pint.json.stub ' ,
37+ 'config_file ' => 'pint.json ' ,
38+ 'description ' => 'Pint ensures your code follows consistent formatting rules. ' ,
39+ ],
40+ [
41+ 'package_name ' => 'pestphp/pest ' ,
42+ 'stub_file ' => 'phpunit.xml.stub ' ,
43+ 'config_file ' => 'phpunit.xml ' ,
44+ 'description ' => 'Elegant testing framework. ' ,
45+ ],
2346 ];
2447
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- }
41-
42- $ filesystem ->copy ($ sourceFile , $ destinationFile );
43- $ this ->info ("Copied: {$ file } to project root " );
44- $ this ->newLine ();
48+ foreach ($ packages as $ package ) {
49+ $ this ->configurePackage ($ package );
4550 }
4651 }
4752
48- private function confirmOverwrite ( string $ file ): bool
53+ private function configurePackage ( array $ package ): void
4954 {
50- $ this ->info (
51- sprintf ('%s already exists. Do you want to overwrite it? ' , $ file )
52- );
53-
54- return $ this ->ask ('Overwrite? ' , false );
55+ spin (
56+ callback: function () use ($ package ): void {
57+ sleep (1 );
58+ $ result = File::copy (
59+ __DIR__ .'/../../stubs/ ' .$ package ['stub_file ' ],
60+ base_path ($ package ['config_file ' ])
61+ );
62+ if (! $ result ) {
63+ self ::fail (sprintf ('❌ Failed to copy %s configuration file ' , $ package ['config_file ' ]));
64+ }
65+ },
66+ message: sprintf ('Configuring %s... ' , $ package ['package_name ' ]));
67+ $ this ->info (sprintf ('✅ %s configured successfully! ' , $ package ['package_name ' ]));
5568 }
5669}
0 commit comments