@keycloakify/angular-email 0.0.1-rc.9 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Angular Email
2
2
 
3
- Angular Email is a library that enables email template development using Angular, inspired by [jsx-email](https://github.com/rezqio/jsx-email). It provides a way to create email components using Angular's templating system.
3
+ Angular Email is a library that enables email template development using Angular, inspired by [jsx-email](https://github.com/shellscape/jsx-email). It provides a way to create email components using Angular's templating system.
4
4
 
5
5
  ## Installation
6
6
 
@@ -23,22 +23,69 @@ see this [example](https://github.com/keycloakify/angular-email/blob/main/projec
23
23
  To render the email as HTML or plaintext, use Angular's rendering engine:
24
24
 
25
25
  ```typescript
26
+ // email.component.ts
26
27
  ...
27
- import { render } from '@keycloakify/angular-email';
28
+ import { render, RenderToHtml } from '@keycloakify/angular-email';
28
29
 
29
- const emailHtml = render({
30
- component: AppComponent,
31
- selector: 'app-root',
32
- options: {
33
- pretty: true,
34
- },
35
- }).then((emailHtml) => {
36
- console.log(emailHtml);
37
- });
30
+ ...
31
+ export class EmailComponent {
32
+ ....
33
+ }
34
+
35
+ type EmailComponentProps = {};
36
+
37
+ export const renderToHtml: RenderToHtml<EmailComponentProps> = (props) => {
38
+ return render({
39
+ component: EmailComponent,
40
+ selector: 'app-root',
41
+ props,
42
+ options: {
43
+ pretty: true,
44
+ },
45
+ });
46
+ };
38
47
  ```
39
48
 
49
+ ```sh
50
+ # cmd
51
+
52
+ export $EMAIL_COMPONENTS_DIR_PATH="src/emails"
53
+ npx keycloakify-angular-email build -p $EMAIL_COMPONENTS_DIR_PATH
54
+ ```
55
+
56
+ NB: use `keycloakify-angular-email build` when you don't need to pass dynamic inputs to your components, otherwise see [Standalone Dynamic Rendering](#standalone-dynamic-rendering)
57
+
40
58
  ### With Keycloakify Emails
41
59
 
60
+ ```ts
61
+ // email.component.ts
62
+ ...
63
+ import { render } from '@keycloakify/angular-email';
64
+ import type { GetSubject, GetTemplate } from 'keycloakify-emails';
65
+
66
+ ...
67
+ export class EmailComponent {
68
+ ....
69
+ }
70
+
71
+ export const getTemplate: GetTemplate = async (props) => {
72
+ return await render({
73
+ component: EmailComponent,
74
+ props,
75
+ selector: 'kc-email-test',
76
+ options: {
77
+ signalInputsPrefix: '$',
78
+ pretty: true,
79
+ plainText: props.plainText,
80
+ },
81
+ });
82
+ };
83
+
84
+ export const getSubject: GetSubject = async (_props) => {
85
+ return '[KEYCLOAK] - SMTP test message';
86
+ };
87
+ ```
88
+
42
89
  ```ts
43
90
  // vite.config.ts
44
91
 
@@ -55,14 +102,16 @@ export default defineConfig(({ mode }) => ({
55
102
  postBuild: async (buildContext) => {
56
103
  await buildEmailTheme({
57
104
  templatesSrcDirPath: join(import.meta.dirname, '/emails/templates'),
58
- filterTemplate: (filePath: string) => !filePath.endsWith('.html'),
105
+ filterTemplate: (filePath: string) => !!filePath.endsWith('.component.ts'),
59
106
  themeNames: buildContext.themeNames,
60
107
  keycloakifyBuildDirPath: buildContext.keycloakifyBuildDirPath,
61
108
  locales: ['en'],
62
109
  cwd: import.meta.dirname,
63
110
  esbuild: {
64
111
  packages: 'bundle',
65
- external: ['cheerio'],
112
+ external: ['juice', 'postcss', 'tailwindcss'],
113
+ format: 'esm',
114
+ outExtension: { '.js': '.mjs' },
66
115
  plugins: [angularEsbuildPlugin(import.meta.dirname)],
67
116
  },
68
117
  });
@@ -72,6 +121,108 @@ export default defineConfig(({ mode }) => ({
72
121
  }));
73
122
  ```
74
123
 
124
+ ### Standalone Dynamic Rendering
125
+
126
+ Use it in a server environment
127
+
128
+ ```js
129
+ // index.mjs
130
+
131
+ import { toHTML } from '@keycloakify/angular-email/node';
132
+
133
+ toHTML({
134
+ filePath: 'path/to/your.component.ts',
135
+ props: { foo: 'bar' },
136
+ })
137
+ .then((html) => {
138
+ console.log(html);
139
+ })
140
+ .catch((e) => {
141
+ console.error(e);
142
+ });
143
+ ```
144
+
145
+ or
146
+
147
+ ```js
148
+ // index.cjs
149
+
150
+ const { toHTML } = require('@keycloakify/angular-email/node');
151
+
152
+ toHTML({
153
+ filePath: 'path/to/your.component.ts',
154
+ props: { foo: 'bar' },
155
+ })
156
+ .then((html) => {
157
+ console.log(html);
158
+ })
159
+ .catch((e) => {
160
+ console.error(e);
161
+ });
162
+ ```
163
+
164
+ ```sh
165
+ # cmd
166
+
167
+ node index.mjs # or node index.cjs
168
+ ```
169
+
170
+ ## API
171
+
172
+ ### @keycloakify/angular-email
173
+
174
+ ### Render
175
+
176
+ ```ts
177
+ type Render<Input extends Record<string, any>> = {
178
+ component: Type<unknown>;
179
+ /** Component selector */
180
+ selector: string;
181
+ /** Component inputs */
182
+ props?: Input;
183
+ options?: {
184
+ /** render as text */
185
+ plainText?: boolean;
186
+ /** format the html output */
187
+ pretty?: boolean;
188
+ /** tailwind configuration object */
189
+ tailwindConfig?: Partial<Config>;
190
+ /** if you use prefix conventions on signal inputs */
191
+ signalInputsPrefix?: string;
192
+ };
193
+ };
194
+ ```
195
+
196
+ ### render()
197
+
198
+ ```ts
199
+ render<Input extends Record<string, any>>({ component, selector, props, options }: Render<Input>) => Promise<string>
200
+ ```
201
+
202
+ ### @keycloakify/angular-email/esbuild
203
+
204
+ ### angularEsbuildPlugin()
205
+
206
+ ```ts
207
+ angularEsbuildPlugin(cwd: string) => Plugin
208
+ ```
209
+
210
+ ### @keycloakify/angular-email/node
211
+
212
+ ### toHTML()
213
+
214
+ ```ts
215
+ toHTML<Input extends Record<string, any>>(options: {
216
+ filePath: string;
217
+ props?: Input;
218
+ root?: string;
219
+ }) => Promise<string>
220
+ ```
221
+
222
+ ### @keycloakify/angular-email/tailwindcss-preset-email
223
+
224
+ Just a tailwind v3 preset, inspired by [@maizzle/tailwindcss-preset-email](https://github.com/maizzle/tailwindcss-preset-email)
225
+
75
226
  ## Contributing
76
227
 
77
228
  Contributions are welcome! Feel free to open an issue or submit a pull request on [GitHub](https://github.com/keycloakify/angular-email).
@@ -15,13 +15,15 @@ async function bundle(entryPoints, cwd, outdir) {
15
15
  const result = await esbuild.build({
16
16
  entryPoints: entryPoints,
17
17
  bundle: true,
18
+ splitting: true,
18
19
  outdir,
19
20
  absWorkingDir: cwd,
20
21
  platform: 'node',
21
22
  sourcemap: true,
22
23
  packages: 'bundle',
23
- external: ['@maizzle/framework'],
24
+ external: ['juice', 'postcss', 'tailwindcss'],
24
25
  format: 'esm',
26
+ outExtension: { '.js': '.mjs' },
25
27
  target: 'node20',
26
28
  plugins: [angularEsbuildPlugin(cwd)],
27
29
  metafile: true,
@@ -108,7 +110,7 @@ const program = termost({
108
110
  version: pkg.version,
109
111
  onException: (error) => {
110
112
  console.error(error);
111
- process.exit(1);
113
+ exit(1);
112
114
  },
113
115
  });
114
116
  program.option({