File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Illuminate \Console \Command ;
6
6
use Illuminate \Support \Facades \Http ;
7
- use Native \Electron \Traits \CleansEnvFile ;
7
+ use Native \Laravel \ Commands \Traits \CleansEnvFile ;
8
8
use Symfony \Component \Finder \Finder ;
9
9
use ZipArchive ;
10
10
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Native \Laravel \Commands \Traits ;
4
+
5
+ trait CleansEnvFile
6
+ {
7
+ protected function prepareNativeEnv (): void
8
+ {
9
+ $ this ->line ('Preparing production .env file… ' );
10
+
11
+ $ envFile = app ()->environmentFilePath ();
12
+
13
+ if (! file_exists ($ backup = $ this ->getBackupEnvFilePath ())) {
14
+ copy ($ envFile , $ backup );
15
+ }
16
+
17
+ $ this ->cleanEnvFile ($ envFile );
18
+ }
19
+
20
+ protected function cleanEnvFile (string $ path ): void
21
+ {
22
+ $ cleanUpKeys = config ('nativephp.cleanup_env_keys ' , []);
23
+
24
+ $ contents = collect (file ($ path , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ))
25
+ ->filter (function (string $ line ) use ($ cleanUpKeys ) {
26
+ $ key = str ($ line )->before ('= ' );
27
+
28
+ return ! $ key ->is ($ cleanUpKeys )
29
+ && ! $ key ->startsWith ('# ' );
30
+ })
31
+ ->join ("\n" );
32
+
33
+ file_put_contents ($ path , $ contents );
34
+ }
35
+
36
+ protected function restoreWebEnv (): void
37
+ {
38
+ copy ($ this ->getBackupEnvFilePath (), app ()->environmentFilePath ());
39
+ unlink ($ this ->getBackupEnvFilePath ());
40
+ }
41
+
42
+ protected function getBackupEnvFilePath (): string
43
+ {
44
+ return base_path ('.env.backup ' );
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments