|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Due to its nature, the Symfony UX Toolkit requires a specific setup to be able to |
| 4 | +develop and test it properly. Please follow the instructions below to set up your |
| 5 | +development environment. |
| 6 | + |
| 7 | +## Setting up the development environment |
| 8 | + |
| 9 | +First, ensure to have followed the [Symfony UX's Contribution Guide](https://github.com/symfony/ux/blob/2.x/CONTRIBUTING.md) to set up your fork of the main repository, install dependencies, etc. |
| 10 | + |
| 11 | +Then, install UX Toolkit dependencies: |
| 12 | +```shell |
| 13 | +# src/Toolkit |
| 14 | +composer install |
| 15 | +``` |
| 16 | + |
| 17 | +## Preview kits |
| 18 | + |
| 19 | +For the moment, kits can only be previewed by the Symfony UX Website. installation instructions can be found at [Symfony UX Website's `README.md`](https://github.com/symfony/ux/tree/2.x/ux.symfony.com). |
| 20 | + |
| 21 | +Then, run the following commands from the `ux.symfony.com/` directory: |
| 22 | +```shell |
| 23 | +# Link local UX packages |
| 24 | +php ../link |
| 25 | + |
| 26 | +# Run the local web server |
| 27 | +symfony serve -d |
| 28 | +``` |
| 29 | + |
| 30 | +When the server is running, you can access: |
| 31 | +- the UX Toolkit homepage at https://127.0.0.1:9044/toolkit, |
| 32 | +- the list of available Kits at https://127.0.0.1:9044/toolkit#kits, |
| 33 | +- a dedicated section for each Kit, e.g. https://127.0.0.1:9044/toolkit/kits/shadcn for the Shadcn UI Kit. |
| 34 | + |
| 35 | +## Kit's structure |
| 36 | + |
| 37 | +A Kit is composed of several Recipes, each providing Twig components, styles, and JavaScript. |
| 38 | + |
| 39 | +1. Each kit is located in the `src/Toolkit/kits/` directory. |
| 40 | +2. Each kit has its own directory named after the kit, e.g. `shadcn/` for the Shadcn UI Kit. |
| 41 | +3. Each kit directory contains: |
| 42 | + - a `INSTALL.md` file with installation instructions, it is used by the UX Website, |
| 43 | + - a `manifest.json` file containing metadata about the kit: its name, description, license, homepage, etc., |
| 44 | + - a folder for each Recipe provided by the kit, e.g. `button/` for the Button Recipe, |
| 45 | +4. Each Recipe directory contains: |
| 46 | + - a `manifest.json` file containing metadata about the Recipe: its type, name, description, files to copy, dependencies, etc., |
| 47 | + - a `EXAMPLES.md` file with usage examples, it is used by the UX Website. |
| 48 | + - based on the "files to copy" setting, the Kit may contain subdirectories like: |
| 49 | + - `templates/components/` for Twig components, |
| 50 | + - `assets/controllers/` for Stimulus controllers, |
| 51 | + - the "files to copy" structure is flexible, but we recommend to follow the above conventions for consistency accross kits and Symfony apps. |
| 52 | + |
| 53 | +## Working with kits |
| 54 | + |
| 55 | +After setting up your development environment and the UX Website locally, you can start modifying the kits and test them. |
| 56 | + |
| 57 | +Adding new recipes, or modifying existing ones, will be automatically reflected in the UX Website, thanks to the local linking done with the `php link` command. |
| 58 | +You can then preview your changes by navigating to the relevant sections in the UX Website. |
| 59 | + |
| 60 | +### Running tests & snapshots |
| 61 | + |
| 62 | +Tests use snapshots to ensure that the kits and their recipes work as expected, and to prevent regressions. |
| 63 | + |
| 64 | +Snapshots are created through all Twig code examples provided in each Recipe's `EXAMPLES.md` file. The Twig code examples are rendered in an isolated environment. |
| 65 | + |
| 66 | +The rendered output is then compared to stored snapshots to ensure that the Kit's recipes work as expected. |
| 67 | + |
| 68 | +To update the snapshots, run the following command from the `src/Toolkit/` directory: |
| 69 | +```shell |
| 70 | +# Remove existing snapshots, may be useful if some Twig code examples were removed |
| 71 | +rm -fr tests/Functional/__snapshots__ |
| 72 | + |
| 73 | +# Run tests and update snapshots |
| 74 | +php vendor/bin/simple-phpunit -d --update-snapshots |
| 75 | + |
| 76 | +# Add the updated snapshots to git |
| 77 | +git add tests/Functional/__snapshots__ |
| 78 | +``` |
0 commit comments