@travetto/email-compiler 3.3.8 → 3.4.0-rc.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/email-compiler",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-rc.1",
|
|
4
4
|
"description": "Email compiling module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -26,19 +26,20 @@
|
|
|
26
26
|
"directory": "module/email-compiler"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/base": "^3.
|
|
30
|
-
"@travetto/config": "^3.
|
|
31
|
-
"@travetto/di": "^3.
|
|
32
|
-
"@travetto/email": "^3.
|
|
33
|
-
"@travetto/image": "^3.
|
|
34
|
-
"@
|
|
29
|
+
"@travetto/base": "^3.4.0-rc.1",
|
|
30
|
+
"@travetto/config": "^3.4.0-rc.1",
|
|
31
|
+
"@travetto/di": "^3.4.0-rc.1",
|
|
32
|
+
"@travetto/email": "^3.4.0-rc.1",
|
|
33
|
+
"@travetto/image": "^3.4.0-rc.1",
|
|
34
|
+
"@travetto/worker": "^3.4.0-rc.1",
|
|
35
|
+
"@types/inline-css": "^3.0.2",
|
|
35
36
|
"html-entities": "^2.4.0",
|
|
36
37
|
"inline-css": "^4.0.2",
|
|
37
38
|
"purgecss": "^5.0.0",
|
|
38
|
-
"sass": "^1.
|
|
39
|
+
"sass": "^1.69.5"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"@travetto/cli": "^3.
|
|
42
|
+
"@travetto/cli": "^3.4.0-rc.2"
|
|
42
43
|
},
|
|
43
44
|
"peerDependenciesMeta": {
|
|
44
45
|
"@travetto/cli": {
|
package/src/compiler.ts
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
|
|
3
|
-
import { FileQueryProvider, TypedObject } from '@travetto/base';
|
|
3
|
+
import { CompilerClient, FileQueryProvider, TypedObject } from '@travetto/base';
|
|
4
4
|
import { EmailCompileSource, EmailCompiled, EmailCompileContext, MailUtil } from '@travetto/email';
|
|
5
5
|
import { RootIndex, path } from '@travetto/manifest';
|
|
6
|
-
import {
|
|
6
|
+
import { ManualAsyncIterator as Queue } from '@travetto/worker';
|
|
7
7
|
|
|
8
8
|
import { EmailCompileUtil } from './util';
|
|
9
9
|
|
|
10
10
|
const VALID_FILE = (file: string): boolean => /[.](scss|css|png|jpe?g|gif|ya?ml)$/.test(file) && !/[.]compiled[.]/.test(file);
|
|
11
11
|
|
|
12
|
+
type WatchEvent = { action: 'create' | 'update' | 'delete', file: string, folder: string };
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Email compilation support
|
|
14
16
|
*/
|
|
15
17
|
export class EmailCompiler {
|
|
16
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Watch folders as needed
|
|
21
|
+
*/
|
|
22
|
+
static async #watchFolders(folders: string[], handler: (ev: WatchEvent) => void, signal: AbortSignal): Promise<void> {
|
|
23
|
+
const lib = await import('@parcel/watcher');
|
|
24
|
+
for (const src of folders) {
|
|
25
|
+
const cleanup = await lib.subscribe(src, async (err, events) => {
|
|
26
|
+
for (const ev of events) {
|
|
27
|
+
handler({ action: ev.type, file: path.toPosix(ev.path), folder: src });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
signal.addEventListener('abort', () => cleanup.unsubscribe());
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
/** Load Template */
|
|
18
35
|
static async loadTemplate(file: string): Promise<EmailCompileContext> {
|
|
19
36
|
const entry = RootIndex.getEntry(file);
|
|
@@ -37,8 +54,11 @@ export class EmailCompiler {
|
|
|
37
54
|
*/
|
|
38
55
|
static findAllTemplates(mod?: string): string[] {
|
|
39
56
|
return RootIndex
|
|
40
|
-
.
|
|
41
|
-
|
|
57
|
+
.find({
|
|
58
|
+
module: m => !mod ? m.roles.includes('std') : mod === m.name,
|
|
59
|
+
folder: f => f === 'support',
|
|
60
|
+
file: f => EmailCompileUtil.isTemplateFile(f.sourceFile)
|
|
61
|
+
})
|
|
42
62
|
.map(x => x.sourceFile);
|
|
43
63
|
}
|
|
44
64
|
|
|
@@ -94,7 +114,6 @@ export class EmailCompiler {
|
|
|
94
114
|
return keys;
|
|
95
115
|
}
|
|
96
116
|
|
|
97
|
-
|
|
98
117
|
/**
|
|
99
118
|
* Watch compilation
|
|
100
119
|
*/
|
|
@@ -106,14 +125,20 @@ export class EmailCompiler {
|
|
|
106
125
|
)].map(x => path.resolve(RootIndex.getModule(x)!.sourcePath, 'resources'))
|
|
107
126
|
);
|
|
108
127
|
|
|
109
|
-
const
|
|
128
|
+
const ctrl = new AbortController();
|
|
129
|
+
const stream = new Queue<WatchEvent>([], ctrl.signal);
|
|
110
130
|
|
|
111
|
-
|
|
131
|
+
// watch resources
|
|
132
|
+
this.#watchFolders(all.paths, ev => stream.add(ev), ctrl.signal);
|
|
133
|
+
|
|
134
|
+
// Watch template files
|
|
135
|
+
new CompilerClient().onFileChange(ev => {
|
|
112
136
|
const src = RootIndex.getEntry(ev.file);
|
|
113
137
|
if (src && EmailCompileUtil.isTemplateFile(src.sourceFile)) {
|
|
114
|
-
stream.add({ ...ev, file: src.sourceFile });
|
|
138
|
+
setTimeout(() => stream.add({ ...ev, file: src.sourceFile }), 100); // Wait for it to be loaded
|
|
115
139
|
}
|
|
116
140
|
});
|
|
141
|
+
|
|
117
142
|
for await (const { file, action } of stream) {
|
|
118
143
|
if (action === 'delete') {
|
|
119
144
|
continue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RootRegistry } from '@travetto/registry';
|
|
2
2
|
import { CliCommandShape, CliCommand, cliTpl } from '@travetto/cli';
|
|
3
|
-
import { GlobalEnvConfig } from '@travetto/base';
|
|
3
|
+
import { Env, GlobalEnvConfig } from '@travetto/base';
|
|
4
4
|
|
|
5
5
|
import { EmailCompiler } from '../src/compiler';
|
|
6
6
|
|
|
@@ -17,11 +17,12 @@ export class EmailCompileCommand implements CliCommandShape {
|
|
|
17
17
|
return {
|
|
18
18
|
debug: false,
|
|
19
19
|
dynamic: this.watch,
|
|
20
|
-
profiles: ['email-dev']
|
|
21
20
|
};
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
async main(): Promise<void> {
|
|
24
|
+
Env.addToList('TRV_PROFILES', 'email-dev');
|
|
25
|
+
|
|
25
26
|
await RootRegistry.init();
|
|
26
27
|
|
|
27
28
|
// Let the engine template
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GlobalEnvConfig } from '@travetto/base';
|
|
2
|
-
import { CliCommand } from '@travetto/cli';
|
|
1
|
+
import { Env, GlobalEnvConfig } from '@travetto/base';
|
|
2
|
+
import { CliCommand, CliUtil } from '@travetto/cli';
|
|
3
3
|
import { RootRegistry } from '@travetto/registry';
|
|
4
4
|
|
|
5
5
|
import { EditorState } from './bin/editor';
|
|
@@ -12,12 +12,17 @@ export class EmailEditorCommand {
|
|
|
12
12
|
envInit(): GlobalEnvConfig {
|
|
13
13
|
return {
|
|
14
14
|
envName: 'dev',
|
|
15
|
-
dynamic: true
|
|
16
|
-
profiles: ['email-dev']
|
|
15
|
+
dynamic: true
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
async main(): Promise<void> {
|
|
20
|
+
if (await CliUtil.runWithRestart(this)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Env.addToList('TRV_PROFILES', 'email-dev');
|
|
25
|
+
|
|
21
26
|
await RootRegistry.init();
|
|
22
27
|
await new EditorState(await EmailCompilationManager.createInstance()).init();
|
|
23
28
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { path } from '@travetto/manifest';
|
|
2
2
|
import { RootRegistry } from '@travetto/registry';
|
|
3
3
|
import { CliCommandShape, CliCommand } from '@travetto/cli';
|
|
4
|
-
import { GlobalEnvConfig } from '@travetto/base';
|
|
4
|
+
import { Env, GlobalEnvConfig } from '@travetto/base';
|
|
5
5
|
|
|
6
6
|
import { EmailCompilationManager } from './bin/manager';
|
|
7
7
|
import { EditorConfig } from './bin/config';
|
|
@@ -16,13 +16,12 @@ import { EmailCompiler } from '../src/compiler';
|
|
|
16
16
|
export class EmailTestCommand implements CliCommandShape {
|
|
17
17
|
|
|
18
18
|
envInit(): GlobalEnvConfig {
|
|
19
|
-
return {
|
|
20
|
-
envName: 'dev',
|
|
21
|
-
profiles: ['email-dev']
|
|
22
|
-
};
|
|
19
|
+
return { envName: 'dev' };
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
async main(file: string, to: string): Promise<void> {
|
|
23
|
+
Env.addToList('TRV_PROFILES', 'email-dev');
|
|
24
|
+
|
|
26
25
|
file = path.resolve(file);
|
|
27
26
|
await RootRegistry.init();
|
|
28
27
|
await EmailCompiler.compile(file, true);
|