44
55use Illuminate \Console \Command ;
66use Illuminate \Filesystem \Filesystem ;
7+
78use function Termwind \render ;
89
910class Configure extends Command
@@ -14,43 +15,58 @@ class Configure extends Command
1415
1516 public function handle (): void
1617 {
17- $ filesystem = new Filesystem () ;
18+ $ filesystem = new Filesystem ;
1819
1920 $ configs = [
20- 'rector.php ' ,
21- 'phpstan.neon ' ,
22- 'pint.json ' ,
21+ 'rector ' => [
22+ 'stub_file ' => __DIR__ .'/../../stubs/rector.php.stub ' ,
23+ 'config_file ' => 'rector.php ' ,
24+ 'description ' => 'Rector makes upgrading and maintaining code easier. ' ,
25+ ],
26+ 'phpstan ' => [
27+ 'stub_file ' => __DIR__ .'/../../stubs/phpstan.neon.stub ' ,
28+ 'config_file ' => 'phpstan.neon ' ,
29+ 'description ' => 'PHPStan helps detect errors at compile time instead of runtime. ' ,
30+ ],
31+ 'pint ' => [
32+ 'stub_file ' => __DIR__ .'/../../stubs/pint.json.stub ' ,
33+ 'config_file ' => 'pint.json ' ,
34+ 'description ' => 'Pint ensures your code follows consistent formatting rules. ' ,
35+ ],
2336 ];
2437
25- foreach ($ configs as $ file ) {
26- $ sourceFile = __DIR__ . "/../../config/laravel/ {$ file }" ;
27- $ destinationFile = base_path ($ file );
38+ render (view ('codebuddy::banner ' ));
39+
40+ foreach ($ configs as $ key => $ config ) {
41+ $ this ->newLine ();
42+ $ this ->info ("Configuring {$ key }... " );
43+
44+ $ stubFile = $ config ['stub_file ' ];
45+ $ destinationFile = base_path ($ config ['config_file ' ]);
2846
29- if (!$ filesystem ->exists ($ sourceFile )) {
30- $ this ->error ("Source file not found: {$ sourceFile }" );
47+ if (! $ filesystem ->exists ($ stubFile )) {
48+ $ this ->error ("Stub file not found: {$ stubFile }" );
3149 continue ;
3250 }
3351
3452 if ($ filesystem ->exists ($ destinationFile )) {
3553 $ overwrite = $ this ->confirmOverwrite ($ destinationFile );
36- if (!$ overwrite ) {
37- $ this ->warn (" Skipped: { $ destinationFile } already exists " );
54+ if (! $ overwrite ) {
55+ $ this ->warn (sprintf ( ' Skipped: %s already exists ' , basename ( $ destinationFile )) );
3856 continue ;
3957 }
4058 }
4159
42- $ filesystem ->copy ($ sourceFile , $ destinationFile );
43- $ this ->info ("Copied: {$ file } to project root " );
60+ $ content = file_get_contents ($ stubFile );
61+
62+ $ filesystem ->put ($ destinationFile , $ content );
63+ $ this ->info (sprintf ('Created: %s in project root ' , $ config ['config_file ' ]));
4464 $ this ->newLine ();
4565 }
4666 }
4767
4868 private function confirmOverwrite (string $ file ): bool
4969 {
50- $ this ->info (
51- sprintf ('%s already exists. Do you want to overwrite it? ' , $ file )
52- );
53-
54- return $ this ->ask ('Overwrite? ' , false );
70+ return $ this ->confirm (sprintf ('%s already exists. Overwrite? ' , basename ($ file )), true );
5571 }
5672}
0 commit comments