1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/README.md

78 lines
2.1 KiB
Markdown
Raw Normal View History

# frontend
This directory contains the Unleash Admin UI frontend app.
## Run with a local instance of the unleash-api
chore: simplify package scripts (#3736) # Simplify package scripts This PR's purpose is to raise a discussion surrounding our current package scripts. It includes some suggestions that aim to simplify the scripts and hopefully bring a much more straightforward approach to developing and contributing to Unleash. Building (prod) should only happen **explicitly** and when needed. ## Before PR (current behavior) - Clone the project; - Open 2 terminals: One for `unleash` and another for `unleash/frontend`; - On `unleash`: - Run `yarn` (which will also build, for some reason?); - Run `yarn start:dev` to start backend in dev mode (`tsc-watch`); - On `unleash/frontend`: - Run `yarn` (which will also build, for some reason?); - Run `yarn start` to start frontend in dev mode (`vite`); So it seems to me like we build unnecessarily every time we install dependencies. Neither dev scripts need to build the project, as backend uses `tsc-watch` and frontend uses `vite`. I'm unsure why this is the case, as building can take a very long time. ![image](https://github.com/Unleash/unleash/assets/14320932/5ecb7df1-e5b4-4d70-ba7e-97119f5d1116) There's also some complexity in the way we need to split the terminal to `cd` into `frontend` and treat it as a different project. The fact that we have different script names is also confusing (`yarn start`, `yarn start:dev`, etc). ## After PR - Clone the project; - Run `yarn` to install all dependencies; - Run `yarn dev` to get started developing Unleash; Running `yarn` should take care of everything needed to start developing. This includes installing dependencies for frontend as well. It should not build projects if we are not being explicit about it, especially since we don't need to build them at this stage. ![image](https://github.com/Unleash/unleash/assets/14320932/614e42fc-3467-432f-91fc-624b1b35c7c1) Running `yarn dev` should start the project in dev mode. This means running both projects in `dev` mode, which for `backend` means running `tsc-watch` and for `frontend` means running `vite`. Here this PR attempts to provide a better DX by using [concurrently](https://www.npmjs.com/package/concurrently) and [wait-on](https://www.npmjs.com/package/wait-on) - This means both tasks are ran simultaneously, stdout is labeled accordingly, and are stopped together. It also means that `frontend` waits for `backend` to be serving at `4242` before starting, since `frontend` starts pretty much immediately with `vite` and `backend` takes a bit longer. Of course, when the `backend` is hot-reloading you may still find some `ECONNREFUSED`s on `frontend` stdout while it recompiles. ![image](https://github.com/Unleash/unleash/assets/14320932/8bde8ee2-3cad-4e3f-a0db-9eed60cfb04d) No more splitting your terminal and treating `frontend` as a separate project. ## Discussion points Maybe there's a better alternative to `tsc-watch`? I briefly explored some alternatives and while they had a much faster starting speed, hot-reload was sometimes slower. IMO we should aspire to run `src/server-dev.ts` directly and only compile when needed. Running `dev:backend` still serves a version of the frontend (at 4242). **Why? Can we remove that behavior?** I can't imagine a scenario in dev where we wouldn't want to run the latest version of the frontend with `vite`. ~~**Note:** This PR removes all other out-of-scope scripts to focus on this revamp. If we decide to merge it, we should evaluate what other existing scripts we still want to include. May be a good opportunity to clean up unused ones and only include the ones we really use. This includes scripts that our GH actions rely on.~~ **Update:** In an effort to minimize impact surface of this PR and make it a bit more ready for merging: - It updates some docs in https://github.com/Unleash/unleash/pull/3736/commits/2a4ff805e87b65d9c1256effaa189ddcccba15fb and https://github.com/Unleash/unleash/pull/3736/commits/1bbc4882519b5a82e3116f0be255ad24a6f3ce53 to reflect our new simplified flow; - It includes the old package scripts for now in https://github.com/Unleash/unleash/pull/3736/commits/039bc04699ac880e491fd3ce01f9bcd6f97a94b9; - It updates some of our GH actions to reflect the new scripts in https://github.com/Unleash/unleash/pull/3736/commits/7782cb9b12e37ee844507e41ef2b7137eaf55666; Given its current status I'll promote the PR to "ready for review". I still think we should have a second look at our existing scripts and GH actions to see what we really need and/or should adapt, but it should be a team effort so we have a broader context. Maybe on a follow-up PR. Does this require any changes to related projects (e.g. Enterprise)? --------- Co-authored-by: Gastón Fournier <gaston@getunleash.io>
2023-05-12 12:23:22 +02:00
Refer to the [Contributing to Unleash](../CONTRIBUTING.md#how-to-run-the-project) guide for instructions.
The frontend dev server runs (in port 3000) simultaneously with the backend dev server (in port 4242):
```
2021-10-08 22:20:47 +02:00
yarn install
chore: simplify package scripts (#3736) # Simplify package scripts This PR's purpose is to raise a discussion surrounding our current package scripts. It includes some suggestions that aim to simplify the scripts and hopefully bring a much more straightforward approach to developing and contributing to Unleash. Building (prod) should only happen **explicitly** and when needed. ## Before PR (current behavior) - Clone the project; - Open 2 terminals: One for `unleash` and another for `unleash/frontend`; - On `unleash`: - Run `yarn` (which will also build, for some reason?); - Run `yarn start:dev` to start backend in dev mode (`tsc-watch`); - On `unleash/frontend`: - Run `yarn` (which will also build, for some reason?); - Run `yarn start` to start frontend in dev mode (`vite`); So it seems to me like we build unnecessarily every time we install dependencies. Neither dev scripts need to build the project, as backend uses `tsc-watch` and frontend uses `vite`. I'm unsure why this is the case, as building can take a very long time. ![image](https://github.com/Unleash/unleash/assets/14320932/5ecb7df1-e5b4-4d70-ba7e-97119f5d1116) There's also some complexity in the way we need to split the terminal to `cd` into `frontend` and treat it as a different project. The fact that we have different script names is also confusing (`yarn start`, `yarn start:dev`, etc). ## After PR - Clone the project; - Run `yarn` to install all dependencies; - Run `yarn dev` to get started developing Unleash; Running `yarn` should take care of everything needed to start developing. This includes installing dependencies for frontend as well. It should not build projects if we are not being explicit about it, especially since we don't need to build them at this stage. ![image](https://github.com/Unleash/unleash/assets/14320932/614e42fc-3467-432f-91fc-624b1b35c7c1) Running `yarn dev` should start the project in dev mode. This means running both projects in `dev` mode, which for `backend` means running `tsc-watch` and for `frontend` means running `vite`. Here this PR attempts to provide a better DX by using [concurrently](https://www.npmjs.com/package/concurrently) and [wait-on](https://www.npmjs.com/package/wait-on) - This means both tasks are ran simultaneously, stdout is labeled accordingly, and are stopped together. It also means that `frontend` waits for `backend` to be serving at `4242` before starting, since `frontend` starts pretty much immediately with `vite` and `backend` takes a bit longer. Of course, when the `backend` is hot-reloading you may still find some `ECONNREFUSED`s on `frontend` stdout while it recompiles. ![image](https://github.com/Unleash/unleash/assets/14320932/8bde8ee2-3cad-4e3f-a0db-9eed60cfb04d) No more splitting your terminal and treating `frontend` as a separate project. ## Discussion points Maybe there's a better alternative to `tsc-watch`? I briefly explored some alternatives and while they had a much faster starting speed, hot-reload was sometimes slower. IMO we should aspire to run `src/server-dev.ts` directly and only compile when needed. Running `dev:backend` still serves a version of the frontend (at 4242). **Why? Can we remove that behavior?** I can't imagine a scenario in dev where we wouldn't want to run the latest version of the frontend with `vite`. ~~**Note:** This PR removes all other out-of-scope scripts to focus on this revamp. If we decide to merge it, we should evaluate what other existing scripts we still want to include. May be a good opportunity to clean up unused ones and only include the ones we really use. This includes scripts that our GH actions rely on.~~ **Update:** In an effort to minimize impact surface of this PR and make it a bit more ready for merging: - It updates some docs in https://github.com/Unleash/unleash/pull/3736/commits/2a4ff805e87b65d9c1256effaa189ddcccba15fb and https://github.com/Unleash/unleash/pull/3736/commits/1bbc4882519b5a82e3116f0be255ad24a6f3ce53 to reflect our new simplified flow; - It includes the old package scripts for now in https://github.com/Unleash/unleash/pull/3736/commits/039bc04699ac880e491fd3ce01f9bcd6f97a94b9; - It updates some of our GH actions to reflect the new scripts in https://github.com/Unleash/unleash/pull/3736/commits/7782cb9b12e37ee844507e41ef2b7137eaf55666; Given its current status I'll promote the PR to "ready for review". I still think we should have a second look at our existing scripts and GH actions to see what we really need and/or should adapt, but it should be a team effort so we have a broader context. Maybe on a follow-up PR. Does this require any changes to related projects (e.g. Enterprise)? --------- Co-authored-by: Gastón Fournier <gaston@getunleash.io>
2023-05-12 12:23:22 +02:00
yarn dev
2016-11-10 14:26:24 +01:00
```
docs: Remove/update references to Heroku (#2099) ## What This PR removes or updates references in the docs to Heroku. Most of the code samples have been replaced with a more generic `unleash.example.com` url, while other references have been removed or updated. Also removes old OpenAPI files that are out of date and redundant with the new generation. ## Background Come November and Heroku will no longer offer free deployments of Unleash, so it's about time we remove that claim. Links to the heroku instance are also outdated because we don't have that instance running anymore. Finally, the OpenAPI files we do have there are old and static, so they don't match the current reality. ## Commits * Meta: update ignore file to ignore autogenerated docs I must've missed the ignore file when looking for patterns. * docs: delete old openapi file. This seems to have been a holdover from 2020 and is probably hand-written. It has been superseded by the new autogenerated OpenAPI docs. * docs: add notes for heroku changes to the frontend readme and pkg * docs: remove old openapi article and add redirects to new openapi * docs: fix link in overview doc: point to GitHub instead of heroku * docs: update quickstart docs with new heroku details * docs: remove reference to crashing heroku instance * docs: remove references to herokuapp in code samples * docs: add a placeholder comment * docs: update references for heroku updates * docs: keep using unleash4 for enterprise * docs: remove start:heroku script in favor of start:sandbox * docs: remove 'deploy on heroku button' Now that it's not free anymore (or won't be very shortly), let's remove it. * docs: remove extra newline
2022-10-19 14:02:00 +02:00
## Run with a sandbox instance of the Unleash API
docs: Remove/update references to Heroku (#2099) ## What This PR removes or updates references in the docs to Heroku. Most of the code samples have been replaced with a more generic `unleash.example.com` url, while other references have been removed or updated. Also removes old OpenAPI files that are out of date and redundant with the new generation. ## Background Come November and Heroku will no longer offer free deployments of Unleash, so it's about time we remove that claim. Links to the heroku instance are also outdated because we don't have that instance running anymore. Finally, the OpenAPI files we do have there are old and static, so they don't match the current reality. ## Commits * Meta: update ignore file to ignore autogenerated docs I must've missed the ignore file when looking for patterns. * docs: delete old openapi file. This seems to have been a holdover from 2020 and is probably hand-written. It has been superseded by the new autogenerated OpenAPI docs. * docs: add notes for heroku changes to the frontend readme and pkg * docs: remove old openapi article and add redirects to new openapi * docs: fix link in overview doc: point to GitHub instead of heroku * docs: update quickstart docs with new heroku details * docs: remove reference to crashing heroku instance * docs: remove references to herokuapp in code samples * docs: add a placeholder comment * docs: update references for heroku updates * docs: keep using unleash4 for enterprise * docs: remove start:heroku script in favor of start:sandbox * docs: remove 'deploy on heroku button' Now that it's not free anymore (or won't be very shortly), let's remove it. * docs: remove extra newline
2022-10-19 14:02:00 +02:00
Alternatively, instead of running unleash-api on localhost, you can use a remote instance:
```
cd ./frontend
2021-10-08 22:20:47 +02:00
yarn install
docs: Remove/update references to Heroku (#2099) ## What This PR removes or updates references in the docs to Heroku. Most of the code samples have been replaced with a more generic `unleash.example.com` url, while other references have been removed or updated. Also removes old OpenAPI files that are out of date and redundant with the new generation. ## Background Come November and Heroku will no longer offer free deployments of Unleash, so it's about time we remove that claim. Links to the heroku instance are also outdated because we don't have that instance running anymore. Finally, the OpenAPI files we do have there are old and static, so they don't match the current reality. ## Commits * Meta: update ignore file to ignore autogenerated docs I must've missed the ignore file when looking for patterns. * docs: delete old openapi file. This seems to have been a holdover from 2020 and is probably hand-written. It has been superseded by the new autogenerated OpenAPI docs. * docs: add notes for heroku changes to the frontend readme and pkg * docs: remove old openapi article and add redirects to new openapi * docs: fix link in overview doc: point to GitHub instead of heroku * docs: update quickstart docs with new heroku details * docs: remove reference to crashing heroku instance * docs: remove references to herokuapp in code samples * docs: add a placeholder comment * docs: update references for heroku updates * docs: keep using unleash4 for enterprise * docs: remove start:heroku script in favor of start:sandbox * docs: remove 'deploy on heroku button' Now that it's not free anymore (or won't be very shortly), let's remove it. * docs: remove extra newline
2022-10-19 14:02:00 +02:00
yarn run start:sandbox
```
## Running end-to-end tests
We have a set of Cypress tests that run on the build before a PR can be merged
so it's important that you check these yourself before submitting a PR.
On the server the tests will run against the deployed Heroku app so this is what you probably want to test against:
```
docs: Remove/update references to Heroku (#2099) ## What This PR removes or updates references in the docs to Heroku. Most of the code samples have been replaced with a more generic `unleash.example.com` url, while other references have been removed or updated. Also removes old OpenAPI files that are out of date and redundant with the new generation. ## Background Come November and Heroku will no longer offer free deployments of Unleash, so it's about time we remove that claim. Links to the heroku instance are also outdated because we don't have that instance running anymore. Finally, the OpenAPI files we do have there are old and static, so they don't match the current reality. ## Commits * Meta: update ignore file to ignore autogenerated docs I must've missed the ignore file when looking for patterns. * docs: delete old openapi file. This seems to have been a holdover from 2020 and is probably hand-written. It has been superseded by the new autogenerated OpenAPI docs. * docs: add notes for heroku changes to the frontend readme and pkg * docs: remove old openapi article and add redirects to new openapi * docs: fix link in overview doc: point to GitHub instead of heroku * docs: update quickstart docs with new heroku details * docs: remove reference to crashing heroku instance * docs: remove references to herokuapp in code samples * docs: add a placeholder comment * docs: update references for heroku updates * docs: keep using unleash4 for enterprise * docs: remove start:heroku script in favor of start:sandbox * docs: remove 'deploy on heroku button' Now that it's not free anymore (or won't be very shortly), let's remove it. * docs: remove extra newline
2022-10-19 14:02:00 +02:00
yarn run start:sandbox
```
In a different shell, you can run the tests themselves:
```
yarn run e2e:heroku
```
If you need to test against patches against a local server instance,
you'll need to run that, and then run the end to end tests using:
```
yarn run e2e
```
You may also need to test that a feature works against the enterprise version of unleash.
Assuming the Heroku instance is still running, this can be done by:
2019-10-05 09:55:08 +02:00
```
yarn run start:enterprise
yarn run e2e
```
## Generating the OpenAPI client
The frontend uses an OpenAPI client generated from the backend's OpenAPI spec.
Whenever there are changes to the backend API, the client should be regenerated:
For now we only use generated types (src/openapi/models).
We will use methods (src/openapi/apis) for new features soon.
```
yarn gen:api
rm -rf src/openapi/apis
```
clean up `src/openapi/index.ts` imports, only keep first line `export * from './models';`
This script assumes that you have a running instance of the enterprise backend at `http://localhost:4242`.
The new OpenAPI client will be generated from the runtime schema of this instance.
The target URL can be changed by setting the `UNLEASH_OPENAPI_URL` env var.
## Analyzing bundle size
`npx vite-bundle-visualizer` in the root of the frontend directory