Skip to content

Commit afd865d

Browse files
committed
Adding ComposerEditor and fixing CI
1 parent 726b999 commit afd865d

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

.travis.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ cache:
1313
- $HOME/.composer
1414

1515
before_script:
16-
- cd generator
17-
- composer install --no-interaction
18-
- mkdir -p build/logs
16+
- cd generator && composer install --no-interaction && cd ..
1917
- |
2018
if [ ! -d "generator/doc/doc-en/en" ]; then
2119
cd generator/doc
@@ -26,16 +24,12 @@ before_script:
2624
svn update
2725
cd ../../..
2826
fi
29-
- cd ..
3027
- composer update
3128

3229
script:
33-
- cd generator
34-
- "./vendor/bin/phpunit"
35-
#- "./vendor/bin/composer-require-checker --config-file=composer-require-checker.json"
36-
- composer cs-check
37-
- composer phpstan
38-
- cd ..
30+
- cd generator && ./vendor/bin/phpunit && cd ..
31+
- cd generator && composer cs-check && cd ..
32+
- cd generator && composer phpstan && cd ..
3933
- composer cs-check
4034
- composer phpstan
4135

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
4+
namespace Safe;
5+
6+
/**
7+
* This class will edit the main composer.json file to add the list of files generated from modules.
8+
*/
9+
class ComposerJsonEditor
10+
{
11+
/**
12+
* @param string[] $modules A list of modules
13+
*/
14+
public static function editFiles(array $modules): void
15+
{
16+
$files = \array_map(function(string $module) {
17+
return 'generated/'.lcfirst($module).'.php';
18+
}, $modules);
19+
$composerContent = file_get_contents(__DIR__.'/../../composer.json');
20+
if ($composerContent === false) {
21+
throw new \Exception('Error while loading composer.json file for edition.');
22+
}
23+
$composerJson = \json_decode($composerContent, true);
24+
$composerJson['autoload']['files'] = $files;
25+
26+
$newContent = json_encode($composerJson, \JSON_PRETTY_PRINT);
27+
\file_put_contents(__DIR__.'/../../composer.json', $newContent);
28+
}
29+
}

generator/src/GenerateCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
5656
foreach ($files as $file) {
5757
require($file);
5858
}
59+
60+
// Finally, let's edit the composer.json file
61+
ComposerJsonEditor::editFiles(\array_keys($modules));
5962
}
6063

6164
private function rmGenerated(): void

0 commit comments

Comments
 (0)