@@ -88,7 +88,7 @@ public function copyToBuildDirectory(): bool
8888 }
8989
9090 $ this ->keepRequiredDirectories ();
91- $ this ->keepLivewireDispatcher ();
91+ $ this ->copyIncludedFiles ();
9292
9393 return true ;
9494 }
@@ -108,16 +108,45 @@ private function keepRequiredDirectories()
108108 $ filesystem ->dumpFile ("{$ buildPath }/storage/logs/_native.json " , '{} ' );
109109 }
110110
111- private function keepLivewireDispatcher ()
111+ private function copyIncludedFiles (): void
112112 {
113- // This is a bit leaky, since we only need this for electron, not potential other drivers
114- // We'll find a better place for it when we add more drivers.
115- $ dispatcherPath = ' vendor/nativephp/desktop/resources/electron/electron-plugin/src/preload/livewire-dispatcher.js ' ;
113+
114+ $ sourcePath = $ this -> sourcePath ();
115+ $ buildPath = $ this -> buildPath ( ' app ' ) ;
116116 $ filesystem = new Filesystem ;
117117
118- $ filesystem -> copy (
119- $ this -> sourcePath ( $ dispatcherPath ),
120- $ this -> buildPath ( " app/ { $ dispatcherPath }" )
118+ $ patterns = array_merge (
119+ config ( ' nativephp-internal.cleanup_include_files ' , [] ),
120+ config ( ' nativephp.cleanup_include_files ' , []),
121121 );
122+
123+ foreach ($ patterns as $ pattern ) {
124+ $ matchingFiles = glob ($ sourcePath . '/ ' . $ pattern , GLOB_BRACE );
125+
126+ foreach ($ matchingFiles as $ sourceFile ) {
127+ $ relativePath = substr ($ sourceFile , strlen ($ sourcePath ) + 1 );
128+ $ targetFile = $ buildPath . '/ ' . $ relativePath ;
129+
130+ // Create target directory if it doesn't exist
131+ $ targetDir = dirname ($ targetFile );
132+ if (!is_dir ($ targetDir )) {
133+ $ filesystem ->mkdir ($ targetDir , 0755 );
134+ }
135+
136+ // Copy the file
137+ if (is_file ($ sourceFile )) {
138+ copy ($ sourceFile , $ targetFile );
139+
140+ // Preserve permissions on non-Windows systems
141+ if (PHP_OS_FAMILY !== 'Windows ' ) {
142+ $ perms = fileperms ($ sourceFile );
143+ if ($ perms !== false ) {
144+ chmod ($ targetFile , $ perms );
145+ }
146+ }
147+ }
148+ }
149+ }
122150 }
151+
123152}
0 commit comments