Skip to content

Commit

Permalink
Add default configuration when using assets
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Apr 30, 2021
1 parent d9010be commit eaeb0d4
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 61 deletions.
119 changes: 59 additions & 60 deletions config/projects.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
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']
Expand Down
21 changes: 21 additions & 0 deletions src/Command/Dispatcher/DispatchFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <info>/%s</info> file!', $filepath));
$this->filesystem->remove($file);
}
}
}

if (!$project->isBundle()) {
$filepath = '.symfony.bundle.yaml';
$symfonyBundleFile = u($distPath)
Expand Down
2 changes: 2 additions & 0 deletions src/Config/ProjectsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
18 changes: 18 additions & 0 deletions src/Domain/Value/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,6 +58,8 @@ private function __construct(
array $tools,
array $phpExtensions,
array $variants,
?string $customGitignorePart,
bool $assets,
Path $docsPath,
Path $testsPath,
?PhpVersion $targetPhpVersion
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions templates/project/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
21 changes: 21 additions & 0 deletions templates/project/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
" *",
" * For the full copyright and license information, please view the LICENSE",
" * file that was distributed with this source code.",
" "
], 2]
}
}
48 changes: 48 additions & 0 deletions templates/project/.github/workflows/frontend.yaml.twig
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion templates/project/.gitignore.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
13 changes: 13 additions & 0 deletions templates/project/.stylelintrc.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit eaeb0d4

Please sign in to comment.