@keycloakify/angular-email 0.0.1-rc.10
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/LICENSE.md +21 -0
- package/README.md +130 -0
- package/bin/build.js +153 -0
- package/esbuild/esbuild.d.ts +2 -0
- package/esbuild/index.d.ts +1 -0
- package/fesm2022/keycloakify-angular-email-esbuild.mjs +28 -0
- package/fesm2022/keycloakify-angular-email-esbuild.mjs.map +1 -0
- package/fesm2022/keycloakify-angular-email.mjs +829 -0
- package/fesm2022/keycloakify-angular-email.mjs.map +1 -0
- package/index.d.ts +19 -0
- package/lib/components/background/background.component.d.ts +15 -0
- package/lib/components/body/body.component.d.ts +7 -0
- package/lib/components/button/button.component.d.ts +55 -0
- package/lib/components/color-scheme/color-scheme.component.d.ts +34 -0
- package/lib/components/column/column.component.d.ts +9 -0
- package/lib/components/conditional/conditional.component.d.ts +12 -0
- package/lib/components/container/container.component.d.ts +20 -0
- package/lib/components/head/head.component.d.ts +7 -0
- package/lib/components/heading/heading.component.d.ts +16 -0
- package/lib/components/hr/hr.component.d.ts +13 -0
- package/lib/components/html/html.component.d.ts +10 -0
- package/lib/components/img/img.component.d.ts +18 -0
- package/lib/components/link/link.component.d.ts +14 -0
- package/lib/components/preview/preview.component.d.ts +8 -0
- package/lib/components/raw/raw.component.d.ts +8 -0
- package/lib/components/section/section.component.d.ts +8 -0
- package/lib/components/text/text.component.d.ts +13 -0
- package/lib/render.d.ts +26 -0
- package/lib/utils.d.ts +18 -0
- package/package.json +58 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Luca Peruzzo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Angular Email
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install Angular Email, use npm or yarn:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @keycloakify/angular-email
|
|
11
|
+
# or
|
|
12
|
+
yarn add @keycloakify/angular-email
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Creating an Email Component
|
|
18
|
+
|
|
19
|
+
see this [example](https://github.com/keycloakify/angular-email/blob/main/projects/showcase/src/app/app.component.ts)
|
|
20
|
+
|
|
21
|
+
### Rendering the Email
|
|
22
|
+
|
|
23
|
+
To render the email as HTML or plaintext, use Angular's rendering engine:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
// email.component.ts
|
|
27
|
+
...
|
|
28
|
+
import { render } from '@keycloakify/angular-email';
|
|
29
|
+
|
|
30
|
+
...
|
|
31
|
+
export class EmailComponent {
|
|
32
|
+
....
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const renderToHtml = () => {
|
|
36
|
+
return render({
|
|
37
|
+
component: EmailComponent,
|
|
38
|
+
selector: 'app-root',
|
|
39
|
+
props: {},
|
|
40
|
+
options: {
|
|
41
|
+
pretty: true,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
# cmd
|
|
49
|
+
|
|
50
|
+
export $EMAIL_COMPONENTS_DIR_PATH="src/emails"
|
|
51
|
+
npx keycloakify-angular-email build -p $EMAIL_COMPONENTS_DIR_PATH
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### With Keycloakify Emails
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// email.component.ts
|
|
58
|
+
...
|
|
59
|
+
import { render } from '@keycloakify/angular-email';
|
|
60
|
+
import type { GetSubject, GetTemplate } from 'keycloakify-emails';
|
|
61
|
+
|
|
62
|
+
...
|
|
63
|
+
export class EmailComponent {
|
|
64
|
+
....
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const getTemplate: GetTemplate = async (props) => {
|
|
68
|
+
return await render({
|
|
69
|
+
component: EmailComponent,
|
|
70
|
+
props,
|
|
71
|
+
selector: 'kc-email-test',
|
|
72
|
+
options: {
|
|
73
|
+
signalInputsPrefix: '$',
|
|
74
|
+
pretty: true,
|
|
75
|
+
plainText: props.plainText,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const getSubject: GetSubject = async (_props) => {
|
|
81
|
+
return '[KEYCLOAK] - SMTP test message';
|
|
82
|
+
};
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// vite.config.ts
|
|
87
|
+
|
|
88
|
+
...
|
|
89
|
+
import { buildEmailTheme } from 'keycloakify-emails';
|
|
90
|
+
import { angularEsbuildPlugin } from '@keycloakify/angular-email/esbuild';
|
|
91
|
+
|
|
92
|
+
export default defineConfig(({ mode }) => ({
|
|
93
|
+
...
|
|
94
|
+
plugins: [
|
|
95
|
+
angular(),
|
|
96
|
+
keycloakify({
|
|
97
|
+
...
|
|
98
|
+
postBuild: async (buildContext) => {
|
|
99
|
+
await buildEmailTheme({
|
|
100
|
+
templatesSrcDirPath: join(import.meta.dirname, '/emails/templates'),
|
|
101
|
+
filterTemplate: (filePath: string) => !!filePath.endsWith('.component.ts'),
|
|
102
|
+
themeNames: buildContext.themeNames,
|
|
103
|
+
keycloakifyBuildDirPath: buildContext.keycloakifyBuildDirPath,
|
|
104
|
+
locales: ['en'],
|
|
105
|
+
cwd: import.meta.dirname,
|
|
106
|
+
esbuild: {
|
|
107
|
+
packages: 'bundle',
|
|
108
|
+
external: ['@maizzle/framework'],
|
|
109
|
+
plugins: [angularEsbuildPlugin(import.meta.dirname)],
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
],
|
|
115
|
+
}));
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Contributing
|
|
119
|
+
|
|
120
|
+
Contributions are welcome! Feel free to open an issue or submit a pull request on [GitHub](https://github.com/keycloakify/angular-email).
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
125
|
+
|
|
126
|
+
## Acknowledgments
|
|
127
|
+
|
|
128
|
+
- Inspired by [jsx-email](https://github.com/rezqio/jsx-email)
|
|
129
|
+
- Builded with [@maizzle/framework](https://github.com/maizzle/framework)
|
|
130
|
+
- Developed by [Luca Peruzzo](https://github.com/luca-peruzzo)
|
package/bin/build.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { angularEsbuildPlugin } from '@keycloakify/angular-email/esbuild';
|
|
3
|
+
import esbuild from 'esbuild';
|
|
4
|
+
import { readdir, rm, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { basename, join, resolve } from 'node:path';
|
|
6
|
+
import { cwd, exit } from 'node:process';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
import { termost } from 'termost';
|
|
9
|
+
import pkg from '../package.json' with { type: 'json' };
|
|
10
|
+
async function bundle(entryPoints, cwd, outdir) {
|
|
11
|
+
// we have to use a bundler to preprocess templates code
|
|
12
|
+
// It's better to not use the same bundling configuration used for the
|
|
13
|
+
// frontend theme, because for email templates there might be a different
|
|
14
|
+
// transpiling settings, such as other jsx-pragma or additional transpilation plugins,
|
|
15
|
+
const result = await esbuild.build({
|
|
16
|
+
entryPoints: entryPoints,
|
|
17
|
+
bundle: true,
|
|
18
|
+
outdir,
|
|
19
|
+
absWorkingDir: cwd,
|
|
20
|
+
platform: 'node',
|
|
21
|
+
sourcemap: true,
|
|
22
|
+
packages: 'bundle',
|
|
23
|
+
external: ['@maizzle/framework'],
|
|
24
|
+
format: 'esm',
|
|
25
|
+
target: 'node20',
|
|
26
|
+
plugins: [angularEsbuildPlugin(cwd)],
|
|
27
|
+
metafile: true,
|
|
28
|
+
});
|
|
29
|
+
// collect map of entrypoints -> output files
|
|
30
|
+
// esbuild return paths relative to the CWD
|
|
31
|
+
// https://github.com/evanw/esbuild/issues/338
|
|
32
|
+
return Object.entries(result.metafile.outputs).reduce((acc, [filePath, meta]) => {
|
|
33
|
+
if (meta.entryPoint) {
|
|
34
|
+
// Absolute pathes doesn't work on windows.
|
|
35
|
+
// Have to use `pathToFileURL` to convert it to url
|
|
36
|
+
acc[resolve(cwd, meta.entryPoint)] = pathToFileURL(resolve(cwd, filePath)).toString();
|
|
37
|
+
}
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
}
|
|
41
|
+
async function getTemplates(dirPath, filterTemplate) {
|
|
42
|
+
try {
|
|
43
|
+
const recursiveGetFiles = async (path) => {
|
|
44
|
+
const items = await readdir(path, { withFileTypes: true });
|
|
45
|
+
const dirents = [];
|
|
46
|
+
for (const item of items) {
|
|
47
|
+
if (item.isFile())
|
|
48
|
+
dirents.push(item);
|
|
49
|
+
else if (item.isDirectory()) {
|
|
50
|
+
dirents.push(...(await recursiveGetFiles(join(item.parentPath, item.name))));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return dirents;
|
|
54
|
+
};
|
|
55
|
+
// Read all items in the directory
|
|
56
|
+
const items = (await recursiveGetFiles(dirPath))
|
|
57
|
+
.map((file) => join(file.parentPath, file.name))
|
|
58
|
+
.filter((filePath) => {
|
|
59
|
+
if (!filterTemplate)
|
|
60
|
+
return true;
|
|
61
|
+
return filterTemplate(filePath);
|
|
62
|
+
});
|
|
63
|
+
return items;
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error(`Error scanning directory: ${err.message}`);
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const build = async (emailFilesPath, outdir = 'dist/emails') => {
|
|
71
|
+
if (!emailFilesPath) {
|
|
72
|
+
console.error('emailFilesPath is required!');
|
|
73
|
+
exit(1);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
console.log(`building emails to ${outdir}...`);
|
|
77
|
+
const tmp = join(cwd(), outdir, '.tmp');
|
|
78
|
+
await rm(outdir, { recursive: true, force: true });
|
|
79
|
+
const tpls = await getTemplates(resolve(cwd(), emailFilesPath), (path) => path.endsWith('.ts'));
|
|
80
|
+
if (!tpls.length) {
|
|
81
|
+
console.error('no templates found!');
|
|
82
|
+
exit(1);
|
|
83
|
+
}
|
|
84
|
+
const entryPoints = [...tpls];
|
|
85
|
+
const bundled = await bundle(entryPoints, cwd(), tmp);
|
|
86
|
+
const promises = tpls.map(async (file) => {
|
|
87
|
+
const module = await import(bundled[file]);
|
|
88
|
+
console.log(`- ${file}`);
|
|
89
|
+
return Object.assign(Object.assign({}, module), { file });
|
|
90
|
+
});
|
|
91
|
+
const modules = await Promise.all(promises);
|
|
92
|
+
modules.forEach(async (module) => {
|
|
93
|
+
const html = await module.renderToHtml();
|
|
94
|
+
await writeFile(`${outdir}/${basename(module.file).split('.')[0]}.html`, html);
|
|
95
|
+
});
|
|
96
|
+
await rm(tmp, { recursive: true, force: true });
|
|
97
|
+
console.log('\x1b[36m%s\x1b[0m', `build complete!`);
|
|
98
|
+
exit(0);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.error(error);
|
|
102
|
+
exit(1);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const program = termost({
|
|
106
|
+
name: 'keycloakify-angular-email',
|
|
107
|
+
description: 'Keycloakify CLI',
|
|
108
|
+
version: pkg.version,
|
|
109
|
+
onException: (error) => {
|
|
110
|
+
console.error(error);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
program.option({
|
|
115
|
+
key: 'emailFilesPath',
|
|
116
|
+
name: { long: 'emailFilesPath', short: 'p' },
|
|
117
|
+
description: '',
|
|
118
|
+
defaultValue: '',
|
|
119
|
+
});
|
|
120
|
+
program.option({
|
|
121
|
+
key: 'outDir',
|
|
122
|
+
name: { long: 'outDir', short: 'o' },
|
|
123
|
+
description: '',
|
|
124
|
+
defaultValue: 'dist/emails',
|
|
125
|
+
});
|
|
126
|
+
program
|
|
127
|
+
.command({
|
|
128
|
+
name: 'build',
|
|
129
|
+
description: 'build angular components to html',
|
|
130
|
+
})
|
|
131
|
+
.input({
|
|
132
|
+
key: 'emailFilesPath',
|
|
133
|
+
type: 'text',
|
|
134
|
+
defaultValue: undefined,
|
|
135
|
+
label: "what's the path of your email components files?",
|
|
136
|
+
skip(context) {
|
|
137
|
+
return Boolean(context.emailFilesPath);
|
|
138
|
+
},
|
|
139
|
+
})
|
|
140
|
+
.input({
|
|
141
|
+
key: 'outDir',
|
|
142
|
+
type: 'text',
|
|
143
|
+
defaultValue: 'dist/emails',
|
|
144
|
+
label: 'where do you want to output html files?',
|
|
145
|
+
skip(context) {
|
|
146
|
+
return Boolean(context.outDir);
|
|
147
|
+
},
|
|
148
|
+
})
|
|
149
|
+
.task({
|
|
150
|
+
handler: async (context) => {
|
|
151
|
+
await build(context.emailFilesPath, context.outDir);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './esbuild';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createCompilerPlugin } from '@angular/build/private';
|
|
2
|
+
|
|
3
|
+
const angularEsbuildPlugin = (cwd) => createCompilerPlugin({
|
|
4
|
+
browserOnlyBuild: false,
|
|
5
|
+
incremental: false,
|
|
6
|
+
sourcemap: true,
|
|
7
|
+
tsconfig: cwd + '/tsconfig.json',
|
|
8
|
+
}, {
|
|
9
|
+
cacheOptions: {
|
|
10
|
+
basePath: cwd + '/.angular/cache',
|
|
11
|
+
enabled: false,
|
|
12
|
+
path: cwd + '/.angular/cache/angular-email',
|
|
13
|
+
},
|
|
14
|
+
inlineFonts: false,
|
|
15
|
+
inlineStyleLanguage: 'css',
|
|
16
|
+
optimization: true,
|
|
17
|
+
sourcemap: false,
|
|
18
|
+
target: [],
|
|
19
|
+
workspaceRoot: cwd,
|
|
20
|
+
outputNames: { bundles: '', media: '' },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Generated bundle index. Do not edit.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export { angularEsbuildPlugin };
|
|
28
|
+
//# sourceMappingURL=keycloakify-angular-email-esbuild.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keycloakify-angular-email-esbuild.mjs","sources":["../../../projects/angular-email/esbuild/esbuild.ts","../../../projects/angular-email/esbuild/keycloakify-angular-email-esbuild.ts"],"sourcesContent":["import { createCompilerPlugin } from '@angular/build/private';\nimport { Plugin } from 'esbuild';\n\nexport const angularEsbuildPlugin = (cwd: string): Plugin =>\n createCompilerPlugin(\n {\n browserOnlyBuild: false,\n incremental: false,\n sourcemap: true,\n tsconfig: cwd + '/tsconfig.json',\n },\n {\n cacheOptions: {\n basePath: cwd + '/.angular/cache',\n enabled: false,\n path: cwd + '/.angular/cache/angular-email',\n },\n inlineFonts: false,\n inlineStyleLanguage: 'css',\n optimization: true,\n sourcemap: false,\n target: [],\n workspaceRoot: cwd,\n outputNames: { bundles: '', media: '' },\n },\n );\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAGa,MAAA,oBAAoB,GAAG,CAAC,GAAW,KAC9C,oBAAoB,CAClB;AACE,IAAA,gBAAgB,EAAE,KAAK;AACvB,IAAA,WAAW,EAAE,KAAK;AAClB,IAAA,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,GAAG,GAAG,gBAAgB;CACjC,EACD;AACE,IAAA,YAAY,EAAE;QACZ,QAAQ,EAAE,GAAG,GAAG,iBAAiB;AACjC,QAAA,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,GAAG,GAAG,+BAA+B;AAC5C,KAAA;AACD,IAAA,WAAW,EAAE,KAAK;AAClB,IAAA,mBAAmB,EAAE,KAAK;AAC1B,IAAA,YAAY,EAAE,IAAI;AAClB,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,MAAM,EAAE,EAAE;AACV,IAAA,aAAa,EAAE,GAAG;IAClB,WAAW,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;AACxC,CAAA;;ACxBL;;AAEG;;;;"}
|