2023-03-05 21:18:56 +03:00
|
|
|
# Building AFFiNE Web
|
2023-02-09 10:34:43 +03:00
|
|
|
|
2023-03-09 09:36:51 +03:00
|
|
|
> **Note**
|
|
|
|
> For developing & building desktop client app, please refer to [building-desktop-client-app.md](./building-desktop-client-app.md)
|
|
|
|
|
2023-02-09 10:34:43 +03:00
|
|
|
## Table of Contents
|
|
|
|
|
|
|
|
- [Prerequisites](#prerequisites)
|
|
|
|
- [Setup Environment](#setup-environment)
|
2023-03-05 21:18:56 +03:00
|
|
|
- [Start Development Server](#start-development-server)
|
2023-02-09 10:34:43 +03:00
|
|
|
- [Testing](#testing)
|
|
|
|
|
|
|
|
## Prerequisites
|
|
|
|
|
|
|
|
We suggest develop our product under node.js LTS(Long-term support) version
|
|
|
|
|
|
|
|
### Option 1: Manually install node.js
|
|
|
|
|
|
|
|
install [Node LTS version](https://nodejs.org/en/download)
|
|
|
|
|
|
|
|
> Up to now, the major node.js version is 18.x
|
|
|
|
|
|
|
|
### Option 2: Use node version manager
|
|
|
|
|
|
|
|
install [nvm](https://github.com/nvm-sh/nvm)
|
|
|
|
|
|
|
|
```sh
|
2023-03-21 08:12:42 +03:00
|
|
|
nvm install 18
|
|
|
|
nvm use 18
|
2023-02-09 10:34:43 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Setup Environment
|
|
|
|
|
2023-05-22 15:18:43 +03:00
|
|
|
This setup requires modern yarn (currently `3.x`), run this if your yarn version is `1.x`
|
2023-04-20 08:25:10 +03:00
|
|
|
|
|
|
|
Reference: [Yarn installation doc](https://yarnpkg.com/getting-started/install)
|
|
|
|
|
|
|
|
```sh
|
|
|
|
corepack enable
|
2023-05-22 15:18:43 +03:00
|
|
|
corepack prepare yarn@stable --activate
|
2023-04-20 08:25:10 +03:00
|
|
|
```
|
|
|
|
|
2023-02-09 10:34:43 +03:00
|
|
|
```sh
|
|
|
|
# install dependencies
|
2023-03-21 08:12:42 +03:00
|
|
|
yarn install
|
2023-02-09 10:34:43 +03:00
|
|
|
```
|
|
|
|
|
2023-03-05 21:18:56 +03:00
|
|
|
## Start Development Server
|
2023-02-09 10:34:43 +03:00
|
|
|
|
2023-03-21 08:12:42 +03:00
|
|
|
### Option 1: Local OctoBase
|
|
|
|
|
|
|
|
```shell
|
|
|
|
# Run OctoBase container in background
|
2023-03-28 06:08:40 +03:00
|
|
|
docker pull ghcr.io/toeverything/cloud-self-hosted:nightly-latest
|
2023-05-22 15:18:43 +03:00
|
|
|
docker run --env=SIGN_KEY=test123 --env=RUST_LOG=debug --env=JWST_DEV=1 --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --workdir=/app -p 127.0.0.1:3000:3000 --runtime=runc -d ghcr.io/toeverything/cloud-self-hosted:nightly-latest
|
2023-02-09 10:34:43 +03:00
|
|
|
```
|
|
|
|
|
2023-03-21 08:12:42 +03:00
|
|
|
```shell
|
|
|
|
# Run AFFiNE Web in development mode
|
|
|
|
yarn dev:local
|
|
|
|
```
|
|
|
|
|
|
|
|
### Option 2: Remote OctoBase
|
|
|
|
|
|
|
|
```shell
|
|
|
|
yarn dev
|
|
|
|
```
|
|
|
|
|
|
|
|
you might need set environment variables in `.env.local` file.
|
|
|
|
See our [template](../apps/web/.env.local.template).
|
|
|
|
|
|
|
|
Then, the playground page should work at [http://localhost:8080/](http://localhost:8080/)
|
2023-02-09 10:34:43 +03:00
|
|
|
|
2023-03-05 21:18:56 +03:00
|
|
|
For more details, see [apps/web/README.md](../apps/web/README.md)
|
|
|
|
|
2023-02-09 10:34:43 +03:00
|
|
|
## Testing
|
|
|
|
|
2023-03-21 08:12:42 +03:00
|
|
|
> Local OctoBase is required for testing. Otherwise, the affine part of the tests will fail.
|
|
|
|
|
2023-02-09 10:34:43 +03:00
|
|
|
Adding test cases is strongly encouraged when you contribute new features and bug fixes.
|
|
|
|
|
|
|
|
We use [Playwright](https://playwright.dev/) for E2E test, and [vitest](https://vitest.dev/) for unit test.
|
|
|
|
|
|
|
|
To test locally, please make sure browser binaries are already installed via `npx playwright install`. Then there are multi commands to choose from:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
# run tests in headless mode in another terminal window
|
2023-03-21 08:12:42 +03:00
|
|
|
yarn test
|
2023-02-09 10:34:43 +03:00
|
|
|
```
|