44
55use Illuminate \Console \Command ;
66use Illuminate \Support \Facades \File ;
7- use Illuminate \Support \Str ;
87use Symfony \Component \Process \Process ;
98use 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