@travetto/email-compiler 7.1.4 → 8.0.0-alpha.1
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/package.json +10 -10
- package/src/compiler.ts +3 -2
- package/src/util.ts +14 -20
- package/support/bin/config.ts +3 -2
- package/support/bin/editor.ts +2 -2
- package/support/cli.email_compile.ts +1 -1
- package/support/cli.email_editor.ts +5 -2
- package/support/cli.email_test.ts +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/email-compiler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Email compiling module",
|
|
6
6
|
"keywords": [
|
|
@@ -27,20 +27,20 @@
|
|
|
27
27
|
"directory": "module/email-compiler"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/config": "^
|
|
31
|
-
"@travetto/di": "^
|
|
32
|
-
"@travetto/email": "^
|
|
33
|
-
"@travetto/image": "^
|
|
34
|
-
"@travetto/runtime": "^
|
|
35
|
-
"@travetto/worker": "^
|
|
30
|
+
"@travetto/config": "^8.0.0-alpha.1",
|
|
31
|
+
"@travetto/di": "^8.0.0-alpha.1",
|
|
32
|
+
"@travetto/email": "^8.0.0-alpha.1",
|
|
33
|
+
"@travetto/image": "^8.0.0-alpha.1",
|
|
34
|
+
"@travetto/runtime": "^8.0.0-alpha.1",
|
|
35
|
+
"@travetto/worker": "^8.0.0-alpha.1",
|
|
36
36
|
"@types/inline-css": "^3.0.4",
|
|
37
37
|
"html-entities": "^2.6.0",
|
|
38
38
|
"inline-css": "^4.0.3",
|
|
39
|
-
"purgecss": "^
|
|
40
|
-
"sass": "^1.97.
|
|
39
|
+
"purgecss": "^8.0.0",
|
|
40
|
+
"sass": "^1.97.3"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@travetto/cli": "^
|
|
43
|
+
"@travetto/cli": "^8.0.0-alpha.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {
|
|
46
46
|
"@travetto/cli": {
|
package/src/compiler.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
import { TypedObject, RuntimeIndex, Runtime,
|
|
4
|
+
import { TypedObject, RuntimeIndex, Runtime, ExecUtil } from '@travetto/runtime';
|
|
5
5
|
import { type EmailCompiled, MailUtil, type EmailTemplateImport, type EmailTemplateModule } from '@travetto/email';
|
|
6
|
+
import { ManifestFileUtil } from '@travetto/manifest';
|
|
6
7
|
|
|
7
8
|
import { EmailCompileUtil } from './util.ts';
|
|
8
9
|
|
|
@@ -57,7 +58,7 @@ export class EmailCompiler {
|
|
|
57
58
|
await Promise.all(TypedObject.keys(outs).map(async key => {
|
|
58
59
|
if (message[key]) {
|
|
59
60
|
const content = MailUtil.buildBrand(file, message[key], 'trv email:compile');
|
|
60
|
-
await
|
|
61
|
+
await ManifestFileUtil.bufferedFileWrite(outs[key], content);
|
|
61
62
|
} else {
|
|
62
63
|
await fs.rm(outs[key], { force: true }); // Remove file if data not provided
|
|
63
64
|
}
|
package/src/util.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { buffer as toBuffer } from 'node:stream/consumers';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import type { CompileResult, Options } from 'sass';
|
|
4
3
|
|
|
5
4
|
import type { EmailCompiled, EmailTemplateModule, EmailTemplateResource } from '@travetto/email';
|
|
6
5
|
import { ImageUtil } from '@travetto/image';
|
|
7
|
-
import { RuntimeIndex } from '@travetto/runtime';
|
|
6
|
+
import { BinaryUtil, CodecUtil, RuntimeIndex, type BinaryArray } from '@travetto/runtime';
|
|
8
7
|
|
|
9
8
|
type Tokenized = {
|
|
10
9
|
text: string;
|
|
@@ -144,26 +143,21 @@ export class EmailCompileUtil {
|
|
|
144
143
|
*/
|
|
145
144
|
static async inlineImages(html: string, options: EmailTemplateResource): Promise<string> {
|
|
146
145
|
const { tokens, finalize } = await this.tokenizeResources(html, HTML_CSS_IMAGE_URLS);
|
|
147
|
-
const pendingImages
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
156
|
-
const buffer = await toBuffer(output);
|
|
157
|
-
pendingImages.push([token, ext, buffer]);
|
|
146
|
+
const pendingImages = [...tokens.entries()].map(async ([token, source]) => {
|
|
147
|
+
const format = path.extname(source).substring(1);
|
|
148
|
+
|
|
149
|
+
let bytes: BinaryArray;
|
|
150
|
+
if (ImageUtil.isKnownExtension(format)) {
|
|
151
|
+
const stream = await options.loader.readBinaryStream(source);
|
|
152
|
+
const converted = await ImageUtil.convert(stream, { optimize: true, format });
|
|
153
|
+
bytes = await BinaryUtil.toBinaryArray(converted);
|
|
158
154
|
} else {
|
|
159
|
-
|
|
155
|
+
bytes = await options.loader.readBinaryArray(source);
|
|
160
156
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const imageMap = new Map(await Promise.all(pendingImages.map(async ([token, ext, data]) =>
|
|
164
|
-
[token, `data:image/${ext.replace('.', '')};base64,${data.toString('base64')}`] as const
|
|
165
|
-
)));
|
|
157
|
+
return [token, `data:image/${format};base64,${CodecUtil.toBase64String(bytes)}`] as const;
|
|
158
|
+
});
|
|
166
159
|
|
|
160
|
+
const imageMap = new Map(await Promise.all(pendingImages));
|
|
167
161
|
return finalize(token => imageMap.get(token)!);
|
|
168
162
|
}
|
|
169
163
|
|
|
@@ -191,7 +185,7 @@ export class EmailCompileUtil {
|
|
|
191
185
|
static async applyStyles(html: string, options: EmailTemplateResource): Promise<string> {
|
|
192
186
|
const styles = [
|
|
193
187
|
options.globalStyles ?? '',
|
|
194
|
-
await options.loader.
|
|
188
|
+
await options.loader.readText('/email/main.scss').catch(() => '')
|
|
195
189
|
]
|
|
196
190
|
.filter(line => !!line)
|
|
197
191
|
.join('\n');
|
package/support/bin/config.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import { parse, stringify } from 'yaml';
|
|
3
3
|
|
|
4
|
-
import { Runtime
|
|
4
|
+
import { Runtime } from '@travetto/runtime';
|
|
5
|
+
import { ManifestFileUtil } from '@travetto/manifest';
|
|
5
6
|
|
|
6
7
|
import type { EditorConfigType } from './types.ts';
|
|
7
8
|
|
|
@@ -51,7 +52,7 @@ export class EditorConfig {
|
|
|
51
52
|
static async ensureConfig(): Promise<string> {
|
|
52
53
|
const resolved = Runtime.workspaceRelative(CONFIG_FILE);
|
|
53
54
|
if (!(await fs.stat(resolved).catch(() => { }))) {
|
|
54
|
-
await
|
|
55
|
+
await ManifestFileUtil.bufferedFileWrite(resolved, this.getDefaultConfig());
|
|
55
56
|
}
|
|
56
57
|
return resolved;
|
|
57
58
|
}
|
package/support/bin/editor.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Inject, Injectable } from '@travetto/di';
|
|
2
2
|
import { MailUtil, type EmailCompiled, type MailInterpolator } from '@travetto/email';
|
|
3
|
-
import {
|
|
3
|
+
import { RuntimeError, TypedObject, WatchUtil } from '@travetto/runtime';
|
|
4
4
|
|
|
5
5
|
import type { EditorSendService } from './send.ts';
|
|
6
6
|
import { EditorConfig } from './config.ts';
|
|
@@ -63,7 +63,7 @@ export class EditorService {
|
|
|
63
63
|
*/
|
|
64
64
|
async listen(): Promise<void> {
|
|
65
65
|
if (!process.connected || !process.send) {
|
|
66
|
-
throw new
|
|
66
|
+
throw new RuntimeError('Unable to run email editor, missing ipc channel');
|
|
67
67
|
}
|
|
68
68
|
process.on('message', async (request: EditorRequest) => {
|
|
69
69
|
switch (request.type) {
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { Env } from '@travetto/runtime';
|
|
2
|
-
import { CliCommand } from '@travetto/cli';
|
|
2
|
+
import { CliCommand, CliProfilesFlag } from '@travetto/cli';
|
|
3
3
|
import { Registry } from '@travetto/registry';
|
|
4
4
|
import { DependencyRegistryIndex } from '@travetto/di';
|
|
5
5
|
|
|
6
6
|
import { EditorService } from './bin/editor.ts';
|
|
7
7
|
|
|
8
8
|
/** The email editor compilation service and output serving */
|
|
9
|
-
@CliCommand(
|
|
9
|
+
@CliCommand()
|
|
10
10
|
export class EmailEditorCommand {
|
|
11
11
|
|
|
12
|
+
@CliProfilesFlag()
|
|
13
|
+
profile: string[];
|
|
14
|
+
|
|
12
15
|
preMain(): void {
|
|
13
16
|
Env.TRV_ROLE.set('build');
|
|
14
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
3
|
import { Registry } from '@travetto/registry';
|
|
4
|
-
import { type CliCommandShape, CliCommand } from '@travetto/cli';
|
|
4
|
+
import { type CliCommandShape, CliCommand, CliProfilesFlag } from '@travetto/cli';
|
|
5
5
|
import { DependencyRegistryIndex } from '@travetto/di';
|
|
6
6
|
import { Env } from '@travetto/runtime';
|
|
7
7
|
|
|
@@ -10,10 +10,13 @@ import { EditorService } from './bin/editor.ts';
|
|
|
10
10
|
/**
|
|
11
11
|
* CLI Entry point for running the email server
|
|
12
12
|
*/
|
|
13
|
-
@CliCommand(
|
|
13
|
+
@CliCommand()
|
|
14
14
|
export class EmailTestCommand implements CliCommandShape {
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
@CliProfilesFlag()
|
|
17
|
+
profile: string[];
|
|
18
|
+
|
|
19
|
+
finalize(): void {
|
|
17
20
|
Env.TRV_ROLE.set('build');
|
|
18
21
|
}
|
|
19
22
|
|