Skip to content

Commit bade9e2

Browse files
committed
Setup @comet/mail package
This will be used for helper functions for building HTML emails with React, such as the already included `css` helper. Simple components built with React and/or MJML may also be added in future PRs.
1 parent 2580c61 commit bade9e2

File tree

14 files changed

+279
-21
lines changed

14 files changed

+279
-21
lines changed

.changeset/mighty-pants-march.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@comet/mail": minor
3+
---
4+
5+
Add the `css` helper function
6+
7+
Similar to the `css` function provided by styled-components or @mui/material.
8+
It simply returns the string passed into it but provides CSS syntax highlighting and auto-formatting when using certain IDE plugins, e.g. the "styled-components" plugin in VSCode.

demo/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@apollo/server": "^5.1.0",
3838
"@as-integrations/express5": "^1.1.2",
3939
"@comet/cms-api": "workspace:*",
40+
"@comet/mail": "workspace:*",
4041
"@faker-js/faker": "^10.1.0",
4142
"@kubernetes/client-node": "^1.3.0",
4243
"@mikro-orm/cli": "^6.4.16",

demo/api/src/products/product-published.mail.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { MailTemplate, MailTemplateInterface } from "@comet/cms-api";
2+
import { css } from "@comet/mail";
23
import { TranslationService } from "@src/translation/translation.service";
34

45
type MailProps = {
56
recipient: { name: string; email: string; language: string };
67
countProductPublished: "all" | number;
78
};
89

10+
const mailStyles = css`
11+
body {
12+
font-family: Arial, sans-serif;
13+
}
14+
`;
15+
916
@MailTemplate()
1017
export class ProductPublishedMail implements MailTemplateInterface<MailProps> {
1118
constructor(private readonly translationService: TranslationService) {}
@@ -34,7 +41,7 @@ export class ProductPublishedMail implements MailTemplateInterface<MailProps> {
3441
countProductPublished: props.countProductPublished,
3542
},
3643
),
37-
html: intl.formatMessage(
44+
html: `<head><style>${mailStyles}</style></head>${intl.formatMessage(
3845
{
3946
id: "product-published-mail.html-message",
4047
defaultMessage:
@@ -51,7 +58,7 @@ export class ProductPublishedMail implements MailTemplateInterface<MailProps> {
5158
countProductPublished: props.countProductPublished,
5259
p: (...chunks) => `<p>${chunks.join("")}</p>`,
5360
},
54-
),
61+
)}`,
5562
};
5663
}
5764

dev-pm.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ export default defineConfig({
126126
group: ["site-react", "site-nextjs", "cms"],
127127
},
128128

129+
//group mail
130+
{
131+
name: "mail",
132+
script: "pnpm --filter @comet/mail run dev",
133+
group: ["mail"],
134+
},
135+
129136
//group demo admin
130137
{
131138
name: "demo-admin",

knip.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
"project": ["./src/**/*.{ts,tsx}"],
7171
"ignore": ["./src/**/*.generated.ts"]
7272
},
73+
"packages/mail": {
74+
"project": ["./src/**/*.{ts,tsx}"]
75+
},
7376
"demo/admin": {
7477
"entry": ["./src/loader.ts", "./src/**/*.cometGen.{ts,tsx}"],
7578
"project": ["./src/**/*.{ts,tsx}"],

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
"build:docs": "pnpm build:storybook && pnpm --recursive --filter '@comet/eslint-plugin' --filter '@comet/admin*' --filter '!@comet/admin-generator' --filter 'comet-docs' run build",
1515
"clean": "pnpm --recursive run clean",
1616
"copy-project-files": "node copy-project-files.js",
17-
"dev": "pnpm dev:admin && pnpm dev:cms && pnpm dev:demo",
17+
"dev": "pnpm dev:admin && pnpm dev:cms && pnpm dev:mail && pnpm dev:demo",
1818
"dev:admin": "dev-pm start @comet-admin",
1919
"dev:cms": "dev-pm start @cms",
2020
"dev:cms:admin": "dev-pm start @cms-admin",
2121
"dev:cms:api": "dev-pm start @cms-api",
2222
"dev:cms:site-nextjs": "dev-pm start @site-nextjs",
2323
"dev:cms:site-react": "dev-pm start @site-react",
24+
"dev:mail": "dev-pm start @mail",
2425
"dev:demo": "dev-pm start @demo",
2526
"dev:demo:admin": "dev-pm start @demo-admin",
2627
"dev:demo:api": "dev-pm start @demo-api",

packages/mail/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/

packages/mail/eslint.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import eslintConfigReact from "@comet/eslint-config/future/react.js";
2+
3+
/** @type {import('eslint')} */
4+
const config = [
5+
{
6+
ignores: ["lib/**"],
7+
},
8+
...eslintConfigReact,
9+
{
10+
rules: {
11+
"@comet/no-other-module-relative-import": "off",
12+
},
13+
},
14+
];
15+
16+
export default config;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @filename: lint-staged.config.mjs
3+
* @type {import('lint-staged').Configuration}
4+
*/
5+
export default {
6+
"src/**/*.{ts,tsx,js,jsx,json,css,scss,md}": () => "pnpm lint:eslint",
7+
"src/**/*.{ts,tsx}": () => "pnpm lint:tsc",
8+
"*.{js,json,md,yml,yaml}": () => "pnpm lint:prettier",
9+
};

packages/mail/package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@comet/mail",
3+
"version": "8.10.0",
4+
"description": "Helper functions for building HTML emails with React",
5+
"type": "commonjs",
6+
"main": "lib/index.js",
7+
"scripts": {
8+
"build": "pnpm run clean && tsc",
9+
"clean": "rimraf lib",
10+
"dev": "tsc --watch",
11+
"lint": "run-p lint:prettier lint:eslint lint:tsc",
12+
"lint:ci": "pnpm run lint",
13+
"lint:eslint": "eslint --max-warnings 0 src/ **/*.json --no-warn-ignored",
14+
"lint:prettier": "pnpm exec prettier --check './**/*.{js,json,md,yml,yaml}'",
15+
"lint:tsc": "tsc",
16+
"test": "jest --passWithNoTests",
17+
"test:watch": "jest --watch"
18+
},
19+
"devDependencies": {
20+
"@comet/eslint-config": "workspace:*",
21+
"@types/jest": "^29.5.14",
22+
"eslint": "^9.30.1",
23+
"jest": "^29.7.0",
24+
"npm-run-all2": "^8.0.0",
25+
"prettier": "^3.6.2",
26+
"typescript": "5.9.3"
27+
},
28+
"peerDependencies": {
29+
"eslint": ">=9",
30+
"prettier": ">=3"
31+
},
32+
"engines": {
33+
"node": ">=22.0.0"
34+
},
35+
"publishConfig": {
36+
"access": "public",
37+
"registry": "https://registry.npmjs.org"
38+
}
39+
}

0 commit comments

Comments
 (0)