33namespace Native \Laravel \Commands ;
44
55use Illuminate \Console \Command ;
6+ use Illuminate \Support \Str ;
7+ use Native \Laravel \Compactor \Php ;
68use Symfony \Component \Finder \Finder ;
79
810class MinifyApplicationCommand extends Command
@@ -21,7 +23,9 @@ public function handle()
2123
2224 $ this ->info ('Minifying application… ' );
2325
24- $ compactor = new \Native \Laravel \Compactor \Php ();
26+ $ this ->cleanUpEnvFile ($ appPath );
27+
28+ $ compactor = new Php ();
2529
2630 $ phpFiles = Finder::create ()
2731 ->files ()
@@ -33,4 +37,27 @@ public function handle()
3337 file_put_contents ($ phpFile ->getRealPath (), $ minifiedContent );
3438 }
3539 }
40+
41+ protected function cleanUpEnvFile (string $ appPath ): void
42+ {
43+ $ envFile = $ appPath .'/.env ' ;
44+
45+ if (! file_exists ($ envFile )) {
46+ return ;
47+ }
48+
49+ $ this ->info ('Cleaning up .env file… ' );
50+
51+ $ cleanUpKeys = config ('nativephp.cleanup_env_keys ' , []);
52+
53+ $ envContent = file_get_contents ($ envFile );
54+ $ envValues = collect (explode ("\n" , $ envContent ))
55+ ->filter (function (string $ line ) use ($ cleanUpKeys ) {
56+ $ key = Str::before ($ line , '= ' );
57+ return ! in_array ($ key , $ cleanUpKeys );
58+ })
59+ ->join ("\n" );
60+
61+ file_put_contents ($ envFile , $ envValues );
62+ }
3663}
0 commit comments