AFFiNE/docs/BUILDING.md

103 lines
2.7 KiB
Markdown
Raw Normal View History

2023-03-05 21:18:56 +03:00
# Building AFFiNE Web
2023-02-09 10:34:43 +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
AFFiNE client has both **Node.js** & **Rust** toolchains.
### Install Node.js
2023-02-09 10:34:43 +03:00
We suggest develop our product under node.js LTS(Long-term support) version
#### Option 1: Manually install node.js
2023-02-09 10:34:43 +03:00
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
2023-02-09 10:34:43 +03:00
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
```
### Install Rust Tools
Please follow the official guide at https://www.rust-lang.org/tools/install.
### Setup Node.js Environment
2023-02-09 10:34:43 +03:00
This setup requires modern yarn (currently `3.x`), run this if your yarn version is `1.x`
Reference: [Yarn installation doc](https://yarnpkg.com/getting-started/install)
```sh
corepack enable
corepack prepare yarn@stable --activate
```
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
```
### Build Native Dependencies
2023-02-09 10:34:43 +03:00
Run the following script. It will build the native module at [`/packages/native`](/packages/native) and build Node.js binding using [NAPI.rs](https://napi.rs/).
This could take a while if you build it for the first time.
Note: use `strip` from system instead of `binutils` if you are runinng MacOS. [see problem here](https://github.com/toeverything/AFFiNE/discussions/2840)
2023-03-21 08:12:42 +03:00
2023-02-09 10:34:43 +03:00
```
yarn workspace @affine/native build
2023-03-21 08:12:42 +03:00
```
2023-06-29 07:13:35 +03:00
## Debugging the Electron App
2023-03-21 08:12:42 +03:00
You need to run two scripts to run the app in development mode
Firstly, run the web app which is served at :8080
2023-06-29 07:13:35 +03:00
```
2023-06-29 07:13:35 +03:00
yarn dev # you may want to chose `dev - 100.84.105.99:11001` when selecting the dev server
2023-03-21 08:12:42 +03:00
```
Secondly, bring up the electron app
2023-03-21 08:12:42 +03:00
```
yarn workspace @affine/electron dev
```
2023-02-09 10:34:43 +03:00
If everything goes well, you should see the AFFiNE App window popping up in a few seconds. 🎉
2023-03-05 21:18:56 +03:00
2023-02-09 10:34:43 +03:00
## Testing
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`.
Also make sure you have built the `@affine/web` workspace before running E2E tests.
2023-02-09 10:34:43 +03:00
```sh
yarn build
2023-02-09 10:34:43 +03:00
# 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
```
## Troubleshooting
> I ran `yarn start -p 8080` after `yarn build` but the index page returned 404.
Try stopping your development server (initialized by `yarn dev:local` or something) and running `yarn build` again.