2023-03-05 21:18:56 +03:00
# Building AFFiNE Web
2023-02-09 10:34:43 +03:00
2023-08-06 19:45:30 +03:00
> **Warning**:
>
> This document has not been updated for a while.
> If you find any outdated information, please feel free to open an issue or submit a PR.
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
2023-06-16 08:15:42 +03:00
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
2023-06-16 08:15:42 +03:00
#### 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
2023-06-16 08:15:42 +03:00
#### Option 2: Use node version manager
2023-02-09 10:34:43 +03:00
2023-09-01 02:50:54 +03:00
install [fnm ](https://github.com/Schniz/fnm )
2023-02-09 10:34:43 +03:00
```sh
2023-09-01 02:50:54 +03:00
fnm use
2023-02-09 10:34:43 +03:00
```
2023-06-16 08:15:42 +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
2023-11-02 06:56:02 +03:00
This setup requires modern yarn (currently `4.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-12-27 12:21:32 +03:00
### Clone repository
#### Linux & MacOS
```sh
git clone https://github.com/toeverything/AFFiNE
```
#### Windows
In our codebase, we use symbolic links. Due to the security design of Windows, the creation of symbolic links requires administrator privileges. This is part of the security policy settings of Windows, and more information can be found at [Security Policy Settings for Creating Symbolic Links ](https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links ).
For detailed guidance on enabling this feature, please refer to the official documentation: [Enable Developer Mode on Windows ](https://learn.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development ).
Once Developer Mode is enabled, execute the following command with administrator privileges:
```sh
# Enable symbolic links
git config --global core.symlinks true
# Clone the repository, also need to be run with administrator privileges
git clone https://github.com/toeverything/AFFiNE
```
2023-06-16 08:15:42 +03:00
### Build Native Dependencies
2023-02-09 10:34:43 +03:00
2023-10-18 18:30:08 +03:00
Run the following script. It will build the native module at [`/packages/frontend/native` ](/packages/frontend/native ) and build Node.js binding using [NAPI.rs ](https://napi.rs/ ).
2023-08-02 18:32:22 +03:00
This could take a while if you build it for the first time.
2023-08-08 10:25:56 +03:00
Note: use `strip` from system instead of `binutils` if you are running 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
```
2023-06-16 08:15:42 +03:00
yarn workspace @affine/native build
2023-03-21 08:12:42 +03:00
```
2023-09-01 02:50:54 +03:00
### Build Server Dependencies
2023-03-21 08:12:42 +03:00
2023-09-01 02:50:54 +03:00
```sh
yarn workspace @affine/storage build
2023-06-16 08:15:42 +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.
2023-05-30 08:14:10 +03:00
To test locally, please make sure browser binaries are already installed via `npx playwright install` .
2023-09-01 02:50:54 +03:00
Also make sure you have built the `@affine/core` workspace before running E2E tests.
### Unit Test
2023-02-09 10:34:43 +03:00
```sh
2023-03-21 08:12:42 +03:00
yarn test
2023-02-09 10:34:43 +03:00
```
2023-05-30 08:14:10 +03:00
2023-09-01 02:50:54 +03:00
### E2E Test
2023-05-30 08:14:10 +03:00
2023-09-01 02:50:54 +03:00
```shell
2023-12-27 05:49:59 +03:00
# there are `affine-local`, `affine-migration`, `affine-local`, `affine-prototype` e2e tests,
2023-09-01 02:50:54 +03:00
# which are run under different situations.
cd tests/affine-local
yarn e2e
```