22
33namespace Native \Electron \Traits ;
44
5- use Illuminate \Contracts \Process \ProcessResult ;
65use Illuminate \Support \Collection ;
76use Illuminate \Support \Facades \Process ;
87
@@ -15,72 +14,49 @@ trait HasPreAndPostProcessing
1514{
1615 public function preProcess (): void
1716 {
18- $ config = $ this -> getPrePostBuildConfig ( ' prebuild ' );
17+ $ config = collect ( config ( ' nativephp. prebuild ') );
1918
20- if (! $ config instanceof Collection ) {
19+ if ($ config-> isEmpty () ) {
2120 return ;
2221 }
2322
2423 intro ('Running pre-process commands... ' );
2524
26- $ config -> each ( $ this ->getProcessCallback () );
25+ $ this ->runProcess ( $ config );
2726
2827 outro ('Pre-process commands completed. ' );
2928 }
3029
3130 public function postProcess (): void
3231 {
33- $ config = $ this -> getPrePostBuildConfig ( ' postbuild ' );
32+ $ config = collect ( config ( ' nativephp. postbuild ') );
3433
35- if (! $ config instanceof Collection ) {
34+ if ($ config-> isEmpty () ) {
3635 return ;
3736 }
3837
3938 intro ('Running post-process commands... ' );
4039
41- $ config -> each ( $ this ->getProcessCallback () );
40+ $ this ->runProcess ( $ config );
4241
4342 outro ('Post-process commands completed. ' );
4443 }
4544
46- private function formatConfigKey ( string $ configKey ): string
45+ private function runProcess ( Collection $ configCommands ): void
4746 {
48- return sprintf ('nativephp.%s ' , $ configKey );
49- }
50-
51- private function executeCommand (mixed $ command ): ProcessResult
52- {
53- return Process::path (base_path ())
54- ->timeout (300 )
55- ->tty (\Symfony \Component \Process \Process::isTtySupported ())
56- ->run ($ command , function (string $ type , string $ output ) {
57- echo $ output ;
58- });
59- }
60-
61- protected function getPrePostBuildConfig (string $ configKey ): mixed
62- {
63- $ config = config ($ this ->formatConfigKey ($ configKey ));
64-
65- if (is_array ($ config )) {
66- // Filter out empty values
67- return collect ($ config )
68- ->filter (fn ($ value ) => ! empty ($ value ));
69- }
70-
71- return $ config ;
72- }
73-
74- private function getProcessCallback (): callable
75- {
76- return function ($ command ) {
47+ $ configCommands ->each (function ($ command ) {
7748 note ("Running command: {$ command }" );
7849
7950 if (is_array ($ command )) {
8051 $ command = implode (' && ' , $ command );
8152 }
8253
83- $ result = $ this ->executeCommand ($ command );
54+ $ result = Process::path (base_path ())
55+ ->timeout (300 )
56+ ->tty (\Symfony \Component \Process \Process::isTtySupported ())
57+ ->run ($ command , function (string $ type , string $ output ) {
58+ echo $ output ;
59+ });
8460
8561 if (! $ result ->successful ()) {
8662 error ("Command failed: {$ command }" );
@@ -89,6 +65,6 @@ private function getProcessCallback(): callable
8965 }
9066
9167 note ("Command successful: {$ command }" );
92- };
68+ }) ;
9369 }
9470}
0 commit comments