2
2
3
3
namespace Codelabmw \Suave \Traits ;
4
4
5
- use Illuminate \Support \Arr ;
6
5
use Illuminate \Filesystem \Filesystem ;
6
+ use Illuminate \Support \Arr ;
7
7
use Illuminate \Support \Str ;
8
-
9
8
use RuntimeException ;
10
9
use Symfony \Component \Process \PhpExecutableFinder ;
11
10
use Symfony \Component \Process \Process ;
@@ -29,7 +28,7 @@ protected function installApi()
29
28
$ this ->addApiPrefix ('v1 ' );
30
29
31
30
// Middleware...
32
- $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Http/Middleware ' , app_path ('Http/Middleware ' ));
31
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Http/Middleware ' , app_path ('Http/Middleware ' ));
33
32
34
33
$ this ->installMiddlewareAliases ([
35
34
'verified ' => '\App\Http\Middleware\EnsureEmailIsVerified::class ' ,
@@ -42,58 +41,58 @@ protected function installApi()
42
41
43
42
// Contracts
44
43
$ files ->ensureDirectoryExists (app_path ('Contracts ' ));
45
- $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Contracts ' , app_path ('Contracts ' ));
44
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Contracts ' , app_path ('Contracts ' ));
46
45
47
46
// Events
48
47
$ files ->ensureDirectoryExists (app_path ('Events ' ));
49
- $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Events ' , app_path ('Events ' ));
48
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Events ' , app_path ('Events ' ));
50
49
51
50
// Listeners
52
51
$ files ->ensureDirectoryExists (app_path ('Listeners ' ));
53
- $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Listeners ' , app_path ('Listeners ' ));
52
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Listeners ' , app_path ('Listeners ' ));
54
53
55
54
// Models
56
55
$ files ->ensureDirectoryExists (app_path ('Models ' ));
57
- $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Models ' , app_path ('Models ' ));
56
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Models ' , app_path ('Models ' ));
58
57
59
58
// Notifications
60
59
$ files ->ensureDirectoryExists (app_path ('Notifications ' ));
61
- $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Notifications ' , app_path ('Notifications ' ));
60
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Notifications ' , app_path ('Notifications ' ));
62
61
63
62
// Traits
64
63
$ files ->ensureDirectoryExists (app_path ('Traits ' ));
65
- $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Traits ' , app_path ('Traits ' ));
64
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Traits ' , app_path ('Traits ' ));
66
65
67
66
// Controllers...
68
67
$ files ->ensureDirectoryExists (app_path ('Http/Controllers/Account ' ));
69
68
$ files ->ensureDirectoryExists (app_path ('Http/Controllers/Account/Token ' ));
70
69
$ files ->ensureDirectoryExists (app_path ('Http/Controllers/Account/Session ' ));
71
- $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Http/Controllers/Account ' , app_path ('Http/Controllers/Account ' ));
70
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/app/Http/Controllers/Account ' , app_path ('Http/Controllers/Account ' ));
72
71
73
72
// Configuration...
74
- $ files ->copyDirectory (__DIR__ . '/../../stubs/config ' , config_path ());
73
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/config ' , config_path ());
75
74
76
75
// Factories...
77
- $ files ->copyDirectory (__DIR__ . '/../../stubs/database/factories ' , base_path ('database/factories ' ));
76
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/database/factories ' , base_path ('database/factories ' ));
78
77
79
78
// Environment...
80
- if (!$ files ->exists (base_path ('.env ' ))) {
79
+ if (! $ files ->exists (base_path ('.env ' ))) {
81
80
copy (base_path ('.env.example ' ), base_path ('.env ' ));
82
81
}
83
82
84
83
file_put_contents (
85
84
base_path ('.env ' ),
86
- preg_replace ('/APP_URL=(.*)/ ' , 'APP_URL=http://localhost:8000 ' . PHP_EOL . 'FRONTEND_URL=http://localhost:3000 ' , file_get_contents (base_path ('.env ' )))
85
+ preg_replace ('/APP_URL=(.*)/ ' , 'APP_URL=http://localhost:8000 ' . PHP_EOL . 'FRONTEND_URL=http://localhost:3000 ' , file_get_contents (base_path ('.env ' )))
87
86
);
88
87
89
88
// Routes...
90
- $ files ->copyDirectory (__DIR__ . '/../../stubs/routes ' , base_path ('routes ' ));
89
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/routes ' , base_path ('routes ' ));
91
90
92
91
// Pest Tests...
93
92
$ files ->ensureDirectoryExists (base_path ('tests/Feature ' ));
94
- $ files ->copyDirectory (__DIR__ . '/../../stubs/pest-tests/Feature ' , base_path ('tests/Feature ' ));
95
- $ files ->copyDirectory (__DIR__ . '/../../stubs/pest-tests/Unit ' , base_path ('tests/Unit ' ));
96
- $ files ->copy (__DIR__ . '/../../stubs/pest-tests/Pest.php ' , base_path ('tests/Pest.php ' ));
93
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/pest-tests/Feature ' , base_path ('tests/Feature ' ));
94
+ $ files ->copyDirectory (__DIR__ . '/../../stubs/pest-tests/Unit ' , base_path ('tests/Unit ' ));
95
+ $ files ->copy (__DIR__ . '/../../stubs/pest-tests/Pest.php ' , base_path ('tests/Pest.php ' ));
97
96
}
98
97
99
98
/**
@@ -110,7 +109,7 @@ protected function addApiPrefix(string $prefix): void
110
109
$ bootstrapApp = str_replace (
111
110
'->withRouting( ' ,
112
111
'->withRouting( '
113
- . PHP_EOL . " apiPrefix: ' $ prefix', " ,
112
+ .PHP_EOL . " apiPrefix: ' $ prefix', " ,
114
113
$ bootstrapApp ,
115
114
);
116
115
@@ -125,17 +124,17 @@ protected function installMiddleware(array|string $names, string $group = 'web',
125
124
$ bootstrapApp = file_get_contents (base_path ('bootstrap/app.php ' ));
126
125
127
126
$ names = collect (Arr::wrap ($ names ))
128
- ->filter (fn ($ name ) => !Str::contains ($ bootstrapApp , $ name ))
127
+ ->filter (fn ($ name ) => ! Str::contains ($ bootstrapApp , $ name ))
129
128
->whenNotEmpty (function ($ names ) use ($ bootstrapApp , $ group , $ modifier ) {
130
- $ names = $ names ->map (fn ($ name ) => "$ name " )->implode (', ' . PHP_EOL . ' ' );
129
+ $ names = $ names ->map (fn ($ name ) => "$ name " )->implode (', ' . PHP_EOL . ' ' );
131
130
132
131
$ bootstrapApp = str_replace (
133
132
'->withMiddleware(function (Middleware $middleware) { ' ,
134
133
'->withMiddleware(function (Middleware $middleware) { '
135
- . PHP_EOL . " \$middleware-> $ group( $ modifier: [ "
136
- . PHP_EOL . " $ names, "
137
- . PHP_EOL . ' ]); '
138
- . PHP_EOL ,
134
+ .PHP_EOL . " \$middleware-> $ group( $ modifier: [ "
135
+ .PHP_EOL . " $ names, "
136
+ .PHP_EOL . ' ]); '
137
+ .PHP_EOL ,
139
138
$ bootstrapApp ,
140
139
);
141
140
@@ -151,17 +150,17 @@ protected function installMiddlewareAliases(array $aliases): void
151
150
$ bootstrapApp = file_get_contents (base_path ('bootstrap/app.php ' ));
152
151
153
152
$ aliases = collect ($ aliases )
154
- ->filter (fn ($ alias ) => !Str::contains ($ bootstrapApp , $ alias ))
153
+ ->filter (fn ($ alias ) => ! Str::contains ($ bootstrapApp , $ alias ))
155
154
->whenNotEmpty (function ($ aliases ) use ($ bootstrapApp ) {
156
- $ aliases = $ aliases ->map (fn ($ name , $ alias ) => "' $ alias' => $ name " )->implode (', ' . PHP_EOL . ' ' );
155
+ $ aliases = $ aliases ->map (fn ($ name , $ alias ) => "' $ alias' => $ name " )->implode (', ' . PHP_EOL . ' ' );
157
156
158
157
$ bootstrapApp = str_replace (
159
158
'->withMiddleware(function (Middleware $middleware) { ' ,
160
159
'->withMiddleware(function (Middleware $middleware) { '
161
- . PHP_EOL . ' $middleware->alias([ '
162
- . PHP_EOL . " $ aliases, "
163
- . PHP_EOL . ' ]); '
164
- . PHP_EOL ,
160
+ .PHP_EOL . ' $middleware->alias([ '
161
+ .PHP_EOL . " $ aliases, "
162
+ .PHP_EOL . ' ]); '
163
+ .PHP_EOL ,
165
164
$ bootstrapApp ,
166
165
);
167
166
@@ -259,12 +258,12 @@ protected function runCommands(array $commands): void
259
258
try {
260
259
$ process ->setTty (true );
261
260
} catch (RuntimeException $ e ) {
262
- $ this ->output ->writeln (' <bg=yellow;fg=black> WARN </> ' . $ e ->getMessage () . PHP_EOL );
261
+ $ this ->output ->writeln (' <bg=yellow;fg=black> WARN </> ' . $ e ->getMessage (). PHP_EOL );
263
262
}
264
263
}
265
264
266
265
$ process ->run (function ($ type , $ line ) {
267
- $ this ->output ->write (' ' . $ line );
266
+ $ this ->output ->write (' ' . $ line );
268
267
});
269
268
}
270
269
0 commit comments