44
55use Illuminate \Console \Command ;
66use Illuminate \Filesystem \Filesystem ;
7+
8+ use Illuminate \Support \Facades \File ;
9+ use Illuminate \Support \Facades \Process ;
10+ use function Laravel \Prompts \spin ;
711use function Termwind \render ;
12+ use function Laravel \Prompts \info ;
813
914class Configure extends Command
1015{
@@ -14,43 +19,54 @@ class Configure extends Command
1419
1520 public function handle (): void
1621 {
17- $ filesystem = new Filesystem ( );
22+ render ( view ( ' codebuddy::banner ' ) );
1823
19- $ configs = [
20- 'rector.php ' ,
21- 'phpstan.neon ' ,
22- 'pint.json ' ,
24+ $ packages = [
25+ [
26+ 'package_name ' => 'driftingly/rector-laravel ' ,
27+ 'stub_file ' => 'rector.php.stub ' ,
28+ 'config_file ' => 'rector.php ' ,
29+ 'description ' => 'Rector makes upgrading and maintaining code easier. ' ,
30+ ],
31+ [
32+ 'package_name ' => 'larastan/larastan ' ,
33+ 'stub_file ' => 'phpstan.neon.stub ' ,
34+ 'config_file ' => 'phpstan.neon ' ,
35+ 'description ' => 'PHPStan helps detect errors at compile time instead of runtime. ' ,
36+ ],
37+ [
38+ 'package_name ' => 'laravel/pint ' ,
39+ 'stub_file ' => 'pint.json.stub ' ,
40+ 'config_file ' => 'pint.json ' ,
41+ 'description ' => 'Pint ensures your code follows consistent formatting rules. ' ,
42+ ],
43+ [
44+ 'package_name ' => 'pestphp/pest ' ,
45+ 'stub_file ' => 'phpunit.xml.stub ' ,
46+ 'config_file ' => 'phpunit.xml ' ,
47+ 'description ' => 'Elegant testing framework. ' ,
48+ ],
2349 ];
2450
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 ();
51+ foreach ($ packages as $ package ) {
52+ $ this ->configurePackage ($ package );
4553 }
4654 }
4755
48- private function confirmOverwrite ( string $ file ): bool
56+ private function configurePackage ( array $ package ): void
4957 {
50- $ this ->info (
51- sprintf ('%s already exists. Do you want to overwrite it? ' , $ file )
52- );
53-
54- return $ this ->ask ('Overwrite? ' , false );
58+ spin (
59+ callback: function () use ($ package ): void {
60+ sleep (1 );
61+ $ result = File::copy (
62+ __DIR__ .'/../../stubs/ ' . $ package ['stub_file ' ],
63+ base_path ($ package ['config_file ' ])
64+ );
65+ if (! $ result ) {
66+ self ::fail (sprintf ('❌ Failed to copy %s configuration file ' , $ package ['config_file ' ]));
67+ }
68+ },
69+ message: sprintf ('Configuring %s... ' , $ package ['package_name ' ]));
70+ $ this ->info (sprintf ('✅ %s configured successfully! ' , $ package ['package_name ' ]));
5571 }
5672}
0 commit comments