17
17
*/
18
18
class ComposerGenerator
19
19
{
20
+ /**
21
+ * Types of supported Magento component packages
22
+ */
23
+ private const COMPONENT_PACKAGE_TYPES = [
24
+ 'magento2-module ' ,
25
+ 'magento2-theme ' ,
26
+ 'magento2-language ' ,
27
+ 'magento2-library '
28
+ ];
29
+
20
30
/**
21
31
* @var DirectoryList
22
32
*/
@@ -81,10 +91,13 @@ public function generate(array $repoOptions): array
81
91
$ baseRepoFolder = $ this ->directoryList ->getMagentoRoot () . '/ ' . $ repoDir ;
82
92
83
93
$ dirComposerJson = $ baseRepoFolder . '/composer.json ' ;
94
+ $ isModuleRoot = false ;
84
95
if ($ this ->file ->isExists ($ dirComposerJson )) {
85
96
$ dirPackageInfo = json_decode ($ this ->file ->fileGetContents ($ dirComposerJson ), true );
86
- if (isset ($ dirPackageInfo[ ' type ' ]) && $ dirPackageInfo [ ' type ' ] == ' project ' ) {
97
+ if ($ this -> isProjectPackage ($ dirPackageInfo) ) {
87
98
$ composer ['require ' ] = array_merge ($ composer ['require ' ], $ dirPackageInfo ['require ' ]);
99
+ } elseif ($ this ->isComponentPackage ($ dirPackageInfo )) {
100
+ $ isModuleRoot = true ;
88
101
}
89
102
}
90
103
@@ -99,12 +112,16 @@ public function generate(array $repoOptions): array
99
112
];
100
113
$ composer ['require ' ][$ packageName ] = '*@dev ' ;
101
114
}
102
- $ excludeRepoStr = empty ($ repoPackages ) ? '' : "--exclude=' " . join ("' --exclude=' " , $ repoPackages ) . "' " ;
103
- $ preparePackagesScripts [] = sprintf (
104
- "rsync -azhm --stats $ excludeRepoStr--exclude='dev/tests' --exclude='.git' " .
105
- "--exclude='composer.json' --exclude='composer.lock' ./%s/ ./ " ,
106
- $ repoDir
107
- );
115
+ if (!$ isModuleRoot ) {
116
+ $ excludeRepoStr = empty ($ repoPackages )
117
+ ? ''
118
+ : "--exclude=' " . join ("' --exclude=' " , $ repoPackages ) . "' " ;
119
+ $ preparePackagesScripts [] = sprintf (
120
+ "rsync -azhm --stats $ excludeRepoStr--exclude='dev/tests' --exclude='.git' " .
121
+ "--exclude='composer.json' --exclude='composer.lock' ./%s/ ./ " ,
122
+ $ repoDir
123
+ );
124
+ }
108
125
}
109
126
$ composer ['scripts ' ]['prepare-packages ' ] = $ preparePackagesScripts ;
110
127
$ composer ['scripts ' ]['post-install-cmd ' ] = ['@prepare-packages ' ];
@@ -208,7 +225,6 @@ private function getBaseComposer(array $repoOptions): array
208
225
private function findPackages (string $ path )
209
226
{
210
227
$ path = rtrim ($ path , '\\/ ' );
211
- $ packageTypes = ['magento2-module ' , 'magento2-theme ' , 'magento2-language ' , 'magento2-library ' ];
212
228
$ pathLength = strlen ($ path . '/ ' );
213
229
214
230
$ dirIterator = $ this ->file ->getRecursiveFileIterator (
@@ -219,11 +235,33 @@ private function findPackages(string $path)
219
235
$ packages = [];
220
236
foreach ($ dirIterator as $ currentFileInfo ) {
221
237
$ packageInfo = json_decode ($ this ->file ->fileGetContents ($ currentFileInfo ->getPathName ()), true );
222
- if (isset ( $ packageInfo [ ' type ' ]) && in_array ($ packageInfo[ ' type ' ], $ packageTypes )) {
238
+ if ($ this -> isComponentPackage ($ packageInfo )) {
223
239
$ packages [$ packageInfo ['name ' ]] = substr ($ currentFileInfo ->getPath (), $ pathLength );
224
240
}
225
241
}
226
242
227
243
return $ packages ;
228
244
}
245
+
246
+ /**
247
+ * Check if provided package info belongs to a Magento component package
248
+ *
249
+ * @param array $packageInfo
250
+ * @return bool
251
+ */
252
+ private function isComponentPackage (array $ packageInfo ): bool
253
+ {
254
+ return isset ($ packageInfo ['type ' ]) && in_array ($ packageInfo ['type ' ], self ::COMPONENT_PACKAGE_TYPES );
255
+ }
256
+
257
+ /**
258
+ * Check if provided package info belongs to a Magento project package
259
+ *
260
+ * @param array $packageInfo
261
+ * @return bool
262
+ */
263
+ private function isProjectPackage (array $ packageInfo ): bool
264
+ {
265
+ return isset ($ packageInfo ['type ' ]) && $ packageInfo ['type ' ] == 'project ' ;
266
+ }
229
267
}
0 commit comments