Skip to content

V4 Upgrade #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/tailwindcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
| @see https://github.com/tailwindlabs/tailwindcss/releases to know the version availables.
|
*/
'version' => env('TAILWINDCSS_CLI_VERSION', 'v3.4.9'),
'version' => env('TAILWINDCSS_CLI_VERSION', 'v4.0.0'),
];
34 changes: 17 additions & 17 deletions src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function handle()
$sourcePath = $this->fixFilePathForOs(config('tailwindcss.build.source_file_path'));
$sourceRelativePath = str_replace(rtrim(resource_path(), DIRECTORY_SEPARATOR), '', $sourcePath);
$destinationPath = $this->fixFilePathForOs(config('tailwindcss.build.destination_path'));
$destinationFileAbsolutePath = $destinationPath.DIRECTORY_SEPARATOR.trim($sourceRelativePath, DIRECTORY_SEPARATOR);
$destinationFileAbsolutePath = $destinationPath . DIRECTORY_SEPARATOR . trim($sourceRelativePath, DIRECTORY_SEPARATOR);
$destinationFileRelativePath = str_replace(rtrim(public_path(), DIRECTORY_SEPARATOR), '', $destinationFileAbsolutePath);

File::ensureDirectoryExists(dirname($destinationFileAbsolutePath));
Expand All @@ -55,7 +55,7 @@ public function handle()
$binFile,
'-i', $sourcePath,
'-o', $destinationFileAbsolutePath,
$this->option('watch') ? '-w' : null,
$this->option('watch') ? '--watch=always' : null,
$this->shouldMinify() ? '-m' : null,
]), function ($type, $output) {
$this->output->write($output);
Expand All @@ -79,6 +79,21 @@ public function handle()
return self::SUCCESS;
}

protected function ensureAssetIsVersioned(string $generatedFile): string
{
$digest = sha1_file($generatedFile);

$versionedFile = preg_replace(
'/(\.css)$/',
sprintf('-%s$1', $digest),
$generatedFile,
);

File::move($generatedFile, $versionedFile);

return $versionedFile;
}

private function fixFilePathForOs(string $path): string
{
return str_replace('/', DIRECTORY_SEPARATOR, $path);
Expand All @@ -98,19 +113,4 @@ private function shouldMinify(): bool
{
return $this->option('minify') || $this->option('prod');
}

protected function ensureAssetIsVersioned(string $generatedFile): string
{
$digest = sha1_file($generatedFile);

$versionedFile = preg_replace(
'/(\.css)$/',
sprintf('-%s$1', $digest),
$generatedFile,
);

File::move($generatedFile, $versionedFile);

return $versionedFile;
}
}
2 changes: 2 additions & 0 deletions src/Commands/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class DownloadCommand extends Command

public function handle()
{
ini_set('memory_limit', '1024M');

$os = php_uname('s');
$cpu = php_uname('m');

Expand Down
30 changes: 15 additions & 15 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ public function handle()
return self::SUCCESS;
}

protected function phpBinary()
{
return (new PhpExecutableFinder())->find(false) ?: 'php';
}

private function ensureTailwindConfigExists()
{
$this->copyStubToApp(
stub: __DIR__.'/../../stubs/tailwind.config.js',
to: base_path('tailwind.config.js'),
stub: __DIR__ . '/../../stubs/postcss.config.js',
to: base_path('postcss.config.js'),
);

if (! File::exists($appCssFilePath = resource_path('css/app.css')) || empty(trim(File::get($appCssFilePath)))) {
$this->copyStubToApp(
stub: __DIR__.'/../../stubs/resources/css/app.css',
stub: __DIR__ . '/../../stubs/resources/css/app.css',
to: $appCssFilePath,
);
}
Expand Down Expand Up @@ -85,15 +90,15 @@ private function installMiddlewareAfter($after, $name, $group = 'web')
$httpKernel = file_get_contents(app_path('Http/Kernel.php'));

$middlewareGroups = Str::before(Str::after($httpKernel, '$middlewareGroups = ['), '];');
$middlewareGroup = Str::before(Str::after($middlewareGroups, "'$group' => ["), '],');
$middlewareGroup = Str::before(Str::after($middlewareGroups, "'{$group}' => ["), '],');

if (str_contains($middlewareGroup, $name)) {
return;
}

$modifiedMiddlewareGroup = str_replace(
$after.',',
$after.','.PHP_EOL.' '.$name.',',
$after . ',',
$after . ',' . PHP_EOL . ' ' . $name . ',',
$middlewareGroup,
);

Expand Down Expand Up @@ -140,10 +145,10 @@ private function installMiddlewareToBootstrap(string $middleware, string $group
$bootstrapApp = str_replace(
'->withMiddleware(function (Middleware $middleware) {',
'->withMiddleware(function (Middleware $middleware) {'
.PHP_EOL." \$middleware->$group($modifier: ["
.PHP_EOL." $middleware,"
.PHP_EOL.' ]);'
.PHP_EOL,
. PHP_EOL . " \$middleware->{$group}({$modifier}: ["
. PHP_EOL . " {$middleware},"
. PHP_EOL . ' ]);'
. PHP_EOL,
$bootstrapApp,
);

Expand Down Expand Up @@ -177,9 +182,4 @@ private function runFirstBuild()
$this->output->write($output);
});
}

protected function phpBinary()
{
return (new PhpExecutableFinder())->find(false) ?: 'php';
}
}
5 changes: 5 additions & 0 deletions stubs/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};
5 changes: 2 additions & 3 deletions stubs/resources/css/app.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
@import "tailwindcss";

21 changes: 0 additions & 21 deletions stubs/tailwind.config.js

This file was deleted.

Loading