@@ -34,13 +34,6 @@ class CopyWordPressFilesStep implements BuildStepInterface
3434 */
3535 private $ filesystem ;
3636
37- /**
38- * The Ymir project configuration.
39- *
40- * @var ProjectConfiguration
41- */
42- private $ projectConfiguration ;
43-
4437 /**
4538 * The project directory where the project files are copied from.
4639 *
@@ -51,14 +44,44 @@ class CopyWordPressFilesStep implements BuildStepInterface
5144 /**
5245 * Constructor.
5346 */
54- public function __construct (string $ buildDirectory , ProjectConfiguration $ projectConfiguration , string $ projectDirectory, Filesystem $ filesystem )
47+ public function __construct (string $ buildDirectory , Filesystem $ filesystem , string $ projectDirectory )
5548 {
5649 $ this ->buildDirectory = rtrim ($ buildDirectory , '/ ' );
5750 $ this ->filesystem = $ filesystem ;
58- $ this ->projectConfiguration = $ projectConfiguration ;
5951 $ this ->projectDirectory = rtrim ($ projectDirectory , '/ ' );
6052 }
6153
54+ /**
55+ * List of files we need to append manually because they're in the default Bedrock .gitignore file.
56+ */
57+ public function getBedrockFilesToAppend (): array
58+ {
59+ // Need the .env file for WP-CLI to work during the build
60+ $ files = [new SplFileInfo ($ this ->projectDirectory .'/.env ' , $ this ->projectDirectory , '/.env ' )];
61+
62+ // Finder can't seem to honor the .gitignore path ignoring child folders in the mu-plugins
63+ // folder while keeping the files at the root of the mu-plugins folder.
64+ $ finder = Finder::create ()->in ($ this ->projectDirectory )
65+ ->path ('/^web\/app\/mu-plugins/ ' )
66+ ->depth ('== 3 ' )
67+ ->files ();
68+
69+ foreach ($ finder as $ file ) {
70+ $ files [] = $ file ;
71+ }
72+
73+ // TODO: Remove once we can install with Composer
74+ $ finder = Finder::create ()->in ($ this ->projectDirectory )
75+ ->path ('/^web\/app\/plugins\/ymir/ ' )
76+ ->files ();
77+
78+ foreach ($ finder as $ file ) {
79+ $ files [] = $ file ;
80+ }
81+
82+ return $ files ;
83+ }
84+
6285 /**
6386 * {@inheritdoc}
6487 */
@@ -70,15 +93,15 @@ public function getDescription(): string
7093 /**
7194 * {@inheritdoc}
7295 */
73- public function perform (string $ environment )
96+ public function perform (string $ environment, ProjectConfiguration $ projectConfiguration )
7497 {
7598 if ($ this ->filesystem ->exists ($ this ->buildDirectory )) {
7699 $ this ->filesystem ->remove ($ this ->buildDirectory );
77100 }
78101
79102 $ this ->filesystem ->mkdir ($ this ->buildDirectory , 0755 );
80103
81- foreach ($ this ->getProjectFiles () as $ file ) {
104+ foreach ($ this ->getProjectFiles ($ projectConfiguration -> getProjectType () ) as $ file ) {
82105 $ this ->copyFile ($ file );
83106 }
84107 }
@@ -98,7 +121,7 @@ private function copyFile(SplFileInfo $file)
98121 /**
99122 * Get the Finder object for finding all the project files.
100123 */
101- private function getProjectFiles (): Finder
124+ private function getProjectFiles (string $ projectType ): Finder
102125 {
103126 $ finder = Finder::create ()
104127 ->in ($ this ->projectDirectory )
@@ -107,14 +130,16 @@ private function getProjectFiles(): Finder
107130 ->followLinks ()
108131 ->ignoreVcs (true )
109132 ->ignoreDotFiles (false );
110- $ projectType = $ this ->projectConfiguration ->getProjectType ();
111133
112134 if (is_readable ($ this ->projectDirectory .'/.gitignore ' )) {
113135 $ finder ->ignoreVCSIgnored (true );
114136 }
115137
116138 if ('wordpress ' === $ projectType ) {
117139 $ finder ->exclude ('wp-content/uploads ' );
140+ } elseif ('bedrock ' === $ projectType ) {
141+ $ finder ->exclude ('web/app/uploads ' );
142+ $ finder ->append ($ this ->getBedrockFilesToAppend ());
118143 }
119144
120145 return $ finder ;
0 commit comments