From e576fe0d67b315e993fd0f3699dd18931beaf348 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Mon, 25 Mar 2024 12:31:18 +0100 Subject: [PATCH] Update yarn commands (#4644) * Simplify commands * Simplify commands * Migrate all dev commands to project.json * Fix tests --- .github/workflows/ci-server.yaml | 4 +- .vscode/launch.json | 2 +- package.json | 2 +- .../docs/contributor/server/server.mdx | 20 +- .../docs/start/local-setup/docker-setup.mdx | 4 +- .../docs/start/local-setup/yarn-setup.mdx | 4 +- .../start/self-hosting/cloud-providers.mdx | 2 +- .../start/self-hosting/docker-compose.mdx | 2 +- .../ui/display/icon/constants/index.ts | 2 - packages/twenty-server/package.json | 25 +-- packages/twenty-server/project.json | 185 +++++++++++++++--- packages/twenty-server/scripts/render-run.sh | 2 +- .../twenty-server/scripts/run-integration.sh | 4 +- .../src/utils/generate-front-config.ts | 3 +- 14 files changed, 179 insertions(+), 82 deletions(-) diff --git a/.github/workflows/ci-server.yaml b/.github/workflows/ci-server.yaml index e1de6dda9c..9e46add8bc 100644 --- a/.github/workflows/ci-server.yaml +++ b/.github/workflows/ci-server.yaml @@ -30,7 +30,7 @@ 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 @@ -38,4 +38,4 @@ jobs: 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 diff --git a/.vscode/launch.json b/.vscode/launch.json index 31721f10ea..80198e9cc1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "runtimeArgs": [ "nx", "run", - "twenty-server:start:dev", + "twenty-server:start", ], "outputCapture": "std", "internalConsoleOptions": "openOnSessionStart", diff --git a/package.json b/package.json index 312f4a45e6..b6320ad1f0 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/packages/twenty-docs/docs/contributor/server/server.mdx b/packages/twenty-docs/docs/contributor/server/server.mdx index 19b0a54017..73292f3bbd 100644 --- a/packages/twenty-docs/docs/contributor/server/server.mdx +++ b/packages/twenty-docs/docs/contributor/server/server.mdx @@ -13,35 +13,31 @@ 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 ` 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 @@ -49,7 +45,7 @@ nx test twenty-server If you want to reset the database, you can run the following command: ```bash -nx database:reset twenty-server +yarn nx database:reset ``` :::warning diff --git a/packages/twenty-docs/docs/start/local-setup/docker-setup.mdx b/packages/twenty-docs/docs/start/local-setup/docker-setup.mdx index 5a1bdd5d96..87d12690ee 100644 --- a/packages/twenty-docs/docs/start/local-setup/docker-setup.mdx +++ b/packages/twenty-docs/docs/start/local-setup/docker-setup.mdx @@ -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 @@ -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: diff --git a/packages/twenty-docs/docs/start/local-setup/yarn-setup.mdx b/packages/twenty-docs/docs/start/local-setup/yarn-setup.mdx index 12d8569c75..bb2221dd71 100644 --- a/packages/twenty-docs/docs/start/local-setup/yarn-setup.mdx +++ b/packages/twenty-docs/docs/start/local-setup/yarn-setup.mdx @@ -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 ``` diff --git a/packages/twenty-docs/docs/start/self-hosting/cloud-providers.mdx b/packages/twenty-docs/docs/start/self-hosting/cloud-providers.mdx index 0eae5ff1a4..586f01a5f9 100644 --- a/packages/twenty-docs/docs/start/self-hosting/cloud-providers.mdx +++ b/packages/twenty-docs/docs/start/self-hosting/cloud-providers.mdx @@ -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 diff --git a/packages/twenty-docs/docs/start/self-hosting/docker-compose.mdx b/packages/twenty-docs/docs/start/self-hosting/docker-compose.mdx index a5594f7edf..792428e1ee 100644 --- a/packages/twenty-docs/docs/start/self-hosting/docker-compose.mdx +++ b/packages/twenty-docs/docs/start/self-hosting/docker-compose.mdx @@ -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 diff --git a/packages/twenty-front/src/modules/ui/display/icon/constants/index.ts b/packages/twenty-front/src/modules/ui/display/icon/constants/index.ts index cc521b61a0..8c0c4b2676 100644 --- a/packages/twenty-front/src/modules/ui/display/icon/constants/index.ts +++ b/packages/twenty-front/src/modules/ui/display/icon/constants/index.ts @@ -757,7 +757,6 @@ import { IconBrandPocket, IconBrandPolymer, IconBrandPowershell, - IconBrandPrisma, IconBrandProducthunt, IconBrandPushbullet, IconBrandPushover, @@ -4957,7 +4956,6 @@ export default { IconBrandPocket, IconBrandPolymer, IconBrandPowershell, - IconBrandPrisma, IconBrandProducthunt, IconBrandPushbullet, IconBrandPushover, diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index 3a88c7286c..2b9b958902 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -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": { diff --git a/packages/twenty-server/project.json b/packages/twenty-server/project.json index 358c38cb50..95da95eec1 100644 --- a/packages/twenty-server/project.json +++ b/packages/twenty-server/project.json @@ -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 + } } -} \ No newline at end of file + } +} diff --git a/packages/twenty-server/scripts/render-run.sh b/packages/twenty-server/scripts/render-run.sh index 09758bfe6b..056a3c919e 100755 --- a/packages/twenty-server/scripts/render-run.sh +++ b/packages/twenty-server/scripts/render-run.sh @@ -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 diff --git a/packages/twenty-server/scripts/run-integration.sh b/packages/twenty-server/scripts/run-integration.sh index 3673ab813f..8f48e2178f 100755 --- a/packages/twenty-server/scripts/run-integration.sh +++ b/packages/twenty-server/scripts/run-integration.sh @@ -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 diff --git a/packages/twenty-server/src/utils/generate-front-config.ts b/packages/twenty-server/src/utils/generate-front-config.ts index c4d15838a2..7005d26554 100644 --- a/packages/twenty-server/src/utils/generate-front-config.ts +++ b/packages/twenty-server/src/utils/generate-front-config.ts @@ -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());