Skip to content

Commit

Permalink
Implement Webpack Encore (BitBagCommerce#77)
Browse files Browse the repository at this point in the history
* Add webpack configuration

* Replace gulp with webpack, add dist files

* Update and relocate templates, refactor JS

* Split readme.md into smaler files

* Add plugin development documentation

* Add frontend instructions

* Upgrade frontend dependencies

* Refactor a wishlist details page

* Upgrade node version for githib actions

* Change non-webpack.md

* Improve QC and fix github actions

* Add test attributes for Behat

* Update docs

* Improve QC

* Improve QC
  • Loading branch information
mycreedo authored Oct 25, 2021
1 parent 738acde commit 26678fa
Show file tree
Hide file tree
Showing 80 changed files with 7,320 additions and 368 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
php: ["8.0", "7.4"]
symfony: ["^4.4", "^5.2"]
sylius: ["~1.10.0"]
node: ["10.x"]
node: ["^14.17.x"]
mysql: ["8.0"]

env:
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
- name: Prepare test application assets
run: |
(cd tests/Application && bin/console assets:install public -vvv)
(cd tests/Application && yarn build)
(cd tests/Application && yarn prod)
- name: Prepare test application cache
run: (cd tests/Application && bin/console cache:warmup -vvv)
Expand Down
128 changes: 13 additions & 115 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

----

[ ![](https://img.shields.io/packagist/l/bitbag/wishlist-plugin.svg) ](https://packagist.org/packages/bitbag/wishlist-plugin "License")
[ ![](https://img.shields.io/packagist/v/bitbag/wishlist-plugin.svg) ](https://packagist.org/packages/bitbag/wishlist-plugin "Version")
[ ![](https://img.shields.io/travis/BitBagCommerce/SyliusWishlistPlugin/master.svg) ](http://travis-ci.org/BitBagCommerce/SyliusWishlistPlugin "Build status")
[ ![](https://img.shields.io/scrutinizer/g/BitBagCommerce/SyliusWishlistPlugin.svg) ](https://scrutinizer-ci.com/g/BitBagCommerce/SyliusWishlistPlugin/ "Scrutinizer")
[ ![](https://poser.pugx.org/bitbag/wishlist-plugin/downloads)](https://packagist.org/packages/bitbag/wishlist-plugin "Total Downloads")
[ ![Slack](https://img.shields.io/badge/community%20chat-slack-FF1493.svg)](http://sylius-devs.slack.com)
[ ![](https://img.shields.io/packagist/l/bitbag/wishlist-plugin.svg) ](https://packagist.org/packages/bitbag/wishlist-plugin "License")
[ ![](https://img.shields.io/packagist/v/bitbag/wishlist-plugin.svg) ](https://packagist.org/packages/bitbag/wishlist-plugin "Version")
[ ![](https://img.shields.io/travis/BitBagCommerce/SyliusWishlistPlugin/master.svg) ](http://travis-ci.org/BitBagCommerce/SyliusWishlistPlugin "Build status")
[ ![](https://img.shields.io/scrutinizer/g/BitBagCommerce/SyliusWishlistPlugin.svg) ](https://scrutinizer-ci.com/g/BitBagCommerce/SyliusWishlistPlugin/ "Scrutinizer")
[ ![](https://poser.pugx.org/bitbag/wishlist-plugin/downloads)](https://packagist.org/packages/bitbag/wishlist-plugin "Total Downloads")
[ ![Slack](https://img.shields.io/badge/community%20chat-slack-FF1493.svg)](http://sylius-devs.slack.com)
[ ![Support](https://img.shields.io/badge/support-contact%20author-blue])](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_wishlist)

<p>
<img align="left" src="https://sylius.com/assets/badge-approved-by-sylius.png" width="85">
</p>
</p>

At BitBag we do believe in open source. However, we are able to do it just because of our awesome clients, who are kind enough to share some parts of our work with the community. Therefore, if you feel like there is a possibility for us to work together, feel free to reach out. You will find out more about our professional services, technologies, and contact details at [https://bitbag.io/](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_wishlist).

Expand All @@ -26,10 +26,6 @@ Like what we do? Want to join us? Check out our job listings on our [career page

* [Overview](#overview)
* [Support](#we-are-here-to-help)
* [Installation](#installation)
* [Usage](#usage)
* [Customization](#customization)
* [Testing](#testing)
* [About us](#about-us)
* [Community](#community)
* [Demo](#demo-sylius-shop)
Expand All @@ -41,116 +37,18 @@ Like what we do? Want to join us? Check out our job listings on our [career page
----
This plugin allows you to integrate wishlist features with Sylius platform app.

- [Installation](./doc/01-installation.md)
- [Usage](./doc/02-usage.md)
- [Customization](./doc/03-customization.md)
- [Development](./doc/04-development.md)
- [Testing](./doc/05-testing.md)

## We are here to help
This **open-source plugin was developed to help the Sylius community**. If you have any additional questions, would like help with installing or configuring the plugin, or need any assistance with your Sylius project - let us know!

[![](https://bitbag.io/wp-content/uploads/2020/10/button-contact.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_wishlist)


# Installation

----


We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.
```bash
$ composer require bitbag/wishlist-plugin
```

Add plugin dependencies to your `config/bundles.php` file:
```php
return [
...

BitBag\SyliusWishlistPlugin\BitBagSyliusWishlistPlugin::class => ['all' => true],
];
```

Import required config in your `config/packages/_sylius.yaml` file:
```yaml
# config/packages/_sylius.yaml

imports:
...

- { resource: "@BitBagSyliusWishlistPlugin/Resources/config/config.yml" }
```
Import routing in your `config/routes.yaml` file:

```
# config/routes.yaml

bitbag_sylius_wishlist_plugin:
resource: "@BitBagSyliusWishlistPlugin/Resources/config/routing.yml"
```
Update your database
```
$ bin/console doctrine:migrations:migrate
```
**Note:** If you are running it on production, add the `-e prod` flag to this command.
**Note:** If you are updating this plugin from version 1.4.x you need to run:
```
$ bin/console doctrine:migrations:version BitBag\\SyliusWishlistPlugin\\Migrations\\Version20201029161558 --add --no-interaction
```
## Usage
----
### Rendering the wishlist
<div align="center">
<img src="doc/index.jpg"/>
</div>
You can use `@BitBagSyliusWishlistPlugin/_addToWishlist.html.twig`, `@BitBagSyliusWishlistPlugin/_removeFromWishlist.html.twig` and `@BitBagSyliusWishlistPlugin/_removeFromWishlist.html.twig`
templates to enable adding/removing/displaying wishlist from the Twig UI.
For an example on how to do that, take a look at [these source files](https://github.com/BitBagCommerce/SyliusWishlistPlugin/tree/master/tests/Application/templates/bundles/SyliusShopBundle).
## Customization
----
### Available services you can [decorate](https://symfony.com/doc/current/service_container/service_decoration.html) and forms you can [extend](http://symfony.com/doc/current/form/create_form_type_extension.html)
Run the below command to see what Symfony services are shared with this plugin:
```bash
$ bin/console debug:container | grep bitbag_sylius_wishlist_plugin
```

### Parameters you can override in your parameters.yml(.dist) file
```yml
$ bin/console debug:container --parameters | grep bitbag
$ bin/console debug:container --parameters | grep wishlist
```

## Testing
----

```bash
$ composer install
$ cd tests/Application
$ yarn install
$ yarn build
$ bin/console assets:install public -e test
$ bin/console doctrine:schema:create -e test
$ bin/console server:run 127.0.0.1:8080 -d public -e test
$ open http://localhost:8080
$ cd ../..
$ vendor/bin/behat
$ vendor/bin/phpspec run
```



# About us

---
Expand Down Expand Up @@ -186,7 +84,7 @@ If you need some help with Sylius development, don't be hesitated to contact us

## Community

----
----

For online communication, we invite you to chat with us & other users on [Sylius Slack](https://sylius-devs.slack.com/).

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"symfony/web-server-bundle": "^4.4|^5.2",
"symfony/webpack-encore-bundle": "^1.12",
"vimeo/psalm": "4.4.1",
"slevomat/coding-standard": "~6.0",
"symfony/dependency-injection": "<4.4.19 || >=5.0.0 <5.2.2"
},
"conflict": {
"doctrine/dbal": "^3.0",
"symfony/symfony": "4.1.8",
"symfony/browser-kit": "4.1.8",
"symfony/dom-crawler": "4.1.8",
Expand Down
73 changes: 73 additions & 0 deletions doc/01-installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# BitBag SyliusWishlistPlugin

- [⬅️ Back](../README.md#overview)
- [➡️ Usage](./02-usage.md)

## Installation


1. *We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.*

```bash
$ composer require bitbag/wishlist-plugin
```

2. Add plugin dependencies to your `config/bundles.php` file:
```php
// config/bundles.php

return [
...

BitBag\SyliusWishlistPlugin\BitBagSyliusWishlistPlugin::class => ['all' => true],
];
```

3. Import required config in your `config/packages/_sylius.yaml` file:
```yaml
# config/packages/_sylius.yaml

imports:
...

- { resource: "@BitBagSyliusWishlistPlugin/Resources/config/config.yml" }
```
4. Import routing in your `config/routes.yaml` file:

```yaml
# config/routes.yaml
bitbag_sylius_wishlist_plugin:
resource: "@BitBagSyliusWishlistPlugin/Resources/config/routing.yml"
```

5. Update your database

```bash
$ bin/console doctrine:migrations:migrate
```

**Note:** If you are running it on production, add the `-e prod` flag to this command.

**Note:** If you are updating this plugin from version 1.4.x you need to run:

```bash
$ bin/console doctrine:migrations:version BitBag\\SyliusWishlistPlugin\\Migrations\\Version20201029161558 --add --no-interaction
```

6. Add plugin assets to your project

We recommend you to use Webpack (Encore), for which we have prepared four different instructions on how to add this plugin's assets to your project:

- [Import webpack config](./01.1-webpack-config.md)*
- [Add entry to existing config](./01.2-webpack-entry.md))
- [Import entries in your entry.js files](./01.3-import-entry.md))
- [Your own custom config](./01.4-custom-solution.md))

<small>* Default option for plugin development</small>


However, if you are not using Webpack, here are instructions on how to add optimized and compressed assets directly to your project templates:

- [Non webpack solution](./01.5-non-webpack.md)
65 changes: 65 additions & 0 deletions doc/01.1-webpack-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# BitBag SyliusWishlistPlugin

- [⬅️ Back](./01-installation.md)

## Installation - Import Webpack Config

- ✔️ Completely independent configuration
- ✔️ No need to add plugin assets globally (you can add it to specific pages)

<br>

1. Import plugin's `webpack.config.js` file

```js
// webpack.config.js
const [ bitbagWishlistShop, bitbagWishlistAdmin ] = require('./vendor/bitbag/wishlist-plugin/webpack.config.js')
...

module.exports = [..., bitbagWishlistShop, bitbagWishlistAdmin];
```

2. Add new packages in `./config/packages/assets.yaml`

```yml
# config/packages/assets.yaml

framework:
assets:
packages:
# ...
wishlist_shop:
json_manifest_path: '%kernel.project_dir%/public/build/bitbag/wishlist/shop/manifest.json'
wishlist_admin:
json_manifest_path: '%kernel.project_dir%/public/build/bitbag/wishlist/admin/manifest.json'
```
3. Add new build paths in `./config/packages/webpack_encore.yml`

```yml
# config/packages/webpack_encore.yml
webpack_encore:
builds:
# ...
wishlist_shop: '%kernel.project_dir%/public/build/bitbag/wishlist/shop'
wishlist_admin: '%kernel.project_dir%/public/build/bitbag/wishlist/admin'
```

4. Add encore functions to your templates

```twig
{# @SyliusShopBundle/_scripts.html.twig #}
{{ encore_entry_script_tags('bitbag-wishlist-shop', null, 'wishlist_shop') }}
{# @SyliusShopBundle/_styles.html.twig #}
{{ encore_entry_link_tags('bitbag-wishlist-shop', null, 'wishlist_shop') }}
{# @SyliusAdminBundle/_scripts.html.twig #}
{{ encore_entry_script_tags('bitbag-wishlist-admin', null, 'wishlist_admin') }}
{# @SyliusAdminBundle/_styles.html.twig #}
{{ encore_entry_link_tags('bitbag-wishlist-admin', null, 'wishlist_admin') }}
```

5. Run `yarn encore dev` or `yarn encore production`
39 changes: 39 additions & 0 deletions doc/01.2-webpack-entry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# BitBag SyliusWishlistPlugin

- [⬅️ Back](./01-installation.md)

## Installation - Add new entry to existing configs

- ✔️ Same webpack configuration for plugin and project assets
- ✔️ No need to add plugin assets globally (you can add it to specific pages)

<br>

1. Add new entries to your `webpack.config.js`
```js
// ./webpack.config.js

// Shop config
.addEntry('bitbag-wishlist-shop', 'vendor/bitbag/wishlist-plugin/src/Resources/assets/shop/entry.js')

// Admin config
.addEntry('bitbag-wishlist-admin', 'vendor/bitbag/wishlist-plugin/src/Resources/assets/admin/entry.js')
```

2. Add encore functions to your templates

```twig
{# @SyliusShopBundle/_scripts.html.twig #}
{{ encore_entry_script_tags('bitbag-wishlist-shop', null, 'shop') }}
{# @SyliusShopBundle/_styles.html.twig #}
{{ encore_entry_link_tags('bitbag-wishlist-shop', null, 'shop') }}
{# @SyliusAdminBundle/_scripts.html.twig #}
{{ encore_entry_script_tags('bitbag-wishlist-admin', null, 'admin') }}
{# @SyliusAdminBundle/_styles.html.twig #}
{{ encore_entry_link_tags('bitbag-wishlist-admin', null, 'admin') }}
```

3. Run `yarn encore dev` or `yarn encore production`
Loading

0 comments on commit 26678fa

Please sign in to comment.