@travetto/email-compiler 3.3.8 → 3.4.0-rc.0

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.8",
3
+ "version": "3.4.0-rc.0",
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.3.4",
30
- "@travetto/config": "^3.3.5",
31
- "@travetto/di": "^3.3.4",
32
- "@travetto/email": "^3.3.5",
33
- "@travetto/image": "^3.3.4",
34
- "@types/inline-css": "^3.0.1",
29
+ "@travetto/base": "^3.4.0-rc.0",
30
+ "@travetto/config": "^3.4.0-rc.0",
31
+ "@travetto/di": "^3.4.0-rc.0",
32
+ "@travetto/email": "^3.4.0-rc.0",
33
+ "@travetto/image": "^3.4.0-rc.0",
34
+ "@travetto/worker": "^3.4.0-rc.0",
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.68.0"
39
+ "sass": "^1.69.5"
39
40
  },
40
41
  "peerDependencies": {
41
- "@travetto/cli": "^3.3.6"
42
+ "@travetto/cli": "^3.4.0-rc.0"
42
43
  },
43
44
  "peerDependenciesMeta": {
44
45
  "@travetto/cli": {
package/src/compiler.ts CHANGED
@@ -4,16 +4,34 @@ import { FileQueryProvider, TypedObject } from '@travetto/base';
4
4
  import { EmailCompileSource, EmailCompiled, EmailCompileContext, MailUtil } from '@travetto/email';
5
5
  import { RootIndex, path } from '@travetto/manifest';
6
6
  import { DynamicFileLoader } from '@travetto/base/src/internal/file-loader';
7
+ import { ManualAsyncIterator as Queue } from '@travetto/worker';
7
8
 
8
9
  import { EmailCompileUtil } from './util';
9
10
 
10
11
  const VALID_FILE = (file: string): boolean => /[.](scss|css|png|jpe?g|gif|ya?ml)$/.test(file) && !/[.]compiled[.]/.test(file);
11
12
 
13
+ type WatchEvent = { action: 'create' | 'update' | 'delete', file: string, folder: string };
14
+
12
15
  /**
13
16
  * Email compilation support
14
17
  */
15
18
  export class EmailCompiler {
16
19
 
20
+ /**
21
+ * Watch folders as needed
22
+ */
23
+ static async #watchFolders(folders: string[], handler: (ev: WatchEvent) => void, signal: AbortSignal): Promise<void> {
24
+ const lib = await import('@parcel/watcher');
25
+ for (const src of folders) {
26
+ const cleanup = await lib.subscribe(src, async (err, events) => {
27
+ for (const ev of events) {
28
+ handler({ action: ev.type, file: path.toPosix(ev.path), folder: src });
29
+ }
30
+ });
31
+ signal.addEventListener('abort', () => cleanup.unsubscribe());
32
+ }
33
+ }
34
+
17
35
  /** Load Template */
18
36
  static async loadTemplate(file: string): Promise<EmailCompileContext> {
19
37
  const entry = RootIndex.getEntry(file);
@@ -94,7 +112,6 @@ export class EmailCompiler {
94
112
  return keys;
95
113
  }
96
114
 
97
-
98
115
  /**
99
116
  * Watch compilation
100
117
  */
@@ -106,14 +123,20 @@ export class EmailCompiler {
106
123
  )].map(x => path.resolve(RootIndex.getModule(x)!.sourcePath, 'resources'))
107
124
  );
108
125
 
109
- const stream = all.watchFiles();
126
+ const ctrl = new AbortController();
127
+ const stream = new Queue<WatchEvent>([], ctrl.signal);
110
128
 
129
+ // watch resources
130
+ this.#watchFolders(all.paths, ev => stream.add(ev), ctrl.signal);
131
+
132
+ // Watch template files
111
133
  DynamicFileLoader.onLoadEvent((ev) => {
112
134
  const src = RootIndex.getEntry(ev.file);
113
135
  if (src && EmailCompileUtil.isTemplateFile(src.sourceFile)) {
114
136
  stream.add({ ...ev, file: src.sourceFile });
115
137
  }
116
138
  });
139
+
117
140
  for await (const { file, action } of stream) {
118
141
  if (action === 'delete') {
119
142
  continue;
@@ -1,5 +1,5 @@
1
1
  import { GlobalEnvConfig } from '@travetto/base';
2
- import { CliCommand } from '@travetto/cli';
2
+ import { CliCommand, CliUtil } from '@travetto/cli';
3
3
  import { RootRegistry } from '@travetto/registry';
4
4
 
5
5
  import { EditorState } from './bin/editor';
@@ -18,6 +18,9 @@ export class EmailEditorCommand {
18
18
  }
19
19
 
20
20
  async main(): Promise<void> {
21
+ if (await CliUtil.runWithRestart(this)) {
22
+ return;
23
+ }
21
24
  await RootRegistry.init();
22
25
  await new EditorState(await EmailCompilationManager.createInstance()).init();
23
26
  }