From e358d677f9ca95d9c5e2b8f469579784b21d3a30 Mon Sep 17 00:00:00 2001 From: martmull Date: Mon, 22 Jan 2024 16:21:56 +0100 Subject: [PATCH] Move emails to dedicated package (#3542) * Add new package * Add twenty-emails package * Use generated files from twenty-emails in twenty-server * Fix deleted file * Import emails templates properly --- package.json | 4 ++++ packages/twenty-emails/.gitignore | 1 + packages/twenty-emails/package.json | 18 ++++++++++++++++++ .../src}/common-style.ts | 0 .../src}/components/BaseEmail.tsx | 5 ++--- .../src}/components/BaseHead.tsx | 5 ++--- .../src}/components/CallToAction.tsx | 5 ++--- .../src}/components/HighlightedText.tsx | 5 ++--- .../src}/components/Logo.tsx | 0 .../src}/components/MainText.tsx | 5 ++--- .../src}/components/Title.tsx | 0 .../clean-inactive-workspaces.email.tsx | 11 +++++------ .../delete-inactive-workspaces.email.tsx | 11 +++++------ packages/twenty-emails/tsconfig.json | 7 +++++++ packages/twenty-emails/tsup.config.ts | 9 +++++++++ packages/twenty-emails/tsup.index.tsx | 2 ++ packages/twenty-server/package.json | 3 ++- .../clean-inactive-workspace.job.ts | 6 ++++-- packages/twenty-server/tsconfig.json | 3 +-- yarn.lock | 7 +++++++ 20 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 packages/twenty-emails/.gitignore create mode 100644 packages/twenty-emails/package.json rename packages/{twenty-server/src/emails => twenty-emails/src}/common-style.ts (100%) rename packages/{twenty-server/src/emails => twenty-emails/src}/components/BaseEmail.tsx (72%) rename packages/{twenty-server/src/emails => twenty-emails/src}/components/BaseHead.tsx (90%) rename packages/{twenty-server/src/emails => twenty-emails/src}/components/CallToAction.tsx (92%) rename packages/{twenty-server/src/emails => twenty-emails/src}/components/HighlightedText.tsx (92%) rename packages/{twenty-server/src/emails => twenty-emails/src}/components/Logo.tsx (100%) rename packages/{twenty-server/src/emails => twenty-emails/src}/components/MainText.tsx (85%) rename packages/{twenty-server/src/emails => twenty-emails/src}/components/Title.tsx (100%) rename packages/{twenty-server/src/workspace/cron/clean-inactive-workspaces => twenty-emails/src/emails}/clean-inactive-workspaces.email.tsx (80%) rename packages/{twenty-server/src/workspace/cron/clean-inactive-workspaces => twenty-emails/src/emails}/delete-inactive-workspaces.email.tsx (66%) create mode 100644 packages/twenty-emails/tsconfig.json create mode 100644 packages/twenty-emails/tsup.config.ts create mode 100644 packages/twenty-emails/tsup.index.tsx diff --git a/package.json b/package.json index d97c299106..dd912557db 100644 --- a/package.json +++ b/package.json @@ -261,6 +261,9 @@ "vite-plugin-checker": "^0.6.2", "vite-plugin-svgr": "^4.2.0" }, + "scripts": { + "postinstall": "yarn nx run twenty-emails:build" + }, "engines": { "node": "^18.17.1", "npm": "please-use-yarn", @@ -278,6 +281,7 @@ "packages/twenty-front", "packages/twenty-docs", "packages/twenty-server", + "packages/twenty-emails", "packages/twenty-utils", "packages/twenty-zapier", "packages/twenty-website", diff --git a/packages/twenty-emails/.gitignore b/packages/twenty-emails/.gitignore new file mode 100644 index 0000000000..1521c8b765 --- /dev/null +++ b/packages/twenty-emails/.gitignore @@ -0,0 +1 @@ +dist diff --git a/packages/twenty-emails/package.json b/packages/twenty-emails/package.json new file mode 100644 index 0000000000..679802f08b --- /dev/null +++ b/packages/twenty-emails/package.json @@ -0,0 +1,18 @@ +{ + "name": "twenty-emails", + "version": "0.1.0", + "description": "", + "author": "", + "private": true, + "license": "AGPL-3.0", + "main": "./dist/index.js", + "scripts": { + "nx": "NX_DEFAULT_PROJECT=twenty-emails node ../../node_modules/nx/bin/nx.js", + "build": "tsup" + }, + "engines": { + "node": "^18.17.1", + "npm": "please-use-yarn", + "yarn": "^4.0.2" + } +} diff --git a/packages/twenty-server/src/emails/common-style.ts b/packages/twenty-emails/src/common-style.ts similarity index 100% rename from packages/twenty-server/src/emails/common-style.ts rename to packages/twenty-emails/src/common-style.ts diff --git a/packages/twenty-server/src/emails/components/BaseEmail.tsx b/packages/twenty-emails/src/components/BaseEmail.tsx similarity index 72% rename from packages/twenty-server/src/emails/components/BaseEmail.tsx rename to packages/twenty-emails/src/components/BaseEmail.tsx index 6717f0e579..eda27ac978 100644 --- a/packages/twenty-server/src/emails/components/BaseEmail.tsx +++ b/packages/twenty-emails/src/components/BaseEmail.tsx @@ -1,8 +1,7 @@ import * as React from 'react'; import { Container, Html } from '@react-email/components'; - -import { BaseHead } from 'src/emails/components/BaseHead'; -import { Logo } from 'src/emails/components/Logo'; +import { BaseHead } from 'src/components/BaseHead'; +import { Logo } from 'src/components/Logo'; export const BaseEmail = ({ children }) => { return ( diff --git a/packages/twenty-server/src/emails/components/BaseHead.tsx b/packages/twenty-emails/src/components/BaseHead.tsx similarity index 90% rename from packages/twenty-server/src/emails/components/BaseHead.tsx rename to packages/twenty-emails/src/components/BaseHead.tsx index 6d3c92be13..def1345747 100644 --- a/packages/twenty-server/src/emails/components/BaseHead.tsx +++ b/packages/twenty-emails/src/components/BaseHead.tsx @@ -1,7 +1,6 @@ -import { Font, Head } from '@react-email/components'; import * as React from 'react'; - -import { emailTheme } from 'src/emails/common-style'; +import { Font, Head } from '@react-email/components'; +import { emailTheme } from 'src/common-style'; export const BaseHead = () => { return ( diff --git a/packages/twenty-server/src/emails/components/CallToAction.tsx b/packages/twenty-emails/src/components/CallToAction.tsx similarity index 92% rename from packages/twenty-server/src/emails/components/CallToAction.tsx rename to packages/twenty-emails/src/components/CallToAction.tsx index 7748999236..5444828013 100644 --- a/packages/twenty-server/src/emails/components/CallToAction.tsx +++ b/packages/twenty-emails/src/components/CallToAction.tsx @@ -1,7 +1,6 @@ -import { Button } from '@react-email/button'; import * as React from 'react'; - -import { emailTheme } from 'src/emails/common-style'; +import { Button } from '@react-email/button'; +import { emailTheme } from 'src/common-style'; const callToActionStyle = { display: 'flex', padding: '8px 32px', diff --git a/packages/twenty-server/src/emails/components/HighlightedText.tsx b/packages/twenty-emails/src/components/HighlightedText.tsx similarity index 92% rename from packages/twenty-server/src/emails/components/HighlightedText.tsx rename to packages/twenty-emails/src/components/HighlightedText.tsx index 75010e017c..22a362ef76 100644 --- a/packages/twenty-server/src/emails/components/HighlightedText.tsx +++ b/packages/twenty-emails/src/components/HighlightedText.tsx @@ -1,9 +1,8 @@ import * as React from 'react'; +import { Column } from '@react-email/components'; import { Row } from '@react-email/row'; import { Text } from '@react-email/text'; -import { Column } from '@react-email/components'; - -import { emailTheme } from 'src/emails/common-style'; +import { emailTheme } from 'src/common-style'; const rowStyle = { display: 'flex', diff --git a/packages/twenty-server/src/emails/components/Logo.tsx b/packages/twenty-emails/src/components/Logo.tsx similarity index 100% rename from packages/twenty-server/src/emails/components/Logo.tsx rename to packages/twenty-emails/src/components/Logo.tsx diff --git a/packages/twenty-server/src/emails/components/MainText.tsx b/packages/twenty-emails/src/components/MainText.tsx similarity index 85% rename from packages/twenty-server/src/emails/components/MainText.tsx rename to packages/twenty-emails/src/components/MainText.tsx index 8412c2bd94..acc9ffd9c2 100644 --- a/packages/twenty-server/src/emails/components/MainText.tsx +++ b/packages/twenty-emails/src/components/MainText.tsx @@ -1,7 +1,6 @@ -import { Text } from '@react-email/text'; import * as React from 'react'; - -import { emailTheme } from 'src/emails/common-style'; +import { Text } from '@react-email/text'; +import { emailTheme } from 'src/common-style'; const mainTextStyle = { fontSize: emailTheme.font.size.md, diff --git a/packages/twenty-server/src/emails/components/Title.tsx b/packages/twenty-emails/src/components/Title.tsx similarity index 100% rename from packages/twenty-server/src/emails/components/Title.tsx rename to packages/twenty-emails/src/components/Title.tsx diff --git a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspaces.email.tsx b/packages/twenty-emails/src/emails/clean-inactive-workspaces.email.tsx similarity index 80% rename from packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspaces.email.tsx rename to packages/twenty-emails/src/emails/clean-inactive-workspaces.email.tsx index fa7420ef94..2d012c39f9 100644 --- a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspaces.email.tsx +++ b/packages/twenty-emails/src/emails/clean-inactive-workspaces.email.tsx @@ -1,10 +1,9 @@ import * as React from 'react'; - -import { HighlightedText } from 'src/emails/components/HighlightedText'; -import { MainText } from 'src/emails/components/MainText'; -import { Title } from 'src/emails/components/Title'; -import { BaseEmail } from 'src/emails/components/BaseEmail'; -import { CallToAction } from 'src/emails/components/CallToAction'; +import { BaseEmail } from 'src/components/BaseEmail'; +import { CallToAction } from 'src/components/CallToAction'; +import { HighlightedText } from 'src/components/HighlightedText'; +import { MainText } from 'src/components/MainText'; +import { Title } from 'src/components/Title'; type CleanInactiveWorkspaceEmailData = { daysLeft: number; diff --git a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/delete-inactive-workspaces.email.tsx b/packages/twenty-emails/src/emails/delete-inactive-workspaces.email.tsx similarity index 66% rename from packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/delete-inactive-workspaces.email.tsx rename to packages/twenty-emails/src/emails/delete-inactive-workspaces.email.tsx index 7686696af6..15aadf0cb0 100644 --- a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/delete-inactive-workspaces.email.tsx +++ b/packages/twenty-emails/src/emails/delete-inactive-workspaces.email.tsx @@ -1,10 +1,9 @@ import * as React from 'react'; - -import { HighlightedText } from 'src/emails/components/HighlightedText'; -import { MainText } from 'src/emails/components/MainText'; -import { Title } from 'src/emails/components/Title'; -import { BaseEmail } from 'src/emails/components/BaseEmail'; -import { CallToAction } from 'src/emails/components/CallToAction'; +import { BaseEmail } from 'src/components/BaseEmail'; +import { CallToAction } from 'src/components/CallToAction'; +import { HighlightedText } from 'src/components/HighlightedText'; +import { MainText } from 'src/components/MainText'; +import { Title } from 'src/components/Title'; type DeleteInactiveWorkspaceEmailData = { daysSinceDead: number; diff --git a/packages/twenty-emails/tsconfig.json b/packages/twenty-emails/tsconfig.json new file mode 100644 index 0000000000..84c44e20bc --- /dev/null +++ b/packages/twenty-emails/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "commonjs", + "baseUrl": "./", + "jsx": "react-jsx" + } +} diff --git a/packages/twenty-emails/tsup.config.ts b/packages/twenty-emails/tsup.config.ts new file mode 100644 index 0000000000..177033ccd3 --- /dev/null +++ b/packages/twenty-emails/tsup.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig([ + { + entry: { index: './tsup.index.tsx' }, + format: ['cjs', 'esm'], + dts: true, + }, +]); diff --git a/packages/twenty-emails/tsup.index.tsx b/packages/twenty-emails/tsup.index.tsx new file mode 100644 index 0000000000..e816bb7363 --- /dev/null +++ b/packages/twenty-emails/tsup.index.tsx @@ -0,0 +1,2 @@ +export * from './src/emails/clean-inactive-workspaces.email'; +export * from './src/emails/delete-inactive-workspaces.email'; diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index 40fa1767b2..fb9ec7eacf 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -37,7 +37,8 @@ "@graphql-yoga/nestjs": "patch:@graphql-yoga/nestjs@2.1.0#./patches/@graphql-yoga+nestjs+2.1.0.patch", "@nestjs/graphql": "patch:@nestjs/graphql@12.0.8#./patches/@nestjs+graphql+12.0.8.patch", "@ptc-org/nestjs-query-graphql": "patch:@ptc-org/nestjs-query-graphql@4.2.0#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch", - "class-validator": "patch:class-validator@^0.14.0#./patches/class-validator+0.14.0.patch" + "class-validator": "patch:class-validator@^0.14.0#./patches/class-validator+0.14.0.patch", + "twenty-emails": "workspace:*" }, "engines": { "node": "^18.17.1", diff --git a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspace.job.ts b/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspace.job.ts index 88159758d5..2c574ea002 100644 --- a/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspace.job.ts +++ b/packages/twenty-server/src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspace.job.ts @@ -3,6 +3,10 @@ import { InjectRepository } from '@nestjs/typeorm'; import { render } from '@react-email/render'; import { Repository } from 'typeorm'; +import { + CleanInactiveWorkspaceEmail, + DeleteInactiveWorkspaceEmail, +} from 'twenty-emails'; import { MessageQueueJob } from 'src/integrations/message-queue/interfaces/message-queue-job.interface'; @@ -12,14 +16,12 @@ import { TypeORMService } from 'src/database/typeorm/typeorm.service'; import { DataSourceEntity } from 'src/metadata/data-source/data-source.entity'; import { UserService } from 'src/core/user/services/user.service'; import { EmailService } from 'src/integrations/email/email.service'; -import CleanInactiveWorkspaceEmail from 'src/workspace/cron/clean-inactive-workspaces/clean-inactive-workspaces.email'; import { EnvironmentService } from 'src/integrations/environment/environment.service'; import { FeatureFlagEntity, FeatureFlagKeys, } from 'src/core/feature-flag/feature-flag.entity'; import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity'; -import DeleteInactiveWorkspaceEmail from 'src/workspace/cron/clean-inactive-workspaces/delete-inactive-workspaces.email'; import { computeObjectTargetTable } from 'src/workspace/utils/compute-object-target-table.util'; const MILLISECONDS_IN_ONE_DAY = 1000 * 3600 * 24; diff --git a/packages/twenty-server/tsconfig.json b/packages/twenty-server/tsconfig.json index 6acfb191b4..f5993c2161 100644 --- a/packages/twenty-server/tsconfig.json +++ b/packages/twenty-server/tsconfig.json @@ -22,7 +22,6 @@ "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false, "resolveJsonModule": true, - "types": ["jest", "node"], - "jsx": "react-jsx" + "types": ["jest", "node"] } } diff --git a/yarn.lock b/yarn.lock index 9aa5a02929..92903d064c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -42367,6 +42367,12 @@ __metadata: languageName: unknown linkType: soft +"twenty-emails@workspace:*, twenty-emails@workspace:packages/twenty-emails": + version: 0.0.0-use.local + resolution: "twenty-emails@workspace:packages/twenty-emails" + languageName: unknown + linkType: soft + "twenty-front@workspace:packages/twenty-front": version: 0.0.0-use.local resolution: "twenty-front@workspace:packages/twenty-front" @@ -42381,6 +42387,7 @@ __metadata: "@nestjs/graphql": "patch:@nestjs/graphql@12.0.8#./patches/@nestjs+graphql+12.0.8.patch" "@ptc-org/nestjs-query-graphql": "patch:@ptc-org/nestjs-query-graphql@4.2.0#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch" class-validator: "patch:class-validator@^0.14.0#./patches/class-validator+0.14.0.patch" + twenty-emails: "workspace:*" languageName: unknown linkType: soft