44
55use Illuminate \Console \Command ;
66use Illuminate \Filesystem \Filesystem ;
7+
78use function Termwind \render ;
89
910class Configure extends Command
@@ -14,43 +15,66 @@ 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 ' => 'rector.php.stub ' ,
23+ 'config_file ' => 'rector.php ' ,
24+ 'description ' => 'Rector makes upgrading and maintaining code easier. ' ,
25+ ],
26+ 'phpstan ' => [
27+ 'stub_file ' => '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 ' => '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+ $ this ->info ($ config ['description ' ]);
44+
45+ $ stubFile = $ this ->getStubPath ($ config ['stub_file ' ]);
46+ $ destinationFile = base_path ($ config ['config_file ' ]);
47+
48+ if (! $ filesystem ->exists ($ stubFile )) {
49+ $ this ->error ("Stub file not found: {$ stubFile }" );
2850
29- if (!$ filesystem ->exists ($ sourceFile )) {
30- $ this ->error ("Source file not found: {$ sourceFile }" );
3151 continue ;
3252 }
3353
3454 if ($ filesystem ->exists ($ destinationFile )) {
3555 $ overwrite = $ this ->confirmOverwrite ($ destinationFile );
36- if (!$ overwrite ) {
37- $ this ->warn ("Skipped: {$ destinationFile } already exists " );
56+ if (! $ overwrite ) {
57+ $ this ->warn (sprintf ('Skipped: %s already exists ' , basename ($ destinationFile )));
58+
3859 continue ;
3960 }
4061 }
4162
42- $ filesystem ->copy ($ sourceFile , $ destinationFile );
43- $ this ->info ("Copied: {$ file } to project root " );
63+ $ content = file_get_contents ($ stubFile );
64+
65+ $ filesystem ->put ($ destinationFile , $ content );
66+ $ this ->info (sprintf ('Created: %s in project root ' , $ config ['config_file ' ]));
4467 $ this ->newLine ();
4568 }
4669 }
4770
4871 private function confirmOverwrite (string $ file ): bool
4972 {
50- $ this ->info (
51- sprintf ('%s already exists. Do you want to overwrite it? ' , $ file )
52- );
73+ return $ this ->confirm (sprintf ('%s already exists. Overwrite? ' , basename ($ file )), true );
74+ }
5375
54- return $ this ->ask ('Overwrite? ' , false );
76+ private function getStubPath (string $ filename ): string
77+ {
78+ return __DIR__ .'/../../stubs/ ' .$ filename ;
5579 }
5680}
0 commit comments