Skip to content

Commit 2f1bdcd

Browse files
committed
Fix build on Windows systems
1 parent d331580 commit 2f1bdcd

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

config/tailwindcss.php

Lines changed: 1 addition & 1 deletion
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

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');

0 commit comments

Comments
 (0)