Skip to content

Commit 7a7c8cb

Browse files
authored
Merge pull request #5 from tonysm/fix-windows
Fix windows
2 parents d331580 + eec087d commit 7a7c8cb

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

config/tailwindcss.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
'build' => [
1515
'source_file_path' => resource_path('css/app.css'),
16-
'destination_file_path' => public_path('dist/css/app.css'),
16+
'destination_path' => public_path('dist'),
1717
'manifest_file_path' => public_path('.tailwindcss-manifest.json'),
1818
],
1919

@@ -27,7 +27,7 @@
2727
| Use the `tailwindcss:download` Artisan command to ensure the binary is there.
2828
|
2929
*/
30-
'bin_path' => base_path('tailwindcss'),
30+
'bin_path' => PHP_OS === 'WINNT' ? base_path('tailwindcss.exe') : base_path('tailwindcss'),
3131

3232
/*
3333
|---------------------------------------------------------------------

src/Commands/BuildCommand.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Facades\File;
7-
use Illuminate\Support\Str;
87
use Symfony\Component\Process\Process;
98
use Tonysm\TailwindCss\Manifest;
109

@@ -31,23 +30,26 @@ public function handle()
3130

3231
$this->info('Building assets...');
3332

34-
$generatedFile = config('tailwindcss.build.destination_file_path');
35-
$generatedFileRelativePath = Str::after($generatedFile, rtrim(public_path(), '/'));
33+
$sourcePath = $this->fixFilePathForOs(config('tailwindcss.build.source_file_path'));
34+
$sourceRelativePath = str_replace(rtrim(resource_path(), DIRECTORY_SEPARATOR), '', $sourcePath);
35+
$destinationPath = $this->fixFilePathForOs(config('tailwindcss.build.destination_path'));
36+
$destinationFileAbsolutePath = $destinationPath . DIRECTORY_SEPARATOR . trim($sourceRelativePath, DIRECTORY_SEPARATOR);
37+
$destinationFileRelativePath = str_replace(rtrim(public_path(), DIRECTORY_SEPARATOR), '', $destinationFileAbsolutePath);
3638

37-
File::ensureDirectoryExists(dirname($generatedFile));
38-
File::cleanDirectory(dirname($generatedFile));
39+
File::ensureDirectoryExists(dirname($destinationFileAbsolutePath));
40+
File::cleanDirectory(dirname($destinationFileAbsolutePath));
3941

4042
if ($this->option('watch') || ! $this->shouldVersion()) {
4143
// Ensure there is at least one mix-manifest.json that points to the unversioned asset...
4244
File::put(Manifest::path(), json_encode([
43-
'/css/app.css' => $generatedFileRelativePath,
45+
$this->fixOsFilePathToUriPath($sourceRelativePath) => $this->fixOsFilePathToUriPath($destinationFileRelativePath),
4446
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
4547
}
4648

4749
$process = new Process(array_filter([
4850
$binFile,
49-
'-i', config('tailwindcss.build.source_file_path'),
50-
'-o', $generatedFile,
51+
'-i', $sourcePath,
52+
'-o', $destinationFileAbsolutePath,
5153
$this->option('watch') ? '-w' : null,
5254
$this->shouldMinify() ? '-m' : null,
5355
]), timeout: null);
@@ -59,14 +61,15 @@ public function handle()
5961
});
6062

6163
if ($this->shouldVersion()) {
62-
$generatedFile = $this->ensureAssetIsVersioned($generatedFile);
64+
$destinationFileAbsolutePath = $this->ensureAssetIsVersioned($destinationFileAbsolutePath);
65+
$destinationFileRelativePath = str_replace(rtrim(public_path(), DIRECTORY_SEPARATOR), '', $destinationFileAbsolutePath);
6366
}
6467

6568
if (! $this->option('watch') && $this->shouldVersion()) {
6669
$this->info(sprintf('Generating the versioned %s file...', Manifest::filename()));
6770

6871
File::put(Manifest::path(), json_encode([
69-
'/css/app.css' => Str::after($generatedFile, rtrim(dirname(Manifest::path()), '/')),
72+
$this->fixOsFilePathToUriPath($sourceRelativePath) => $this->fixOsFilePathToUriPath($destinationFileRelativePath),
7073
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
7174
}
7275

@@ -75,6 +78,16 @@ public function handle()
7578
return self::SUCCESS;
7679
}
7780

81+
private function fixFilePathForOs(string $path): string
82+
{
83+
return str_replace('/', DIRECTORY_SEPARATOR, $path);
84+
}
85+
86+
private function fixOsFilePathToUriPath(string $path): string
87+
{
88+
return str_replace(DIRECTORY_SEPARATOR, '/', $path);
89+
}
90+
7891
private function shouldVersion(): bool
7992
{
8093
return $this->option('digest') || $this->option('prod');

src/Commands/DownloadCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
class DownloadCommand extends Command
1010
{
11-
protected $signature = 'tailwindcss:download {--force : If the file already exists, we will not touch it. Use this flag if you want to replace it with a new version.}';
11+
protected $signature = 'tailwindcss:download
12+
{--force : If the file already exists, we will not touch it. Use this flag if you want to replace it with a new version.}
13+
{--timeout=600 : Timeout in seconds. Defaults to 5 mins (600s).}
14+
';
15+
1216
protected $description = 'Downloads the Tailwind CSS binary for the version specified in your config/tailwindcss.php.';
1317

1418
public function handle()
@@ -21,6 +25,7 @@ public function handle()
2125
'Linux-aarch64' => 'tailwindcss-linux-arm64',
2226
'Darwin-arm64' => 'tailwindcss-macos-arm64',
2327
'Darwin-x86_64' => 'tailwindcss-macos-x64',
28+
'Windows NT-AMD64' => 'tailwindcss-windows-x64.exe',
2429
];
2530

2631
if (! $targetArchitecture = ($architectureToBinary["{$os}-{$cpu}"] ?? false)) {
@@ -40,7 +45,8 @@ public function handle()
4045

4146
$this->info(sprintf('Downloading the Tailwind CSS binary (%s/%s/%s)...', $os, $cpu, $targetVersion));
4247

43-
$contents = Http::get($this->downloadUrl($targetArchitecture, $targetVersion))
48+
$contents = Http::timeout($this->option('timeout'))
49+
->get($this->downloadUrl($targetArchitecture, $targetVersion))
4450
->throw()
4551
->body();
4652

0 commit comments

Comments
 (0)