Update scripts and documentation to use nx and new monorepo architecture (#2912)

* Update scripts and documentation to use nx and new monorepo architecture

* Start fixing docker

* Migrate eslint plugin and postgres setup

* Fix docker

* Fix patches

* Fix

* fix: wip try to fix the patches

* Apply patches

---------

Co-authored-by: Jérémy Magrin <jeremy.magrin@gmail.com>
This commit is contained in:
Charles Bochet
2023-12-11 10:54:57 +01:00
committed by GitHub
parent f91bb35573
commit 44baaee28e
67 changed files with 411 additions and 14097 deletions

View File

@ -57,13 +57,13 @@ You need to set some environment variables before you can work on the project. L
```bash
cd twenty
cp ./front/.env.example ./front/.env
cp ./server/.env.example ./server/.env
cp ./packages/twenty-front/.env.example ./packages/twenty-front/.env
cp ./packages/twenty-server/.env.example ./packages/twenty-server/.env
```
The default values should work out of the box, except for the postgres URL, which requires a small modification.
Open `./server/.env` and change to the following:
Open `./packages/twenty-server/.env` and change to the following:
```bash
PG_DATABASE_URL=postgres://twenty:twenty@postgres:5432/default?connection_limit=1
@ -75,14 +75,9 @@ PG_DATABASE_URL=postgres://twenty:twenty@postgres:5432/default?connection_limit=
The project includes an environment containerized with Docker and orchestrated with `docker-compose`.
This installation method will also provision a PostgreSQL container.
:::info
The configuration for the build is in the `infra/dev` folder, but you can run `make` commands directly from the root folder.
:::
```bash
make build
make -C packages/twenty-docker dev-build
```
## Step 4: Migrate & seed
@ -91,12 +86,12 @@ Before running the project, you need to initialize the database by running the m
Start the containers:
```bash
make up
make -C packages/twenty-docker dev-up
```
Setup database, run migrations, and seed:
```bash
make server-database-init
make -C packages/twenty-docker dev-server-database-init
```
## Step 5: Start Twenty
@ -104,11 +99,11 @@ make server-database-init
Run the project with the following commands from the `root` folder:
```bash
make server-start
make -C packages/twenty-docker dev-server-start
```
```bash
make front-start
make -C packages/twenty-docker dev-front-start
```
You should now have:
@ -123,12 +118,11 @@ Sign in using a seeded demo account `tim@apple.dev` (password: `Applecar2025`) t
If you don't want to use the `make` command and work directly from the container, you can also ssh directly into the container:
```bash
make sh
make -C packages/twenty-docker dev-sh
```
Then run commands through yarn:
Then run commands through yarn and nx:
```bash
cd server
yarn database:init
yarn nx run twenty-server:database:init
```

View File

@ -33,10 +33,11 @@ Windows users can install the project through WSL2. [This guide](/contributor/lo
The repository has the following structure:
```
twenty
└───docs // contains this documentation
└───front // contains the frontend code for the application
└───server // contains the backend code for the application
└───infra // contains docker configurations for development and production deployments
└───packages // contains this documentation
└───twenty-front // contains the frontend code for the application
└───twenty-server // contains the backend code for the application
└───twenty-docker // contains docker configurations for development and production build
└───many other packages your are invited to discover such as twenty-docs, twenty-ui, twenty-eslint-plugin, twenty-zapier...
```
## IDE Setup

View File

@ -23,9 +23,14 @@ In this document, you'll learn how to install the project using yarn. You should
Before you can install and use Twenty, make sure you install the following on your computer:
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- [Node v18](https://nodejs.org/en/download)
- [yarn v1](https://classic.yarnpkg.com/lang/en/docs/install/)
- [yarn v4](https://yarnpkg.com/getting-started/install).
- [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md)
:::info Note
Yarn is now shipped with Node.js nowadays, so you don't need to install it separately.
You should only have to run `corepack enable` to enable Yarn if you haven't done it yet.
:::
</TabItem>
<TabItem value="wsl" label="Windows (WSL)" >
@ -53,7 +58,7 @@ git config --global user.email "youremail@domain.com"
```bash
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
curl -o- -L https://yarnpkg.com/install.sh | bash
corepack enable
```
Close and reopen your terminal to start using nvm.
@ -94,8 +99,16 @@ git clone https://github.com/twentyhq/twenty.git
</TabItem>
</Tabs>
## Step 2: Place yourself at the root of the project
## Step 2: Set up PostgreSQL Database
```bash
cd twenty
```
All commands in the following steps should be run from the root of the project.
## Step 3: Set up PostgreSQL Database
You need to have a PostgreSQL instance available to be able to use Twenty.
You need to provision this database with a `twenty` user (password: `twenty`), a `default` database and a `test` database.
@ -105,7 +118,6 @@ You need to provision this database with a `twenty` user (password: `twenty`), a
<br /><br />
```bash
cd twenty
make provision-postgres-linux
```
@ -113,7 +125,6 @@ make provision-postgres-linux
<br /><br />
```bash
cd twenty
make provision-postgres-docker
```
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
@ -125,7 +136,6 @@ You can access this using `twenty` postgres user (password: `twenty`)
<br /><br />
```bash
cd twenty
make provision-postgres-macos-intel #for intel architecture
make provision-postgres-macos-arm #for M1/M2/M3 architecture
```
@ -134,7 +144,6 @@ make provision-postgres-macos-arm #for M1/M2/M3 architecture
<br /><br />
```bash
cd twenty
make provision-postgres-docker
```
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
@ -145,7 +154,6 @@ You can access this using `twenty` postgres user (password: `twenty`)
It's better to provision your database locally:
```bash
cd twenty
make provision-postgres-linux
```
This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432).
@ -160,57 +168,42 @@ Twenty requires you to set some environment variables. Locally, you should set t
To do so, make copies of the `.env.example` files in `/front` and `/server`:
```bash
cp ./front/.env.example ./front/.env
cp ./server/.env.example ./server/.env
cp ./packages/twenty-front/.env.example ./packages/twenty-front/.env
cp ./packages/twenty-server/.env.example ./packages/twenty-server/.env
```
## Step 4: Server setup
## Step 4: Installing dependencies
:::info
Use `nvm` to install the correct `node` version. The `server/.nvmrc` ensures all contributors use the same version.
Use `nvm` to install the correct `node` version. The `.nvmrc` ensures all contributors use the same version.
:::
To build Twenty server and seed some data into your database, run the following commands:
```bash
cd server
nvm install #recommended
nvm use #recommended
corepack enable #to enable yarn if you haven't done it yet
yarn set version stable #to set the yarn version to yarn version 4
yarn
yarn database:init
yarn start:dev
```
## Step 5: Running the project
Setup your database with the following command:
```bash
yarn nx run twenty-server:database:init
```
Start the server and the frontend:
```bash
yarn nx run twenty-server:database:init
yarn nx run twenty-server:start:dev
yarn nx run twenty-front:dev
```
Twenty's server will be up and running at [http://localhost:3000/graphql](http://localhost:3000/graphql).
## Step 5: Frontend setup
:::info
For the frontend setup, too, it's better to use `nvm` to install the right node version.
:::
To set up the frontend, run the following commands in another terminal:
```bash
cd front
nvm install #recommended
nvm use #recommended
yarn
yarn start
```
Twenty's frontend will be running at [http://localhost:3001](http://localhost:3001). Just login using the seeded demo account: `tim@apple.dev` to start using Twenty.
# Troubleshouting
## Error: Failed to execute init.sql script.
```bash
cp: ./infra/dev/postgres/init.sql: No such file or directory
psql: error: /tmp/init.sql: No such file or directory
```
If you get this error it means you are not launching the local database init script from the repo's root folder. Make sure you're in `twenty/` and not in `twenty/infra/dev/scripts`.