-
Notifications
You must be signed in to change notification settings - Fork 119
/
CopyApplicationToBuildPath.php
146 lines (125 loc) · 3.68 KB
/
CopyApplicationToBuildPath.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace Laravel\VaporCli\BuildProcess;
use Laravel\VaporCli\ApplicationFiles;
use Laravel\VaporCli\Helpers;
use Laravel\VaporCli\Manifest;
use SplFileInfo;
class CopyApplicationToBuildPath
{
use ParticipatesInBuildProcess;
/**
* Execute the build process step.
*
* @return void
*/
public function __invoke()
{
Helpers::step('<options=bold>Copying Application Files</>');
$this->ensureBuildDirectoryExists();
foreach ($this->getApplicationFiles() as $file) {
if ($file->isLink()) {
continue;
}
$file->isDir()
? $this->createDirectoryForCopy($file)
: $this->createFileForCopy($file);
}
$this->flushCacheFiles();
$this->flushStorageDirectories();
$this->removePossibleDockerignoreFile();
}
/**
* Get the included application files.
*
* @return \Symfony\Component\Finder\Finder
*/
public function getApplicationFiles()
{
$files = ApplicationFiles::get($this->path);
if (Manifest::excludeNodeModules()) {
$files->exclude('node_modules');
}
return $files;
}
/**
* Create a directory for the application copy operation.
*
* @param \SplFileInfo $file
* @return void
*/
protected function createDirectoryForCopy(SplFileInfo $file)
{
$this->files->makeDirectory($this->appPath.'/'.$file->getRelativePathname());
}
/**
* Create a file for the application copy operation.
*
* @param \SplFileInfo $file
* @return void
*/
protected function createFileForCopy(SplFileInfo $file)
{
$this->files->copy(
$file->getRealPath(),
$this->appPath.'/'.$file->getRelativePathname()
);
$this->files->chmod(
$this->appPath.'/'.$file->getRelativePathname(),
fileperms($file->getRealPath())
);
}
/**
* Ensure that the build directory exists.
*
* @return void
*/
protected function ensureBuildDirectoryExists()
{
if ($this->files->isDirectory($this->vaporPath.'/build')) {
$this->files->deleteDirectory($this->vaporPath.'/build');
}
$this->files->makeDirectory(
$this->vaporPath.'/build/app',
0755,
true
);
}
/**
* Flush the relevant cache files from the application.
*
* @return void
*/
protected function flushCacheFiles()
{
$this->files->delete($this->appPath.'/bootstrap/cache/config.php');
$this->files->delete(
$this->files->glob(
$this->appPath.'/bootstrap/cache/routes*.php'
)
);
}
/**
* Flush the storage directories that are not needed.
*
* @return void
*/
protected function flushStorageDirectories()
{
$path = $this->buildPath.'/app';
$this->files->deleteDirectory($path.'/storage/app', true);
$this->files->deleteDirectory($path.'/storage/logs', true);
$this->files->deleteDirectory($path.'/storage/framework/cache', true);
$this->files->deleteDirectory($path.'/storage/framework/views', true);
$this->files->deleteDirectory($path.'/storage/framework/testing', true);
$this->files->deleteDirectory($path.'/storage/framework/sessions', true);
}
/**
* Delete a possible .dockerignore file that might exclude required files or directories.
*
* @return void
*/
protected function removePossibleDockerignoreFile()
{
$this->files->delete($this->appPath.'/.dockerignore');
}
}