Skip to content

Commit

Permalink
Update yarn commands (#4644)
Browse files Browse the repository at this point in the history
* Simplify commands

* Simplify commands

* Migrate all dev commands to project.json

* Fix tests
  • Loading branch information
charlesBochet authored Mar 25, 2024
1 parent 1639b2a commit e576fe0
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
- name: Server / Run linter
run: yarn nx lint twenty-server
- name: Server / Run jest tests
run: yarn nx test twenty-server
run: yarn nx test:unit twenty-server
- name: Server / Build
run: yarn nx build twenty-server
- name: Server / Write .env
run: |
cd packages/twenty-server
cp .env.example .env
- name: Worker / Run
run: MESSAGE_QUEUE_TYPE=sync yarn nx queue:work twenty-server
run: MESSAGE_QUEUE_TYPE=sync yarn nx worker twenty-server
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"runtimeArgs": [
"nx",
"run",
"twenty-server:start:dev",
"twenty-server:start",
],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
},
"version": "0.2.1",
"scripts": {
"start": "cross-env FORCE_COLOR=true concurrently -n \"twenty-server,twenty-front\" -c \"bgBlue.bold,bgGreen.bold\" \"yarn nx start:dev twenty-server\" \"yarn nx start twenty-front\""
"start": "cross-env FORCE_COLOR=true concurrently -n \"twenty-server,twenty-front\" -c \"bgBlue.bold,bgGreen.bold\" \"yarn nx start twenty-server\" \"yarn nx start twenty-front\""
},
"workspaces": {
"packages": [
Expand Down
20 changes: 8 additions & 12 deletions packages/twenty-docs/docs/contributor/server/server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,39 @@ import DocCardList from '@theme/DocCardList';

## Useful commands

These commands should be exectued from packages/twenty-server folder.
From any other folder you can run `yarn nx <command>` twenty-server.

### First time setup

```
yarn prisma:migrate # run migrations
yarn prisma:generate # generate prisma and nestjs-graphql schemas
yarn prisma:seed # provision database with seeds
# alternatively, you can run
yarn prisma:reset # all-in-one command to reset, migrate, seed and generate schemas
yarn nx database:reset # setup the database with dev seeds
```

### Starting the app

```
nx prisma:migrate twenty-server
nx prisma:generate twenty-server
nx start:dev twenty-server
yarn nx start
```

### Lint

```
nx lint twenty-server
yarn nx lint
```

### Test

```
nx test twenty-server
yarn nx test:unit
```

### Resetting the database

If you want to reset the database, you can run the following command:

```bash
nx database:reset twenty-server
yarn nx database:reset
```

:::warning
Expand Down
4 changes: 2 additions & 2 deletions packages/twenty-docs/docs/start/local-setup/docker-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Setup database, run migrations, and seed:
```bash
make docker-dev-sh
yarn
yarn nx database:init twenty-server
yarn nx database:reset twenty-server
```

## Step 5: Start Twenty
Expand All @@ -106,7 +106,7 @@ Run the project with the following commands from the `root` folder:

```bash
make docker-dev-sh
yarn nx start:dev twenty-server
yarn nx start twenty-server
```

and in a separate terminal:
Expand Down
4 changes: 2 additions & 2 deletions packages/twenty-docs/docs/start/local-setup/yarn-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ yarn

Setup your database with the following command:
```bash
yarn nx database:init twenty-server
yarn nx database:reset twenty-server
```

Start the server and the frontend:
```bash
yarn nx start:dev twenty-server
yarn nx start twenty-server
yarn nx start twenty-front
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The file shares are used to store uploaded images and files through the UI, and
3. Run `terraform plan -out tfplan`
4. Run `terraform apply tfplan`
5. Connect to server `az containerapp exec --name twenty-server -g twenty-crm-rg`
6. Initialize the database from the server `yarn database:init`
6. Initialize the database from the server `yarn database:init:prod`
7. Go to https://your-twenty-front-fqdn - located in the portal

#### Production docker containers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ REFRESH_TOKEN_SECRET=replace_me_with_a_random_string_refresh

### Not able to login

If you encounter errors, (not able to log into the application after inputting an email) after the inital setup, try running `docker exec -it twenty-backend-1 yarn database:reset` and see if that solves your issue.
If you encounter errors, (not able to log into the application after inputting an email) after the inital setup, try running `docker exec -it twenty-backend-1 yarn nx database:reset` and see if that solves your issue.

### Cannot connect to server, running behind a reverse proxy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,6 @@ import {
IconBrandPocket,
IconBrandPolymer,
IconBrandPowershell,
IconBrandPrisma,
IconBrandProducthunt,
IconBrandPushbullet,
IconBrandPushover,
Expand Down Expand Up @@ -4957,7 +4956,6 @@ export default {
IconBrandPocket,
IconBrandPolymer,
IconBrandPowershell,
IconBrandPrisma,
IconBrandProducthunt,
IconBrandPushbullet,
IconBrandPushover,
Expand Down
25 changes: 3 additions & 22 deletions packages/twenty-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,10 @@
"license": "AGPL-3.0",
"scripts": {
"nx": "NX_DEFAULT_PROJECT=twenty-server node ../../node_modules/nx/bin/nx.js",
"prebuild": "rimraf dist",
"build": "npx nx prebuild && nest build --path ./tsconfig.build.json",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "NODE_ENV=development && nest start",
"start:dev": "npx nx start --watch",
"start:debug": "npx nx start:dev --debug",
"start:prod": "node dist/src/main",
"lint": "eslint \"src/**/*.ts\" --fix",
"test": "jest",
"test:watch": "npx nx test --watch",
"test:cov": "npx nx test --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register ../../node_modules/.bin/jest --runInBand",
"test:e2e": "./scripts/run-integration.sh",
"typeorm": "npx ts-node ../../node_modules/typeorm/cli.js",
"database:init": "npx nx database:setup && npx nx database:seed:dev",
"database:setup": "npx ts-node ./scripts/setup-db.ts && npx nx database:migrate",
"database:truncate": "npx ts-node ./scripts/truncate-db.ts",
"database:migrate": "npx nx typeorm -- migration:run -d src/database/typeorm/metadata/metadata.datasource && npx nx typeorm -- migration:run -d src/database/typeorm/core/core.datasource",
"database:seed:dev": "npx nx command -- workspace:seed:dev",
"database:seed:demo": "npx nx command -- workspace:seed:demo",
"database:reset": "npx nx database:truncate && npx nx database:init",
"command": "node dist/src/command/command",
"queue:work": "node dist/src/queue-worker/queue-worker",
"command:prod": "node dist/src/command/command",
"worker:prod": "node dist/src/queue-worker/queue-worker",
"database:init:prod": "npx ts-node ./scripts/setup-db.ts && yarn database:migrate:prod",
"database:migrate:prod": "npx -y typeorm migration:run -d dist/src/database/typeorm/metadata/metadata.datasource && npx -y typeorm migration:run -d dist/src/database/typeorm/core/core.datasource"
},
"dependencies": {
Expand Down
185 changes: 153 additions & 32 deletions packages/twenty-server/project.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,155 @@
{
"name": "twenty-server",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"targets": {
"build:packageJson": {
"executor": "@nx/js:tsc",
"dependsOn": [
"prebuild"
],
"options": {
"main": "packages/twenty-server/dist/src/main.js",
"tsConfig": "packages/twenty-server/tsconfig.json",
"outputPath": "packages/twenty-server/dist",
"updateBuildableProjectDepsInPackageJson": true
}
},
"command": {
"executor": "nx:run-commands",
"dependsOn": [
"build"
],
"options": {
"cwd": "packages/twenty-server",
"command": "node dist/src/command/command.js"
}
},
"test:debug": {
"dependsOn": [
"^build"
]
}
"name": "twenty-server",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"targets": {
"build": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",
"commands": ["rimraf dist", "nest build --path ./tsconfig.build.json"]
}
},
"build:packageJson": {
"executor": "@nx/js:tsc",
"options": {
"main": "packages/twenty-server/dist/src/main.js",
"tsConfig": "packages/twenty-server/tsconfig.json",
"outputPath": "packages/twenty-server/dist",
"updateBuildableProjectDepsInPackageJson": true
}
},
"start": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "NODE_ENV=development && nest start --watch"
}
},
"start:debug": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "nx start --debug"
}
},
"command": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "node dist/src/command/command.js"
}
},
"command-no-deps": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",
"command": "node dist/src/command/command.js"
}
},
"worker": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "node dist/src/queue-worker/queue-worker.js"
}
},
"typeorm": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",
"command": "ts-node ../../node_modules/typeorm/cli.js"
}
},
"ts-node": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "ts-node"
}
},
"ts-node-no-deps": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",
"command": "ts-node"
}
},
"lint": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",
"command": "eslint \"src/**/*.ts\" --fix"
}
},
"test:unit": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "jest"
}
},
"test:unit:watch": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "jest --watch"
}
},
"test:unit:coverage": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "jest --coverage"
}
},
"test:unit:debug": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",
"command": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register ../../node_modules/.bin/jest --runInBand"
}
},
"test:e2e": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "./scripts/run-integration.sh"
}
},
"database:migrate": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",
"commands": [
"nx typeorm -- migration:run -d src/database/typeorm/metadata/metadata.datasource",
"nx typeorm -- migration:run -d src/database/typeorm/core/core.datasource"
],
"parallel": false
}
},
"database:reset": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"commands": [
"nx ts-node-no-deps -- ./scripts/truncate-db.ts",
"nx ts-node-no-deps -- ./scripts/setup-db.ts",
"nx database:migrate",
"nx command-no-deps -- workspace:seed:dev"
],
"parallel": false
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/twenty-server/scripts/render-run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
export PG_DATABASE_URL=postgres://twenty:twenty@$PG_DATABASE_HOST:$PG_DATABASE_PORT/default
yarn database:setup
yarn database:init:prod
node dist/src/main
4 changes: 2 additions & 2 deletions packages/twenty-server/scripts/run-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
DIR="$(cd "$(dirname "$0")" && pwd)"
source $DIR/set-env-test.sh

yarn database:init
yarn jest --config ./test/jest-e2e.json
yarn nx database:reset
yarn nx jest --config ./test/jest-e2e.json
3 changes: 2 additions & 1 deletion packages/twenty-server/src/utils/generate-front-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ConfigService } from '@nestjs/config';

import * as fs from 'fs';
import * as path from 'path';

import { ConfigService } from '@nestjs/config';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';

const environmentService = new EnvironmentService(new ConfigService());
Expand Down

0 comments on commit e576fe0

Please sign in to comment.