Update yarn commands (#4644)

* Simplify commands

* Simplify commands

* Migrate all dev commands to project.json

* Fix tests
This commit is contained in:
Charles Bochet 2024-03-25 12:31:18 +01:00 committed by GitHub
parent 1639b2ad0e
commit e576fe0d67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 179 additions and 82 deletions

View File

@ -30,7 +30,7 @@ jobs:
- name: Server / Run linter - name: Server / Run linter
run: yarn nx lint twenty-server run: yarn nx lint twenty-server
- name: Server / Run jest tests - name: Server / Run jest tests
run: yarn nx test twenty-server run: yarn nx test:unit twenty-server
- name: Server / Build - name: Server / Build
run: yarn nx build twenty-server run: yarn nx build twenty-server
- name: Server / Write .env - name: Server / Write .env
@ -38,4 +38,4 @@ jobs:
cd packages/twenty-server cd packages/twenty-server
cp .env.example .env cp .env.example .env
- name: Worker / Run - 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
.vscode/launch.json vendored
View File

@ -10,7 +10,7 @@
"runtimeArgs": [ "runtimeArgs": [
"nx", "nx",
"run", "run",
"twenty-server:start:dev", "twenty-server:start",
], ],
"outputCapture": "std", "outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart", "internalConsoleOptions": "openOnSessionStart",

View File

@ -318,7 +318,7 @@
}, },
"version": "0.2.1", "version": "0.2.1",
"scripts": { "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": { "workspaces": {
"packages": [ "packages": [

View File

@ -13,35 +13,31 @@ import DocCardList from '@theme/DocCardList';
## Useful commands ## 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 ### First time setup
``` ```
yarn prisma:migrate # run migrations yarn nx database:reset # setup the database with dev seeds
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
``` ```
### Starting the app ### Starting the app
``` ```
nx prisma:migrate twenty-server yarn nx start
nx prisma:generate twenty-server
nx start:dev twenty-server
``` ```
### Lint ### Lint
``` ```
nx lint twenty-server yarn nx lint
``` ```
### Test ### Test
``` ```
nx test twenty-server yarn nx test:unit
``` ```
### Resetting the database ### Resetting the database
@ -49,7 +45,7 @@ nx test twenty-server
If you want to reset the database, you can run the following command: If you want to reset the database, you can run the following command:
```bash ```bash
nx database:reset twenty-server yarn nx database:reset
``` ```
:::warning :::warning

View File

@ -97,7 +97,7 @@ Setup database, run migrations, and seed:
```bash ```bash
make docker-dev-sh make docker-dev-sh
yarn yarn
yarn nx database:init twenty-server yarn nx database:reset twenty-server
``` ```
## Step 5: Start Twenty ## Step 5: Start Twenty
@ -106,7 +106,7 @@ Run the project with the following commands from the `root` folder:
```bash ```bash
make docker-dev-sh make docker-dev-sh
yarn nx start:dev twenty-server yarn nx start twenty-server
``` ```
and in a separate terminal: and in a separate terminal:

View File

@ -183,12 +183,12 @@ yarn
Setup your database with the following command: Setup your database with the following command:
```bash ```bash
yarn nx database:init twenty-server yarn nx database:reset twenty-server
``` ```
Start the server and the frontend: Start the server and the frontend:
```bash ```bash
yarn nx start:dev twenty-server yarn nx start twenty-server
yarn nx start twenty-front yarn nx start twenty-front
``` ```

View File

@ -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` 3. Run `terraform plan -out tfplan`
4. Run `terraform apply tfplan` 4. Run `terraform apply tfplan`
5. Connect to server `az containerapp exec --name twenty-server -g twenty-crm-rg` 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 7. Go to https://your-twenty-front-fqdn - located in the portal
#### Production docker containers #### Production docker containers

View File

@ -24,7 +24,7 @@ REFRESH_TOKEN_SECRET=replace_me_with_a_random_string_refresh
### Not able to login ### 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 ### Cannot connect to server, running behind a reverse proxy

View File

@ -757,7 +757,6 @@ import {
IconBrandPocket, IconBrandPocket,
IconBrandPolymer, IconBrandPolymer,
IconBrandPowershell, IconBrandPowershell,
IconBrandPrisma,
IconBrandProducthunt, IconBrandProducthunt,
IconBrandPushbullet, IconBrandPushbullet,
IconBrandPushover, IconBrandPushover,
@ -4957,7 +4956,6 @@ export default {
IconBrandPocket, IconBrandPocket,
IconBrandPolymer, IconBrandPolymer,
IconBrandPowershell, IconBrandPowershell,
IconBrandPrisma,
IconBrandProducthunt, IconBrandProducthunt,
IconBrandPushbullet, IconBrandPushbullet,
IconBrandPushover, IconBrandPushover,

View File

@ -7,29 +7,10 @@
"license": "AGPL-3.0", "license": "AGPL-3.0",
"scripts": { "scripts": {
"nx": "NX_DEFAULT_PROJECT=twenty-server node ../../node_modules/nx/bin/nx.js", "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", "start:prod": "node dist/src/main",
"lint": "eslint \"src/**/*.ts\" --fix", "command:prod": "node dist/src/command/command",
"test": "jest", "worker:prod": "node dist/src/queue-worker/queue-worker",
"test:watch": "npx nx test --watch", "database:init:prod": "npx ts-node ./scripts/setup-db.ts && yarn database:migrate:prod",
"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",
"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" "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": { "dependencies": {

View File

@ -1,34 +1,155 @@
{ {
"name": "twenty-server", "name": "twenty-server",
"$schema": "../../node_modules/nx/schemas/project-schema.json", "$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application", "projectType": "application",
"targets": { "targets": {
"build:packageJson": { "build": {
"executor": "@nx/js:tsc", "executor": "nx:run-commands",
"dependsOn": [ "options": {
"prebuild" "cwd": "packages/twenty-server",
], "commands": ["rimraf dist", "nest build --path ./tsconfig.build.json"]
"options": { }
"main": "packages/twenty-server/dist/src/main.js", },
"tsConfig": "packages/twenty-server/tsconfig.json", "build:packageJson": {
"outputPath": "packages/twenty-server/dist", "executor": "@nx/js:tsc",
"updateBuildableProjectDepsInPackageJson": true "options": {
} "main": "packages/twenty-server/dist/src/main.js",
}, "tsConfig": "packages/twenty-server/tsconfig.json",
"command": { "outputPath": "packages/twenty-server/dist",
"executor": "nx:run-commands", "updateBuildableProjectDepsInPackageJson": true
"dependsOn": [ }
"build" },
], "start": {
"options": { "executor": "nx:run-commands",
"cwd": "packages/twenty-server", "dependsOn": ["build"],
"command": "node dist/src/command/command.js" "options": {
} "cwd": "packages/twenty-server",
}, "command": "NODE_ENV=development && nest start --watch"
"test:debug": { }
"dependsOn": [ },
"^build" "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
}
} }
} }
}

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
export PG_DATABASE_URL=postgres://twenty:twenty@$PG_DATABASE_HOST:$PG_DATABASE_PORT/default 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 node dist/src/main

View File

@ -4,5 +4,5 @@
DIR="$(cd "$(dirname "$0")" && pwd)" DIR="$(cd "$(dirname "$0")" && pwd)"
source $DIR/set-env-test.sh source $DIR/set-env-test.sh
yarn database:init yarn nx database:reset
yarn jest --config ./test/jest-e2e.json yarn nx jest --config ./test/jest-e2e.json

View File

@ -1,7 +1,8 @@
import { ConfigService } from '@nestjs/config';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import { ConfigService } from '@nestjs/config';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service'; import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
const environmentService = new EnvironmentService(new ConfigService()); const environmentService = new EnvironmentService(new ConfigService());