@@ -20,44 +20,43 @@ class InstallCommand extends Command
20
20
21
21
protected $ description = 'Installs the Tailwind CSS scaffolding for new Laravel applications. ' ;
22
22
23
- public function handle ()
23
+ public function handle (): int
24
24
{
25
25
$ this ->ensureTailwindConfigExists ();
26
26
$ this ->ensureTailwindCliBinaryExists ();
27
27
$ this ->appendTailwindStylesToLayouts ();
28
28
$ this ->installMiddleware ('\Tonysm\TailwindCss\Http\Middleware\AddLinkHeaderForPreloadedAssets::class ' );
29
29
$ this ->addIngoreLines ();
30
30
$ this ->runFirstBuild ();
31
- $ this ->removeUnusedFiles ();
32
31
33
32
$ this ->newLine ();
34
33
35
- $ this ->components ->info ('TailwindCSS Laravel was installed successfully. ' );
34
+ $ this ->components ->info ('Tailwind CSS Laravel was installed successfully. ' );
36
35
37
36
return self ::SUCCESS ;
38
37
}
39
38
40
- protected function phpBinary ()
39
+ protected function phpBinary (): string
41
40
{
42
- return (new PhpExecutableFinder () )->find (false ) ?: 'php ' ;
41
+ return (new PhpExecutableFinder )->find (false ) ?: 'php ' ;
43
42
}
44
43
45
- private function ensureTailwindConfigExists ()
44
+ private function ensureTailwindConfigExists (): void
46
45
{
47
46
$ this ->copyStubToApp (
48
- stub: __DIR__ . '/../../stubs/postcss.config.js ' ,
47
+ stub: __DIR__ . '/../../stubs/postcss.config.js ' ,
49
48
to: base_path ('postcss.config.js ' ),
50
49
);
51
50
52
- if (! File::exists ($ appCssFilePath = resource_path ('css/app.css ' )) || empty (trim (File::get ($ appCssFilePath ))) || $ this ->mainCssIsDefault ($ appCssFilePath )) {
51
+ if (! File::exists ($ appCssFilePath = resource_path ('css/app.css ' )) || in_array (trim (File::get ($ appCssFilePath )), [ '' , ' 0 ' ], true ) || $ this ->mainCssIsDefault ($ appCssFilePath )) {
53
52
$ this ->copyStubToApp (
54
- stub: __DIR__ . '/../../stubs/resources/css/app.css ' ,
53
+ stub: __DIR__ . '/../../stubs/resources/css/app.css ' ,
55
54
to: $ appCssFilePath ,
56
55
);
57
56
}
58
57
}
59
58
60
- private function ensureTailwindCliBinaryExists ()
59
+ private function ensureTailwindCliBinaryExists (): void
61
60
{
62
61
if (! File::exists (config ('tailwindcss.bin_path ' )) || $ this ->option ('download ' )) {
63
62
Process::forever ()->tty (SymfonyProcess::isTtySupported ())->run ([
@@ -66,7 +65,7 @@ private function ensureTailwindCliBinaryExists()
66
65
'tailwindcss:download ' ,
67
66
'--cli-version ' ,
68
67
$ this ->option ('cli-version ' ) ?: config ('tailwindcss.version ' ),
69
- ], function ($ _type , $ output ) {
68
+ ], function ($ _type , $ output ): void {
70
69
$ this ->output ->write ($ output );
71
70
});
72
71
}
@@ -81,12 +80,9 @@ private function copyStubToApp(string $stub, string $to): void
81
80
/**
82
81
* Install the middleware to a group in the application Http Kernel.
83
82
*
84
- * @param string $after
85
- * @param string $name
86
83
* @param string $group
87
- * @return void
88
84
*/
89
- private function installMiddlewareAfter ($ after , $ name , $ group = 'web ' )
85
+ private function installMiddlewareAfter (string $ after , string $ name , $ group = 'web ' ): void
90
86
{
91
87
$ httpKernel = file_get_contents (app_path ('Http/Kernel.php ' ));
92
88
@@ -98,8 +94,8 @@ private function installMiddlewareAfter($after, $name, $group = 'web')
98
94
}
99
95
100
96
$ modifiedMiddlewareGroup = str_replace (
101
- $ after . ', ' ,
102
- $ after . ', ' . PHP_EOL . ' ' . $ name . ', ' ,
97
+ $ after. ', ' ,
98
+ $ after. ', ' . PHP_EOL . ' ' . $ name. ', ' ,
103
99
$ middlewareGroup ,
104
100
);
105
101
@@ -110,12 +106,12 @@ private function installMiddlewareAfter($after, $name, $group = 'web')
110
106
));
111
107
}
112
108
113
- private function appendTailwindStylesToLayouts ()
109
+ private function appendTailwindStylesToLayouts (): void
114
110
{
115
111
$ this ->existingLayoutFiles ()
116
112
->each (fn ($ file ) => File::put (
117
113
$ file ,
118
- (new AppendTailwindTag () )(File::get ($ file )),
114
+ (new AppendTailwindTag )(File::get ($ file )),
119
115
));
120
116
}
121
117
@@ -126,7 +122,7 @@ private function existingLayoutFiles()
126
122
->filter (fn ($ file ) => File::exists ($ file ));
127
123
}
128
124
129
- private function installMiddleware (string $ middleware )
125
+ private function installMiddleware (string $ middleware ): void
130
126
{
131
127
if (file_exists (app_path ('Http/Kernel.php ' ))) {
132
128
$ this ->installMiddlewareAfter ('SubstituteBindings::class ' , $ middleware );
@@ -135,7 +131,7 @@ private function installMiddleware(string $middleware)
135
131
}
136
132
}
137
133
138
- private function installMiddlewareToBootstrap (string $ middleware , string $ group = 'web ' , string $ modifier = 'append ' )
134
+ private function installMiddlewareToBootstrap (string $ middleware , string $ group = 'web ' , string $ modifier = 'append ' ): void
139
135
{
140
136
$ bootstrapApp = file_get_contents (base_path ('bootstrap/app.php ' ));
141
137
@@ -146,19 +142,19 @@ private function installMiddlewareToBootstrap(string $middleware, string $group
146
142
$ bootstrapApp = str_replace (
147
143
'->withMiddleware(function (Middleware $middleware) { ' ,
148
144
'->withMiddleware(function (Middleware $middleware) { '
149
- . PHP_EOL . " \$middleware-> {$ group }( {$ modifier }: [ "
150
- . PHP_EOL . " {$ middleware }, "
151
- . PHP_EOL . ' ]); '
152
- . PHP_EOL ,
145
+ .PHP_EOL . " \$middleware-> {$ group }( {$ modifier }: [ "
146
+ .PHP_EOL . " {$ middleware }, "
147
+ .PHP_EOL . ' ]); '
148
+ .PHP_EOL ,
153
149
$ bootstrapApp ,
154
150
);
155
151
156
152
file_put_contents (base_path ('bootstrap/app.php ' ), $ bootstrapApp );
157
153
}
158
154
159
- private function addIngoreLines ()
155
+ private function addIngoreLines (): void
160
156
{
161
- $ binary = basename (config ('tailwindcss.bin_path ' ));
157
+ $ binary = basename (( string ) config ('tailwindcss.bin_path ' ));
162
158
163
159
if (str_contains (File::get (base_path ('.gitignore ' )), $ binary )) {
164
160
return ;
@@ -173,28 +169,17 @@ private function addIngoreLines()
173
169
LINES );
174
170
}
175
171
176
- private function runFirstBuild ()
172
+ private function runFirstBuild (): void
177
173
{
178
174
Process::forever ()->tty (SymfonyProcess::isTtySupported ())->run ([
179
175
$ this ->phpBinary (),
180
176
'artisan ' ,
181
177
'tailwindcss:build ' ,
182
- ], function ($ _type , $ output ) {
178
+ ], function ($ _type , $ output ): void {
183
179
$ this ->output ->write ($ output );
184
180
});
185
181
}
186
182
187
- private function removeUnusedFiles ()
188
- {
189
- $ files = [
190
- base_path ('tailwind.config.js ' ),
191
- ];
192
-
193
- foreach ($ files as $ file ) {
194
- File::exists ($ file ) && File::delete ($ file );
195
- }
196
- }
197
-
198
183
private function mainCssIsDefault ($ appCssFilePath ): bool
199
184
{
200
185
return trim (File::get ($ appCssFilePath )) === trim (<<<'CSS'
0 commit comments