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+ 'config_file ' => 'rector.php ' ,
23+ 'description ' => 'Rector makes easy to upgrade things & maintain code-quality ' ,
24+ ],
25+ 'phpstan ' => [
26+ 'config_file ' => 'phpstan.neon ' ,
27+ 'description ' => 'Phpstan is like typescript of PHP - avoid bugs at runtime ' ,
28+ ],
29+ 'pint ' => [
30+ 'config_file ' => 'pint.json ' ,
31+ 'description ' => 'Pint is a ' ,
32+ ],
2333 ];
2434
25- foreach ($ configs as $ file ) {
26- $ sourceFile = __DIR__ . "/../../config/laravel/ {$ file }" ;
27- $ destinationFile = base_path ($ file );
35+ render (
36+ view ('codebuddy::banner ' )
37+ );
38+
39+ foreach ($ configs as $ key => $ config ) {
40+
41+ $ this ->newLine ();
42+ $ this ->info ("Configuring {$ key }... " );
43+
44+ $ sourceFile = __DIR__ .'/../../config/laravel/ ' .$ config ['config_file ' ];
45+ $ destinationFile = base_path ($ config ['config_file ' ]);
2846
29- if (!$ filesystem ->exists ($ sourceFile )) {
47+ if (! $ filesystem ->exists ($ sourceFile )) {
3048 $ this ->error ("Source file not found: {$ sourceFile }" );
49+
3150 continue ;
3251 }
3352
3453 if ($ filesystem ->exists ($ destinationFile )) {
3554 $ overwrite = $ this ->confirmOverwrite ($ destinationFile );
36- if (!$ overwrite ) {
37- $ this ->warn ("Skipped: {$ destinationFile } already exists " );
55+ if (! $ overwrite ) {
56+ $ this ->warn (
57+ sprintf ('Skipped: %s already exists ' , basename ($ destinationFile ))
58+ );
59+
3860 continue ;
3961 }
4062 }
4163
4264 $ filesystem ->copy ($ sourceFile , $ destinationFile );
43- $ this ->info ("Copied: {$ file } to project root " );
65+ $ this ->info (
66+ sprintf ('Created: %s in project root ' , $ config ['config_file ' ])
67+ );
4468 $ this ->newLine ();
4569 }
4670 }
4771
4872 private function confirmOverwrite (string $ file ): bool
4973 {
5074 $ this ->info (
51- sprintf ('%s already exists. Do you want to overwrite it? ' , $ file )
75+ sprintf ('%s already exists. Do you want to overwrite it? ' , basename ( $ file) )
5276 );
5377
54- return $ this ->ask ('Overwrite? ' , false );
78+ return $ this ->confirm ('Overwrite? ' , true );
5579 }
5680}
0 commit comments