@@ -18,6 +18,11 @@ class ComposerGenerator
18
18
{
19
19
const REPO_TYPE_SINGLE_PACKAGE = 'single-package ' ;
20
20
21
+ /**
22
+ * Type for packages with modules in the root directory such as Inventory
23
+ */
24
+ const REPO_TYPE_FLAT_STRUCTURE = 'flat-structure ' ;
25
+
21
26
/**
22
27
* @var DirectoryList
23
28
*/
@@ -128,7 +133,7 @@ private function getBaseComposer(array $repoOptions): array
128
133
$ preparePackagesScripts = [];
129
134
130
135
foreach ($ repoOptions as $ repoName => $ gitOption ) {
131
- if ($ this ->isSinglePackage ($ gitOption )) {
136
+ if ($ this ->isSinglePackage ($ gitOption ) || $ this -> isFlatStructurePackage ( $ gitOption ) ) {
132
137
continue ;
133
138
}
134
139
@@ -204,51 +209,68 @@ private function getBaseComposer(array $repoOptions): array
204
209
* @param array $composer
205
210
* @return array
206
211
* @codeCoverageIgnore
212
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
207
213
*/
208
214
private function addModules (array $ repoOptions , array $ composer ): array
209
215
{
210
- $ add = function ($ dir , $ version = null ) use (&$ composer ) {
211
- if (!$ this ->file ->isExists ($ dir . '/composer.json ' )) {
212
- return 0 ;
213
- }
214
-
215
- $ dirComposer = json_decode ($ this ->file ->fileGetContents ($ dir . '/composer.json ' ), true );
216
- $ composer ['repositories ' ][$ dirComposer ['name ' ]] = [
217
- 'type ' => 'path ' ,
218
- 'url ' => ltrim (str_replace ($ this ->directoryList ->getMagentoRoot (), '' , $ dir ), '/ ' ),
219
- 'options ' => [
220
- 'symlink ' => false ,
221
- ],
222
- ];
223
- $ composer ['require ' ][$ dirComposer ['name ' ]] = $ version ?? $ dirComposer ['version ' ] ?? '* ' ;
224
- };
225
-
226
216
foreach ($ repoOptions as $ repoName => $ gitOption ) {
227
217
$ baseRepoFolder = $ this ->directoryList ->getMagentoRoot () . '/ ' . $ repoName ;
228
218
if ($ this ->isSinglePackage ($ gitOption )) {
229
- $ add ($ baseRepoFolder , '* ' );
219
+ $ this ->addModule ($ baseRepoFolder , $ composer , '* ' );
220
+ continue ;
221
+ }
222
+
223
+ if ($ this ->isFlatStructurePackage ($ gitOption )) {
224
+ foreach (glob ($ baseRepoFolder . '/* ' ) as $ dir ) {
225
+ $ this ->addModule ($ dir , $ composer );
226
+ }
230
227
continue ;
231
228
}
232
229
233
230
foreach (glob ($ baseRepoFolder . '/app/code/Magento/* ' ) as $ dir ) {
234
- $ add ($ dir );
231
+ $ this -> addModule ($ dir, $ composer );
235
232
}
236
233
foreach (glob ($ baseRepoFolder . '/app/design/*/Magento/*/ ' ) as $ dir ) {
237
- $ add ($ dir );
234
+ $ this -> addModule ($ dir, $ composer );
238
235
}
239
236
foreach (glob ($ baseRepoFolder . '/app/design/*/Magento/*/ ' ) as $ dir ) {
240
- $ add ($ dir );
237
+ $ this -> addModule ($ dir, $ composer );
241
238
}
242
239
if ($ this ->file ->isDirectory ($ baseRepoFolder . '/lib/internal/Magento/Framework/ ' )) {
243
240
foreach (glob ($ baseRepoFolder . '/lib/internal/Magento/Framework/* ' ) as $ dir ) {
244
- $ add ($ dir );
241
+ $ this -> addModule ($ dir, $ composer );
245
242
}
246
243
}
247
244
}
248
245
249
246
return $ composer ;
250
247
}
251
248
249
+ /**
250
+ * Add single module to composer json
251
+ *
252
+ * @param string $dir
253
+ * @param array $composer
254
+ * @param string|null $version
255
+ * @throws \Magento\MagentoCloud\Filesystem\FileSystemException
256
+ */
257
+ private function addModule (string $ dir , array &$ composer , string $ version = null ): void
258
+ {
259
+ if (!$ this ->file ->isExists ($ dir . '/composer.json ' )) {
260
+ return ;
261
+ }
262
+
263
+ $ dirComposer = json_decode ($ this ->file ->fileGetContents ($ dir . '/composer.json ' ), true );
264
+ $ composer ['repositories ' ][$ dirComposer ['name ' ]] = [
265
+ 'type ' => 'path ' ,
266
+ 'url ' => ltrim (str_replace ($ this ->directoryList ->getMagentoRoot (), '' , $ dir ), '/ ' ),
267
+ 'options ' => [
268
+ 'symlink ' => false ,
269
+ ],
270
+ ];
271
+ $ composer ['require ' ][$ dirComposer ['name ' ]] = $ version ?? $ dirComposer ['version ' ] ?? '* ' ;
272
+ }
273
+
252
274
/**
253
275
* @param array $repoOptions
254
276
* @return bool
@@ -257,4 +279,15 @@ private function isSinglePackage(array $repoOptions): bool
257
279
{
258
280
return isset ($ repoOptions ['type ' ]) && $ repoOptions ['type ' ] == self ::REPO_TYPE_SINGLE_PACKAGE ;
259
281
}
282
+
283
+ /**
284
+ * Checks that package has option type and it equal to @see ComposerGenerator::REPO_TYPE_FLAT_STRUCTURE
285
+ *
286
+ * @param array $repoOptions
287
+ * @return bool
288
+ */
289
+ private function isFlatStructurePackage (array $ repoOptions ): bool
290
+ {
291
+ return isset ($ repoOptions ['type ' ]) && $ repoOptions ['type ' ] == self ::REPO_TYPE_FLAT_STRUCTURE ;
292
+ }
260
293
}
0 commit comments