From 300c2ecc588eee4bc57737ae9a8efcfbf0fc2ea5 Mon Sep 17 00:00:00 2001 From: Jordi Date: Fri, 30 Apr 2021 09:15:30 +0200 Subject: [PATCH 1/7] Add default configuration when using assets --- config/projects.yaml | 119 +++++++++--------- .../DispatchBranchesProtectionCommand.php | 4 + .../Dispatcher/DispatchFilesCommand.php | 21 ++++ src/Config/ProjectsConfiguration.php | 2 + src/Domain/Value/Branch.php | 18 +++ templates/project/.babelrc.json | 3 + templates/project/.eslintrc.json | 21 ++++ .../.github/workflows/frontend.yaml.twig | 48 +++++++ templates/project/.gitignore.twig | 5 +- templates/project/.stylelintrc.json | 13 ++ .../Dispatcher/DispatchFilesCommandTest.php | 4 + tests/Domain/Value/BranchTest.php | 4 + tests/Domain/Value/ProjectTest.php | 8 ++ .../Github/Domain/Value/Search/QueryTest.php | 2 + 14 files changed, 211 insertions(+), 61 deletions(-) create mode 100644 templates/project/.babelrc.json create mode 100644 templates/project/.eslintrc.json create mode 100644 templates/project/.github/workflows/frontend.yaml.twig create mode 100644 templates/project/.stylelintrc.json diff --git a/config/projects.yaml b/config/projects.yaml index 37c7fca89..f27efa12c 100644 --- a/config/projects.yaml +++ b/config/projects.yaml @@ -1,74 +1,73 @@ admin-bundle: phpstan: true psalm: true - - custom_gitignore_part: | - # clean up some non bower ready package - src/Resources/public/vendor/admin-lte/bootstrap - src/Resources/public/vendor/admin-lte/build - src/Resources/public/vendor/admin-lte/dist/img - !src/Resources/public/vendor/admin-lte/dist/img/boxed-bg.jpg # Only image called in AdminLTE.css - src/Resources/public/vendor/admin-lte/dist/js/app.js - src/Resources/public/vendor/admin-lte/dist/js/demo.js - src/Resources/public/vendor/admin-lte/dist/js/pages - src/Resources/public/vendor/admin-lte/documentation - src/Resources/public/vendor/admin-lte/pages - src/Resources/public/vendor/admin-lte/plugins - src/Resources/public/vendor/admin-lte/*.html - src/Resources/public/vendor/admin-lte/Gruntfile.js - - src/Resources/public/vendor/iCheck/skins/all.css - src/Resources/public/vendor/iCheck/skins/*/* - !src/Resources/public/vendor/iCheck/skins/square/blue.css - !src/Resources/public/vendor/iCheck/skins/square/blue.png - !src/Resources/public/vendor/iCheck/skins/square/blue@2x.png - src/Resources/public/vendor/iCheck/icheck.js - - src/Resources/public/vendor/slimScroll/examples - src/Resources/public/vendor/slimScroll/jquery.slimscroll.js - - src/Resources/public/vendor/bootstrap/grunt - src/Resources/public/vendor/bootstrap/less - src/Resources/public/vendor/bootstrap/test-infra - src/Resources/public/vendor/bootstrap/Gruntfile.js - - src/Resources/public/vendor/jqueryui/themes/black-tie - src/Resources/public/vendor/jqueryui/themes/blitzer - src/Resources/public/vendor/jqueryui/themes/cupertino - src/Resources/public/vendor/jqueryui/themes/dark-hive - src/Resources/public/vendor/jqueryui/themes/dot-luv - src/Resources/public/vendor/jqueryui/themes/eggplant - src/Resources/public/vendor/jqueryui/themes/excite-bike - src/Resources/public/vendor/jqueryui/themes/hot-sneaks - src/Resources/public/vendor/jqueryui/themes/humanity - src/Resources/public/vendor/jqueryui/themes/le-frog - src/Resources/public/vendor/jqueryui/themes/mint-choc - src/Resources/public/vendor/jqueryui/themes/overcast - src/Resources/public/vendor/jqueryui/themes/pepper-grinder - src/Resources/public/vendor/jqueryui/themes/redmond - src/Resources/public/vendor/jqueryui/themes/smoothness - src/Resources/public/vendor/jqueryui/themes/south-street - src/Resources/public/vendor/jqueryui/themes/start - src/Resources/public/vendor/jqueryui/themes/sunny - src/Resources/public/vendor/jqueryui/themes/swanky-purse - src/Resources/public/vendor/jqueryui/themes/trontastic - src/Resources/public/vendor/jqueryui/themes/ui-darkness - src/Resources/public/vendor/jqueryui/themes/ui-lightness - src/Resources/public/vendor/jqueryui/themes/vader - - src/Resources/public/vendor/jquery/src - - src/Resources/public/vendor/jquery.scrollTo/demo - src/Resources/public/vendor/jquery.scrollTo/tests - branches: master: php: ['7.3', '7.4', '8.0'] + assets: true variants: symfony/symfony: ['4.4', '5.2'] sonata-project/block-bundle: ['4'] 3.x: php: ['7.3', '7.4', '8.0'] + custom_gitignore_part: | + # clean up some non bower ready package + src/Resources/public/vendor/admin-lte/bootstrap + src/Resources/public/vendor/admin-lte/build + src/Resources/public/vendor/admin-lte/dist/img + !src/Resources/public/vendor/admin-lte/dist/img/boxed-bg.jpg # Only image called in AdminLTE.css + src/Resources/public/vendor/admin-lte/dist/js/app.js + src/Resources/public/vendor/admin-lte/dist/js/demo.js + src/Resources/public/vendor/admin-lte/dist/js/pages + src/Resources/public/vendor/admin-lte/documentation + src/Resources/public/vendor/admin-lte/pages + src/Resources/public/vendor/admin-lte/plugins + src/Resources/public/vendor/admin-lte/*.html + src/Resources/public/vendor/admin-lte/Gruntfile.js + + src/Resources/public/vendor/iCheck/skins/all.css + src/Resources/public/vendor/iCheck/skins/*/* + !src/Resources/public/vendor/iCheck/skins/square/blue.css + !src/Resources/public/vendor/iCheck/skins/square/blue.png + !src/Resources/public/vendor/iCheck/skins/square/blue@2x.png + src/Resources/public/vendor/iCheck/icheck.js + + src/Resources/public/vendor/slimScroll/examples + src/Resources/public/vendor/slimScroll/jquery.slimscroll.js + + src/Resources/public/vendor/bootstrap/grunt + src/Resources/public/vendor/bootstrap/less + src/Resources/public/vendor/bootstrap/test-infra + src/Resources/public/vendor/bootstrap/Gruntfile.js + + src/Resources/public/vendor/jqueryui/themes/black-tie + src/Resources/public/vendor/jqueryui/themes/blitzer + src/Resources/public/vendor/jqueryui/themes/cupertino + src/Resources/public/vendor/jqueryui/themes/dark-hive + src/Resources/public/vendor/jqueryui/themes/dot-luv + src/Resources/public/vendor/jqueryui/themes/eggplant + src/Resources/public/vendor/jqueryui/themes/excite-bike + src/Resources/public/vendor/jqueryui/themes/hot-sneaks + src/Resources/public/vendor/jqueryui/themes/humanity + src/Resources/public/vendor/jqueryui/themes/le-frog + src/Resources/public/vendor/jqueryui/themes/mint-choc + src/Resources/public/vendor/jqueryui/themes/overcast + src/Resources/public/vendor/jqueryui/themes/pepper-grinder + src/Resources/public/vendor/jqueryui/themes/redmond + src/Resources/public/vendor/jqueryui/themes/smoothness + src/Resources/public/vendor/jqueryui/themes/south-street + src/Resources/public/vendor/jqueryui/themes/start + src/Resources/public/vendor/jqueryui/themes/sunny + src/Resources/public/vendor/jqueryui/themes/swanky-purse + src/Resources/public/vendor/jqueryui/themes/trontastic + src/Resources/public/vendor/jqueryui/themes/ui-darkness + src/Resources/public/vendor/jqueryui/themes/ui-lightness + src/Resources/public/vendor/jqueryui/themes/vader + + src/Resources/public/vendor/jquery/src + + src/Resources/public/vendor/jquery.scrollTo/demo + src/Resources/public/vendor/jquery.scrollTo/tests variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['3'] diff --git a/src/Command/Dispatcher/DispatchBranchesProtectionCommand.php b/src/Command/Dispatcher/DispatchBranchesProtectionCommand.php index afe7083a7..2ccac2431 100644 --- a/src/Command/Dispatcher/DispatchBranchesProtectionCommand.php +++ b/src/Command/Dispatcher/DispatchBranchesProtectionCommand.php @@ -143,6 +143,10 @@ private function buildRequiredStatusChecks(Project $project, Branch $branch): ar $requiredStatusChecks[] = 'Psalm'; } + if ($branch->usesAssets()) { + $requiredStatusChecks[] = 'Webpack Encore'; + } + /** @var PhpVersion $phpVersion */ foreach ($branch->phpVersions() as $phpVersion) { $requiredStatusChecks[] = sprintf( diff --git a/src/Command/Dispatcher/DispatchFilesCommand.php b/src/Command/Dispatcher/DispatchFilesCommand.php index 7f874ddb0..06cbe93ad 100644 --- a/src/Command/Dispatcher/DispatchFilesCommand.php +++ b/src/Command/Dispatcher/DispatchFilesCommand.php @@ -295,6 +295,27 @@ private function deleteNotNeededFilesAndDirs(Project $project, Branch $branch, s } } + if (!$branch->usesAssets()) { + $filepaths = [ + '.babelrc.json', + '.eslintrc.json', + '.stylelintrc.json', + '.github/workflows/frontend.yaml', + ]; + + foreach ($filepaths as $filepath) { + $file = u($distPath) + ->append('/') + ->append($filepath) + ->toString(); + + if ($this->filesystem->exists($file)) { + $this->io->writeln(sprintf('Delete /%s file!', $filepath)); + $this->filesystem->remove($file); + } + } + } + if (!$project->isBundle()) { $filepath = '.symfony.bundle.yaml'; $symfonyBundleFile = u($distPath) diff --git a/src/Config/ProjectsConfiguration.php b/src/Config/ProjectsConfiguration.php index 01142b71a..3fec15b19 100644 --- a/src/Config/ProjectsConfiguration.php +++ b/src/Config/ProjectsConfiguration.php @@ -52,6 +52,8 @@ public function getConfigTreeBuilder(): TreeBuilder ->arrayNode('tools')->prototype('scalar')->defaultValue([])->end()->end() ->arrayNode('php_extensions')->prototype('scalar')->defaultValue([])->end()->end() ->scalarNode('target_php')->defaultNull()->end() + ->scalarNode('custom_gitignore_part')->defaultNull()->end() + ->scalarNode('assets')->defaultFalse()->end() ->arrayNode('variants') ->normalizeKeys(false) ->useAttributeAsKey('name') diff --git a/src/Domain/Value/Branch.php b/src/Domain/Value/Branch.php index d55ac16f5..26ee71ebc 100644 --- a/src/Domain/Value/Branch.php +++ b/src/Domain/Value/Branch.php @@ -40,6 +40,8 @@ final class Branch */ private array $variants; + private bool $assets; + private ?string $customGitignorePart; private Path $docsPath; private Path $testsPath; private PhpVersion $targetPhpVersion; @@ -56,6 +58,8 @@ private function __construct( array $tools, array $phpExtensions, array $variants, + ?string $customGitignorePart, + bool $assets, Path $docsPath, Path $testsPath, ?PhpVersion $targetPhpVersion @@ -65,6 +69,8 @@ private function __construct( $this->tools = $tools; $this->phpExtensions = $phpExtensions; $this->variants = $variants; + $this->customGitignorePart = $customGitignorePart; + $this->assets = $assets; $this->docsPath = $docsPath; $this->testsPath = $testsPath; $this->targetPhpVersion = $targetPhpVersion ?? end($this->phpVersions); @@ -103,6 +109,8 @@ public static function fromValues(string $name, array $config): self $tools, $phpExtensions, $variants, + $config['custom_gitignore_part'], + $config['assets'], Path::fromString($config['docs_path']), Path::fromString($config['tests_path']), $targetPhpVersion @@ -171,6 +179,16 @@ public function variants(): array return $this->variants; } + public function usesAssets(): bool + { + return $this->assets; + } + + public function customGitignorePart(): ?string + { + return $this->customGitignorePart; + } + public function docsPath(): Path { return $this->docsPath; diff --git a/templates/project/.babelrc.json b/templates/project/.babelrc.json new file mode 100644 index 000000000..1320b9a32 --- /dev/null +++ b/templates/project/.babelrc.json @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} diff --git a/templates/project/.eslintrc.json b/templates/project/.eslintrc.json new file mode 100644 index 000000000..26257b50b --- /dev/null +++ b/templates/project/.eslintrc.json @@ -0,0 +1,21 @@ +{ + "parser": "@babel/eslint-parser", + "extends": ["airbnb-base"], + "env": { + "browser": true, + "jquery": true + }, + "plugins": ["header"], + "rules": { + "header/header": [2, "block", [ + "!", + " * This file is part of the Sonata Project package.", + " *", + " * (c) Thomas Rabaix ", + " *", + " * For the full copyright and license information, please view the LICENSE", + " * file that was distributed with this source code.", + " " + ], 2] + } +} diff --git a/templates/project/.github/workflows/frontend.yaml.twig b/templates/project/.github/workflows/frontend.yaml.twig new file mode 100644 index 000000000..6a2014c14 --- /dev/null +++ b/templates/project/.github/workflows/frontend.yaml.twig @@ -0,0 +1,48 @@ +# DO NOT EDIT THIS FILE! +# +# It's auto-generated by sonata-project/dev-kit package. + +name: Frontend + +on: + push: + branches: +{% for branch in project.branchesReverse|filter(branch => branch.usesAssets) %} + - {{ branch.name }} +{% endfor %} + paths: + - assets/** + - package.json + - yarn.lock + pull_request: + paths: + - assets/** + - package.json + - yarn.lock + +jobs: + webpack-encore: + name: Webpack Encore + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install Node 14 + uses: actions/setup-node@v2 + with: + node-version: 14 + + - name: Install NPM dependencies + uses: bahmutov/npm-install@v1 + + - name: Run Eslint + run: yarn run eslint assets/js + + - name: Run Stylelint + run: yarn run stylelint assets/scss + + - name: Run Webpack Encore + run: yarn encore production diff --git a/templates/project/.gitignore.twig b/templates/project/.gitignore.twig index 27026b693..e36a60ec2 100644 --- a/templates/project/.gitignore.twig +++ b/templates/project/.gitignore.twig @@ -17,7 +17,10 @@ phpstan.neon /drivers /tests/App/public/bundles {% endif %} -{% if project.customGitignorePart is not empty %} +{% if branch.customGitignorePart is not empty %} + +{{ branch.customGitignorePart }} +{%- elseif project.customGitignorePart is not empty -%} {{ project.customGitignorePart }} {% endif %} diff --git a/templates/project/.stylelintrc.json b/templates/project/.stylelintrc.json new file mode 100644 index 000000000..482517899 --- /dev/null +++ b/templates/project/.stylelintrc.json @@ -0,0 +1,13 @@ +{ + "extends": "stylelint-config-standard", + "plugins": ["stylelint-scss", "stylelint-order"], + "rules": { + "at-rule-no-unknown": null, + "scss/at-rule-no-unknown": true, + "order/order": [ + "custom-properties", + "declarations" + ], + "order/properties-alphabetical-order": true + } +} diff --git a/tests/Command/Dispatcher/DispatchFilesCommandTest.php b/tests/Command/Dispatcher/DispatchFilesCommandTest.php index 8d9735bcb..9826f9938 100644 --- a/tests/Command/Dispatcher/DispatchFilesCommandTest.php +++ b/tests/Command/Dispatcher/DispatchFilesCommandTest.php @@ -85,6 +85,8 @@ public function projectProvider(): \Generator master: php: ['7.3', '7.4'] target_php: ~ + assets: true + custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['4'] @@ -95,6 +97,8 @@ public function projectProvider(): \Generator 3.x: php: ['7.2', '7.3', '7.4'] target_php: ~ + assets: false + custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['3'] diff --git a/tests/Domain/Value/BranchTest.php b/tests/Domain/Value/BranchTest.php index 48c2f33e3..86ba67dee 100644 --- a/tests/Domain/Value/BranchTest.php +++ b/tests/Domain/Value/BranchTest.php @@ -24,6 +24,8 @@ final class BranchTest extends TestCase master: php: ['7.3', '7.4', '8.0'] target_php: '7.4' + assets: true + custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['4'] @@ -55,6 +57,8 @@ public function valid(): void self::assertCount(2, $branch->variants()); self::assertSame('docs', $branch->docsPath()->toString()); self::assertSame('tests', $branch->testsPath()->toString()); + self::assertTrue($branch->usesAssets()); + self::assertNull($branch->customGitignorePart()); self::assertTrue($branch->hasTool('foo')); self::assertTrue($branch->hasPhpExtension('bar')); } diff --git a/tests/Domain/Value/ProjectTest.php b/tests/Domain/Value/ProjectTest.php index 6885c421c..0c9a1aa04 100644 --- a/tests/Domain/Value/ProjectTest.php +++ b/tests/Domain/Value/ProjectTest.php @@ -36,6 +36,8 @@ final class ProjectTest extends TestCase master: php: ['7.3', '7.4'] target_php: ~ + assets: true + custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['4'] @@ -46,6 +48,8 @@ final class ProjectTest extends TestCase 3.x: php: ['7.2', '7.3', '7.4'] target_php: ~ + assets: false + custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['3'] @@ -139,6 +143,8 @@ public function isBundleProvider(): \Generator master: php: ['7.3', '7.4'] target_php: ~ + assets: true + custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['4'] @@ -167,6 +173,8 @@ public function isBundleProvider(): \Generator master: php: ['7.3', '7.4'] target_php: ~ + assets: true + custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['4'] diff --git a/tests/Github/Domain/Value/Search/QueryTest.php b/tests/Github/Domain/Value/Search/QueryTest.php index 5b170a009..e06cc509b 100644 --- a/tests/Github/Domain/Value/Search/QueryTest.php +++ b/tests/Github/Domain/Value/Search/QueryTest.php @@ -74,6 +74,8 @@ public function pullRequestsSince(): void master: php: ['7.3', '7.4'] target_php: ~ + assets: true + custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] sonata-project/block-bundle: ['4'] From 8cc059133665394b2b61ce5dcdee0276384e823b Mon Sep 17 00:00:00 2001 From: Jordi Date: Fri, 30 Apr 2021 15:51:51 +0200 Subject: [PATCH 2/7] Avoid deprecations with faker --- tests/Config/Exception/UnknownProjectTest.php | 2 +- tests/Domain/Value/TrimmedNonEmptyStringTest.php | 4 ++-- tests/Github/Domain/Value/PullRequestTest.php | 6 +++--- tests/Github/Domain/Value/ShaTest.php | 2 +- tests/Github/Domain/Value/UrlTest.php | 2 +- tests/Github/Domain/Value/UserTest.php | 6 +++--- tests/Util/DataProvider/StringProvider.php | 4 ++-- .../Factory/Github/Response/CheckRunFactory.php | 4 ++-- .../Util/Factory/Github/Response/LabelFactory.php | 4 ++-- .../Factory/Github/Response/PullRequestFactory.php | 14 +++++++------- .../Util/Factory/Github/Response/StatusFactory.php | 4 ++-- tests/Util/Factory/Github/Response/UserFactory.php | 4 ++-- 12 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/Config/Exception/UnknownProjectTest.php b/tests/Config/Exception/UnknownProjectTest.php index 480233e02..93094177a 100644 --- a/tests/Config/Exception/UnknownProjectTest.php +++ b/tests/Config/Exception/UnknownProjectTest.php @@ -26,7 +26,7 @@ final class UnknownProjectTest extends TestCase */ public function forName() { - $name = self::faker()->word; + $name = self::faker()->word(); $unknownProject = UnknownProject::forName($name); diff --git a/tests/Domain/Value/TrimmedNonEmptyStringTest.php b/tests/Domain/Value/TrimmedNonEmptyStringTest.php index 93c776ecf..c3ff929b4 100644 --- a/tests/Domain/Value/TrimmedNonEmptyStringTest.php +++ b/tests/Domain/Value/TrimmedNonEmptyStringTest.php @@ -26,7 +26,7 @@ final class TrimmedNonEmptyStringTest extends TestCase */ public function fromString(): void { - $string = self::faker()->word; + $string = self::faker()->word(); self::assertSame( $string, @@ -39,7 +39,7 @@ public function fromString(): void */ public function fromStringWithUntrimmedValue(): void { - $string = self::faker()->word; + $string = self::faker()->word(); $untrimmed = ' '.$string.' '; self::assertSame( diff --git a/tests/Github/Domain/Value/PullRequestTest.php b/tests/Github/Domain/Value/PullRequestTest.php index 4e70d281e..4cf8f133d 100644 --- a/tests/Github/Domain/Value/PullRequestTest.php +++ b/tests/Github/Domain/Value/PullRequestTest.php @@ -91,7 +91,7 @@ public function throwsExceptionIfNumberIsNgeative() */ public function usesTitleFromResponse() { - $value = self::faker()->sentence; + $value = self::faker()->sentence(); $response = Github\Response\PullRequestFactory::create([ 'title' => $value, @@ -437,8 +437,8 @@ public function body(): void - %s ``` BODY, - self::faker()->text, - self::faker()->text, + self::faker()->text(), + self::faker()->text(), $message = 'The fourth argument of the `SetObjectFieldValueAction::__construct` method is now mandatory.' ), ]); diff --git a/tests/Github/Domain/Value/ShaTest.php b/tests/Github/Domain/Value/ShaTest.php index 8a1cdc54a..3fadcc7a1 100644 --- a/tests/Github/Domain/Value/ShaTest.php +++ b/tests/Github/Domain/Value/ShaTest.php @@ -39,7 +39,7 @@ public function throwsExceptionFor(string $value): void */ public function valid(): void { - $value = self::faker()->sha256; + $value = self::faker()->sha256(); $sha = Sha::fromString($value); diff --git a/tests/Github/Domain/Value/UrlTest.php b/tests/Github/Domain/Value/UrlTest.php index 01feb2821..c8aabfaca 100644 --- a/tests/Github/Domain/Value/UrlTest.php +++ b/tests/Github/Domain/Value/UrlTest.php @@ -49,7 +49,7 @@ public function throwsExceptionIfValueDoesNotStartWithHttp(): void */ public function valid(): void { - $value = self::faker()->url; + $value = self::faker()->url(); $url = Url::fromString($value); diff --git a/tests/Github/Domain/Value/UserTest.php b/tests/Github/Domain/Value/UserTest.php index 10297dc38..523a5dddb 100644 --- a/tests/Github/Domain/Value/UserTest.php +++ b/tests/Github/Domain/Value/UserTest.php @@ -117,7 +117,7 @@ public function throwsExceptionIfLoginIs(string $value): void public function usesLoginFromResponse() { $response = Github\Response\UserFactory::create([ - 'login' => $value = self::faker()->word, + 'login' => $value = self::faker()->word(), ]); $user = User::fromResponse($response); @@ -134,7 +134,7 @@ public function usesLoginFromResponse() public function usesLoginForHandleFromResponse() { $response = Github\Response\UserFactory::create([ - 'login' => $value = self::faker()->word, + 'login' => $value = self::faker()->word(), ]); $user = User::fromResponse($response); @@ -181,7 +181,7 @@ public function throwsExceptionIfHtmlUrlIs(string $value): void public function usesHtmlurlFromResponse() { $response = Github\Response\UserFactory::create([ - 'html_url' => $value = self::faker()->url, + 'html_url' => $value = self::faker()->url(), ]); $user = User::fromResponse($response); diff --git a/tests/Util/DataProvider/StringProvider.php b/tests/Util/DataProvider/StringProvider.php index 1cc1796bf..604044526 100644 --- a/tests/Util/DataProvider/StringProvider.php +++ b/tests/Util/DataProvider/StringProvider.php @@ -33,12 +33,12 @@ private static function stringWithLength(int $length): string return str_pad( substr( - $faker->sentence, + $faker->sentence(), 0, $length ), $length, - $faker->randomLetter + $faker->randomLetter() ); } } diff --git a/tests/Util/Factory/Github/Response/CheckRunFactory.php b/tests/Util/Factory/Github/Response/CheckRunFactory.php index 9aa6a6cc7..000cbf14a 100644 --- a/tests/Util/Factory/Github/Response/CheckRunFactory.php +++ b/tests/Util/Factory/Github/Response/CheckRunFactory.php @@ -44,8 +44,8 @@ public static function create(array $parameters = []): array 'success', 'timed_out', ]), - 'name' => $faker->word, - 'details_url' => $faker->url, + 'name' => $faker->word(), + 'details_url' => $faker->url(), ]; return array_replace_recursive( diff --git a/tests/Util/Factory/Github/Response/LabelFactory.php b/tests/Util/Factory/Github/Response/LabelFactory.php index e82976646..591db00c3 100644 --- a/tests/Util/Factory/Github/Response/LabelFactory.php +++ b/tests/Util/Factory/Github/Response/LabelFactory.php @@ -30,8 +30,8 @@ public static function create(array $parameters = []): array $faker = self::faker(); $response = [ - 'name' => $faker->word, - 'color' => u($faker->hexColor)->replace('#', '')->toString(), + 'name' => $faker->word(), + 'color' => u($faker->hexColor())->replace('#', '')->toString(), ]; return array_replace_recursive( diff --git a/tests/Util/Factory/Github/Response/PullRequestFactory.php b/tests/Util/Factory/Github/Response/PullRequestFactory.php index c81e13ef1..18176e6b2 100644 --- a/tests/Util/Factory/Github/Response/PullRequestFactory.php +++ b/tests/Util/Factory/Github/Response/PullRequestFactory.php @@ -29,7 +29,7 @@ public static function create(array $parameters = []): array $faker = self::faker(); $repo = null; - if ($faker->boolean) { + if ($faker->boolean()) { $repo = [ 'owner' => UserFactory::create(), ]; @@ -37,7 +37,7 @@ public static function create(array $parameters = []): array $response = [ 'number' => $faker->numberBetween(1, 99999), - 'title' => $faker->sentence, + 'title' => $faker->sentence(), 'updated_at' => $faker->date('Y-m-d\TH:i:s\Z'), 'merged_at' => $faker->date('Y-m-d\TH:i:s\Z'), 'base' => [ @@ -45,11 +45,11 @@ public static function create(array $parameters = []): array ], 'head' => [ 'ref' => $faker->sentence(1), - 'sha' => $faker->sha256, + 'sha' => $faker->sha256(), 'repo' => $repo, ], 'user' => UserFactory::create(), - 'mergeable' => $faker->optional()->boolean, + 'mergeable' => $faker->optional()->boolean(), 'body' => sprintf( <<<'BODY' @@ -65,10 +65,10 @@ public static function create(array $parameters = []): array - The fourth argument of the `SetObjectFieldValueAction::__construct` method is now mandatory. ``` BODY, - $faker->text, - $faker->text + $faker->text(), + $faker->text() ), - 'html_url' => $faker->url, + 'html_url' => $faker->url(), 'labels' => array_map(static function (): array { return LabelFactory::create(); }, range(0, $faker->numberBetween(0, 5))), diff --git a/tests/Util/Factory/Github/Response/StatusFactory.php b/tests/Util/Factory/Github/Response/StatusFactory.php index 61283cf62..530e60651 100644 --- a/tests/Util/Factory/Github/Response/StatusFactory.php +++ b/tests/Util/Factory/Github/Response/StatusFactory.php @@ -34,9 +34,9 @@ public static function create(array $parameters = []): array 'pending', 'success', ]), - 'context' => $faker->word, + 'context' => $faker->word(), 'description' => $faker->sentence(5), - 'target_url' => $faker->url, + 'target_url' => $faker->url(), ]; return array_replace_recursive( diff --git a/tests/Util/Factory/Github/Response/UserFactory.php b/tests/Util/Factory/Github/Response/UserFactory.php index 856f294eb..f5e0079e3 100644 --- a/tests/Util/Factory/Github/Response/UserFactory.php +++ b/tests/Util/Factory/Github/Response/UserFactory.php @@ -30,8 +30,8 @@ public static function create(array $parameters = []): array $response = [ 'id' => $faker->numberBetween(1, 999), - 'login' => $faker->userName, - 'html_url' => $faker->url, + 'login' => $faker->userName(), + 'html_url' => $faker->url(), ]; return array_replace_recursive( From 860b1cd49dd63819e452661212b88b9fe1a01ca8 Mon Sep 17 00:00:00 2001 From: Jordi Date: Fri, 30 Apr 2021 15:54:35 +0200 Subject: [PATCH 3/7] Rename assets for frontend and usesAssets for hasFrontend --- config/projects.yaml | 2 +- .../Dispatcher/DispatchBranchesProtectionCommand.php | 2 +- src/Command/Dispatcher/DispatchFilesCommand.php | 2 +- src/Config/ProjectsConfiguration.php | 2 +- src/Domain/Value/Branch.php | 4 ++-- templates/project/.github/workflows/frontend.yaml.twig | 2 +- tests/Command/Dispatcher/DispatchFilesCommandTest.php | 4 ++-- tests/Domain/Value/BranchTest.php | 4 ++-- tests/Domain/Value/ProjectTest.php | 8 ++++---- tests/Github/Domain/Value/Search/QueryTest.php | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/config/projects.yaml b/config/projects.yaml index f27efa12c..4e400b580 100644 --- a/config/projects.yaml +++ b/config/projects.yaml @@ -4,7 +4,7 @@ admin-bundle: branches: master: php: ['7.3', '7.4', '8.0'] - assets: true + frontend: true variants: symfony/symfony: ['4.4', '5.2'] sonata-project/block-bundle: ['4'] diff --git a/src/Command/Dispatcher/DispatchBranchesProtectionCommand.php b/src/Command/Dispatcher/DispatchBranchesProtectionCommand.php index 2ccac2431..9b2410b6a 100644 --- a/src/Command/Dispatcher/DispatchBranchesProtectionCommand.php +++ b/src/Command/Dispatcher/DispatchBranchesProtectionCommand.php @@ -143,7 +143,7 @@ private function buildRequiredStatusChecks(Project $project, Branch $branch): ar $requiredStatusChecks[] = 'Psalm'; } - if ($branch->usesAssets()) { + if ($branch->hasFrontend()) { $requiredStatusChecks[] = 'Webpack Encore'; } diff --git a/src/Command/Dispatcher/DispatchFilesCommand.php b/src/Command/Dispatcher/DispatchFilesCommand.php index 06cbe93ad..dd19d9274 100644 --- a/src/Command/Dispatcher/DispatchFilesCommand.php +++ b/src/Command/Dispatcher/DispatchFilesCommand.php @@ -295,7 +295,7 @@ private function deleteNotNeededFilesAndDirs(Project $project, Branch $branch, s } } - if (!$branch->usesAssets()) { + if (!$branch->hasFrontend()) { $filepaths = [ '.babelrc.json', '.eslintrc.json', diff --git a/src/Config/ProjectsConfiguration.php b/src/Config/ProjectsConfiguration.php index 3fec15b19..6c0ac83a4 100644 --- a/src/Config/ProjectsConfiguration.php +++ b/src/Config/ProjectsConfiguration.php @@ -53,7 +53,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->arrayNode('php_extensions')->prototype('scalar')->defaultValue([])->end()->end() ->scalarNode('target_php')->defaultNull()->end() ->scalarNode('custom_gitignore_part')->defaultNull()->end() - ->scalarNode('assets')->defaultFalse()->end() + ->scalarNode('frontend')->defaultFalse()->end() ->arrayNode('variants') ->normalizeKeys(false) ->useAttributeAsKey('name') diff --git a/src/Domain/Value/Branch.php b/src/Domain/Value/Branch.php index 26ee71ebc..d2cb5af7b 100644 --- a/src/Domain/Value/Branch.php +++ b/src/Domain/Value/Branch.php @@ -110,7 +110,7 @@ public static function fromValues(string $name, array $config): self $phpExtensions, $variants, $config['custom_gitignore_part'], - $config['assets'], + $config['frontend'], Path::fromString($config['docs_path']), Path::fromString($config['tests_path']), $targetPhpVersion @@ -179,7 +179,7 @@ public function variants(): array return $this->variants; } - public function usesAssets(): bool + public function hasFrontend(): bool { return $this->assets; } diff --git a/templates/project/.github/workflows/frontend.yaml.twig b/templates/project/.github/workflows/frontend.yaml.twig index 6a2014c14..2ff925e22 100644 --- a/templates/project/.github/workflows/frontend.yaml.twig +++ b/templates/project/.github/workflows/frontend.yaml.twig @@ -7,7 +7,7 @@ name: Frontend on: push: branches: -{% for branch in project.branchesReverse|filter(branch => branch.usesAssets) %} +{% for branch in project.branchesReverse|filter(branch => branch.hasFrontend) %} - {{ branch.name }} {% endfor %} paths: diff --git a/tests/Command/Dispatcher/DispatchFilesCommandTest.php b/tests/Command/Dispatcher/DispatchFilesCommandTest.php index 9826f9938..63352d14f 100644 --- a/tests/Command/Dispatcher/DispatchFilesCommandTest.php +++ b/tests/Command/Dispatcher/DispatchFilesCommandTest.php @@ -85,7 +85,7 @@ public function projectProvider(): \Generator master: php: ['7.3', '7.4'] target_php: ~ - assets: true + frontend: true custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] @@ -97,7 +97,7 @@ public function projectProvider(): \Generator 3.x: php: ['7.2', '7.3', '7.4'] target_php: ~ - assets: false + frontend: false custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] diff --git a/tests/Domain/Value/BranchTest.php b/tests/Domain/Value/BranchTest.php index 86ba67dee..c58ef56de 100644 --- a/tests/Domain/Value/BranchTest.php +++ b/tests/Domain/Value/BranchTest.php @@ -24,7 +24,7 @@ final class BranchTest extends TestCase master: php: ['7.3', '7.4', '8.0'] target_php: '7.4' - assets: true + frontend: true custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] @@ -57,7 +57,7 @@ public function valid(): void self::assertCount(2, $branch->variants()); self::assertSame('docs', $branch->docsPath()->toString()); self::assertSame('tests', $branch->testsPath()->toString()); - self::assertTrue($branch->usesAssets()); + self::assertTrue($branch->hasFrontend()); self::assertNull($branch->customGitignorePart()); self::assertTrue($branch->hasTool('foo')); self::assertTrue($branch->hasPhpExtension('bar')); diff --git a/tests/Domain/Value/ProjectTest.php b/tests/Domain/Value/ProjectTest.php index 0c9a1aa04..e6db1d24a 100644 --- a/tests/Domain/Value/ProjectTest.php +++ b/tests/Domain/Value/ProjectTest.php @@ -36,7 +36,7 @@ final class ProjectTest extends TestCase master: php: ['7.3', '7.4'] target_php: ~ - assets: true + frontend: true custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] @@ -48,7 +48,7 @@ final class ProjectTest extends TestCase 3.x: php: ['7.2', '7.3', '7.4'] target_php: ~ - assets: false + frontend: false custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] @@ -143,7 +143,7 @@ public function isBundleProvider(): \Generator master: php: ['7.3', '7.4'] target_php: ~ - assets: true + frontend: true custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] @@ -173,7 +173,7 @@ public function isBundleProvider(): \Generator master: php: ['7.3', '7.4'] target_php: ~ - assets: true + frontend: true custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] diff --git a/tests/Github/Domain/Value/Search/QueryTest.php b/tests/Github/Domain/Value/Search/QueryTest.php index e06cc509b..7d4fbd990 100644 --- a/tests/Github/Domain/Value/Search/QueryTest.php +++ b/tests/Github/Domain/Value/Search/QueryTest.php @@ -74,7 +74,7 @@ public function pullRequestsSince(): void master: php: ['7.3', '7.4'] target_php: ~ - assets: true + frontend: true custom_gitignore_part: ~ variants: symfony/symfony: ['4.4'] From 78ee35e2765d47eee895abe052e64f313b4a624b Mon Sep 17 00:00:00 2001 From: Jordi Date: Fri, 30 Apr 2021 16:14:24 +0200 Subject: [PATCH 4/7] Change json files for js files to add needed headers --- .../Dispatcher/DispatchFilesCommand.php | 6 ++-- templates/project/.babelrc.js | 18 ++++++++++ templates/project/.babelrc.json | 3 -- templates/project/.eslintrc.js | 36 +++++++++++++++++++ templates/project/.eslintrc.json | 21 ----------- templates/project/.gitignore.twig | 3 ++ templates/project/.stylelintrc.js | 28 +++++++++++++++ templates/project/.stylelintrc.json | 13 ------- 8 files changed, 88 insertions(+), 40 deletions(-) create mode 100644 templates/project/.babelrc.js delete mode 100644 templates/project/.babelrc.json create mode 100644 templates/project/.eslintrc.js delete mode 100644 templates/project/.eslintrc.json create mode 100644 templates/project/.stylelintrc.js delete mode 100644 templates/project/.stylelintrc.json diff --git a/src/Command/Dispatcher/DispatchFilesCommand.php b/src/Command/Dispatcher/DispatchFilesCommand.php index dd19d9274..ce782da2f 100644 --- a/src/Command/Dispatcher/DispatchFilesCommand.php +++ b/src/Command/Dispatcher/DispatchFilesCommand.php @@ -297,9 +297,9 @@ private function deleteNotNeededFilesAndDirs(Project $project, Branch $branch, s if (!$branch->hasFrontend()) { $filepaths = [ - '.babelrc.json', - '.eslintrc.json', - '.stylelintrc.json', + '.babelrc.js', + '.eslintrc.js', + '.stylelintrc.js', '.github/workflows/frontend.yaml', ]; diff --git a/templates/project/.babelrc.js b/templates/project/.babelrc.js new file mode 100644 index 000000000..8717622ae --- /dev/null +++ b/templates/project/.babelrc.js @@ -0,0 +1,18 @@ +/*! + * This file is part of the Sonata Project package. + * + * (c) Thomas Rabaix + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/* + * DO NOT EDIT THIS FILE! + * + * It's auto-generated by sonata-project/dev-kit package. + */ + +module.exports = { + presets: ['@babel/preset-env'], +}; diff --git a/templates/project/.babelrc.json b/templates/project/.babelrc.json deleted file mode 100644 index 1320b9a32..000000000 --- a/templates/project/.babelrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["@babel/preset-env"] -} diff --git a/templates/project/.eslintrc.js b/templates/project/.eslintrc.js new file mode 100644 index 000000000..0ee6ba2c9 --- /dev/null +++ b/templates/project/.eslintrc.js @@ -0,0 +1,36 @@ +/*! + * This file is part of the Sonata Project package. + * + * (c) Thomas Rabaix + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/* + * DO NOT EDIT THIS FILE! + * + * It's auto-generated by sonata-project/dev-kit package. + */ + +module.exports = { + parser: '@babel/eslint-parser', + extends: ['airbnb-base'], + env: { + browser: true, + jquery: true, + }, + plugins: ['header'], + rules: { + 'header/header': [2, 'block', [ + '!', + ' * This file is part of the Sonata Project package.', + ' *', + ' * (c) Thomas Rabaix ', + ' *', + ' * For the full copyright and license information, please view the LICENSE', + ' * file that was distributed with this source code.', + ' ', + ], 2], + }, +}; diff --git a/templates/project/.eslintrc.json b/templates/project/.eslintrc.json deleted file mode 100644 index 26257b50b..000000000 --- a/templates/project/.eslintrc.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "parser": "@babel/eslint-parser", - "extends": ["airbnb-base"], - "env": { - "browser": true, - "jquery": true - }, - "plugins": ["header"], - "rules": { - "header/header": [2, "block", [ - "!", - " * This file is part of the Sonata Project package.", - " *", - " * (c) Thomas Rabaix ", - " *", - " * For the full copyright and license information, please view the LICENSE", - " * file that was distributed with this source code.", - " " - ], 2] - } -} diff --git a/templates/project/.gitignore.twig b/templates/project/.gitignore.twig index e36a60ec2..1d2350e37 100644 --- a/templates/project/.gitignore.twig +++ b/templates/project/.gitignore.twig @@ -17,6 +17,9 @@ phpstan.neon /drivers /tests/App/public/bundles {% endif %} +{% if branch.hasFrontend %} +yarn-error.log +{% endif %} {% if branch.customGitignorePart is not empty %} {{ branch.customGitignorePart }} diff --git a/templates/project/.stylelintrc.js b/templates/project/.stylelintrc.js new file mode 100644 index 000000000..c74f60150 --- /dev/null +++ b/templates/project/.stylelintrc.js @@ -0,0 +1,28 @@ +/*! + * This file is part of the Sonata Project package. + * + * (c) Thomas Rabaix + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/* + * DO NOT EDIT THIS FILE! + * + * It's auto-generated by sonata-project/dev-kit package. + */ + +module.exports = { + extends: 'stylelint-config-standard', + plugins: ['stylelint-scss', 'stylelint-order'], + rules: { + 'at-rule-no-unknown': null, + 'scss/at-rule-no-unknown': true, + 'order/order': [ + 'custom-properties', + 'declarations', + ], + 'order/properties-alphabetical-order': true, + }, +}; diff --git a/templates/project/.stylelintrc.json b/templates/project/.stylelintrc.json deleted file mode 100644 index 482517899..000000000 --- a/templates/project/.stylelintrc.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "stylelint-config-standard", - "plugins": ["stylelint-scss", "stylelint-order"], - "rules": { - "at-rule-no-unknown": null, - "scss/at-rule-no-unknown": true, - "order/order": [ - "custom-properties", - "declarations" - ], - "order/properties-alphabetical-order": true - } -} From 582d5be5d1c51bddaf09892d57c5985771ece587 Mon Sep 17 00:00:00 2001 From: Jordi Date: Fri, 30 Apr 2021 16:19:21 +0200 Subject: [PATCH 5/7] Add missing postcss config --- .../Dispatcher/DispatchFilesCommand.php | 1 + .../.github/workflows/frontend.yaml.twig | 10 ++++++++++ templates/project/postcss.config.js | 20 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 templates/project/postcss.config.js diff --git a/src/Command/Dispatcher/DispatchFilesCommand.php b/src/Command/Dispatcher/DispatchFilesCommand.php index ce782da2f..afde2d476 100644 --- a/src/Command/Dispatcher/DispatchFilesCommand.php +++ b/src/Command/Dispatcher/DispatchFilesCommand.php @@ -300,6 +300,7 @@ private function deleteNotNeededFilesAndDirs(Project $project, Branch $branch, s '.babelrc.js', '.eslintrc.js', '.stylelintrc.js', + 'postcss.config.js', '.github/workflows/frontend.yaml', ]; diff --git a/templates/project/.github/workflows/frontend.yaml.twig b/templates/project/.github/workflows/frontend.yaml.twig index 2ff925e22..76db4d6d6 100644 --- a/templates/project/.github/workflows/frontend.yaml.twig +++ b/templates/project/.github/workflows/frontend.yaml.twig @@ -12,13 +12,23 @@ on: {% endfor %} paths: - assets/** + - webpack.config.js - package.json - yarn.lock + - .babelrc.js + - .eslintrc.js + - .stylelintrc.js + - postcss.config.js pull_request: paths: - assets/** + - webpack.config.js - package.json - yarn.lock + - .babelrc.js + - .eslintrc.js + - .stylelintrc.js + - postcss.config.js jobs: webpack-encore: diff --git a/templates/project/postcss.config.js b/templates/project/postcss.config.js new file mode 100644 index 000000000..85545b709 --- /dev/null +++ b/templates/project/postcss.config.js @@ -0,0 +1,20 @@ +/*! + * This file is part of the Sonata Project package. + * + * (c) Thomas Rabaix + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/* + * DO NOT EDIT THIS FILE! + * + * It's auto-generated by sonata-project/dev-kit package. + */ + +module.exports = { + plugins: { + autoprefixer: {}, + }, +}; From 6f312aa0af8af1f8f3489bbb6823e875be6f32dd Mon Sep 17 00:00:00 2001 From: Jordi Date: Fri, 30 Apr 2021 16:25:33 +0200 Subject: [PATCH 6/7] Fix missing rename to frontend --- src/Domain/Value/Branch.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Domain/Value/Branch.php b/src/Domain/Value/Branch.php index d2cb5af7b..e2cb4f18d 100644 --- a/src/Domain/Value/Branch.php +++ b/src/Domain/Value/Branch.php @@ -40,7 +40,7 @@ final class Branch */ private array $variants; - private bool $assets; + private bool $frontend; private ?string $customGitignorePart; private Path $docsPath; private Path $testsPath; @@ -59,7 +59,7 @@ private function __construct( array $phpExtensions, array $variants, ?string $customGitignorePart, - bool $assets, + bool $frontend, Path $docsPath, Path $testsPath, ?PhpVersion $targetPhpVersion @@ -70,7 +70,7 @@ private function __construct( $this->phpExtensions = $phpExtensions; $this->variants = $variants; $this->customGitignorePart = $customGitignorePart; - $this->assets = $assets; + $this->frontend = $frontend; $this->docsPath = $docsPath; $this->testsPath = $testsPath; $this->targetPhpVersion = $targetPhpVersion ?? end($this->phpVersions); @@ -181,7 +181,7 @@ public function variants(): array public function hasFrontend(): bool { - return $this->assets; + return $this->frontend; } public function customGitignorePart(): ?string From 86588cd6c7395728ed803ab54dde179d8e2f446a Mon Sep 17 00:00:00 2001 From: Jordi Date: Sat, 1 May 2021 08:03:44 +0200 Subject: [PATCH 7/7] Refactor on remove files --- .../Dispatcher/DispatchFilesCommand.php | 76 +++++-------------- 1 file changed, 19 insertions(+), 57 deletions(-) diff --git a/src/Command/Dispatcher/DispatchFilesCommand.php b/src/Command/Dispatcher/DispatchFilesCommand.php index afde2d476..a989c9c76 100644 --- a/src/Command/Dispatcher/DispatchFilesCommand.php +++ b/src/Command/Dispatcher/DispatchFilesCommand.php @@ -257,76 +257,38 @@ private function deleteNotNeededFilesAndDirs(Project $project, Branch $branch, s )); } - if (!$project->hasDocumentation()) { - $docsPath = $branch->docsPath()->toString(); - - $docsDirectory = u($distPath) - ->append('/') - ->append($docsPath) - ->toString(); - - if ($this->filesystem->exists($docsDirectory)) { - $this->io->writeln(sprintf('Delete /%s directory!', $docsPath)); - $this->filesystem->remove($docsDirectory); - } + $filesToRemove = []; - $filepath = '.github/workflows/documentation.yaml'; - $documentationWorkflowFile = u($distPath) - ->append('/') - ->append($filepath) - ->toString(); - - if ($this->filesystem->exists($documentationWorkflowFile)) { - $this->io->writeln(sprintf('Delete /%s file!', $filepath)); - $this->filesystem->remove($documentationWorkflowFile); - } + if (!$project->hasDocumentation()) { + $filesToRemove[] = $branch->docsPath()->toString(); + $filesToRemove[] = '.github/workflows/documentation.yaml'; } if (!$project->usesPHPStan() && !$project->usesPsalm()) { - $filepath = '.github/workflows/qa.yaml'; - $qaWorkflowFile = u($distPath) - ->append('/') - ->append($filepath) - ->toString(); - - if ($this->filesystem->exists($qaWorkflowFile)) { - $this->io->writeln(sprintf('Delete /%s file!', $filepath)); - $this->filesystem->remove($qaWorkflowFile); - } + $filesToRemove[] = '.github/workflows/qa.yaml'; } if (!$branch->hasFrontend()) { - $filepaths = [ - '.babelrc.js', - '.eslintrc.js', - '.stylelintrc.js', - 'postcss.config.js', - '.github/workflows/frontend.yaml', - ]; - - foreach ($filepaths as $filepath) { - $file = u($distPath) - ->append('/') - ->append($filepath) - ->toString(); - - if ($this->filesystem->exists($file)) { - $this->io->writeln(sprintf('Delete /%s file!', $filepath)); - $this->filesystem->remove($file); - } - } + $filesToRemove[] = '.babelrc.js'; + $filesToRemove[] = '.eslintrc.js'; + $filesToRemove[] = '.stylelintrc.js'; + $filesToRemove[] = 'postcss.config.js'; + $filesToRemove[] = '.github/workflows/frontend.yaml'; } if (!$project->isBundle()) { - $filepath = '.symfony.bundle.yaml'; - $symfonyBundleFile = u($distPath) + $filesToRemove[] = '.symfony.bundle.yaml'; + } + + foreach ($filesToRemove as $fileToRemove) { + $file = u($distPath) ->append('/') - ->append($filepath) + ->append($fileToRemove) ->toString(); - if ($this->filesystem->exists($symfonyBundleFile)) { - $this->io->writeln(sprintf('Delete /%s file!', $filepath)); - $this->filesystem->remove($symfonyBundleFile); + if ($this->filesystem->exists($file)) { + $this->io->writeln(sprintf('Delete /%s file!', $fileToRemove)); + $this->filesystem->remove($file); } } }