-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathSetBuildEnvironment.php
86 lines (70 loc) · 2.02 KB
/
SetBuildEnvironment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Laravel\VaporCli\BuildProcess;
use Illuminate\Filesystem\Filesystem;
use Laravel\VaporCli\Helpers;
use Laravel\VaporCli\Path;
class SetBuildEnvironment
{
use ParticipatesInBuildProcess;
/**
* The asset base URL.
*/
protected $assetUrl;
/**
* Create a new project builder.
*
* @param string|null $environment
* @param string|null $assetUrl
* @return void
*/
public function __construct($environment = null, $assetUrl = null)
{
$this->assetUrl = $assetUrl;
$this->environment = $environment;
$this->appPath = Path::app();
$this->path = Path::current();
$this->vaporPath = Path::vapor();
$this->buildPath = Path::build();
$this->files = new Filesystem();
}
/**
* Execute the build process step.
*
* @return void
*/
public function __invoke()
{
Helpers::step('<options=bold>Setting Build Environment</>');
if (! file_exists($envPath = $this->appPath.'/.env')) {
$this->files->put($envPath, '');
}
if (file_exists($this->appPath.'/.env.'.$this->environment)) {
$this->files->copy(
$this->appPath.'/.env.'.$this->environment,
$envPath
);
$this->files->delete($this->appPath.'/.env.'.$this->environment);
}
$this->files->prepend(
$envPath,
'APP_ENV='.$this->environment.PHP_EOL
);
// Mix takes the last environment variable value...
$this->files->append(
$envPath,
PHP_EOL.'APP_ENV='.$this->environment.PHP_EOL
);
$this->files->append(
$envPath,
'ASSET_URL='.$this->assetUrl.PHP_EOL
);
$this->files->append(
$envPath,
'MIX_VAPOR_ASSET_URL='.$this->assetUrl.PHP_EOL
);
$this->files->append(
$envPath,
'VITE_VAPOR_ASSET_URL='.$this->assetUrl.PHP_EOL
);
}
}