Skip to content

Commit c552035

Browse files
committed
fix: transfert CleansEnvFile to this repo
nativephp/electron requires this repo, not the other way around
1 parent d066745 commit c552035

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/Commands/BundleCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Facades\Http;
7-
use Native\Electron\Traits\CleansEnvFile;
7+
use Native\Laravel\Commands\Traits\CleansEnvFile;
88
use Symfony\Component\Finder\Finder;
99
use ZipArchive;
1010

src/Commands/Traits/CleansEnvFile.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
 (0)