react-email 2.1.0 → 2.1.1-canary.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/cli/index.js +205 -77
- package/cli/index.mjs +120 -75
- package/package.json +4 -5
- package/src/utils/get-email-component.ts +6 -0
package/cli/index.js
CHANGED
|
@@ -200,6 +200,20 @@ function _ts_generator(thisArg, body) {
|
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
+
function _ts_values(o) {
|
|
204
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
205
|
+
if (m) return m.call(o);
|
|
206
|
+
if (o && typeof o.length === "number") return {
|
|
207
|
+
next: function() {
|
|
208
|
+
if (o && i >= o.length) o = void 0;
|
|
209
|
+
return {
|
|
210
|
+
value: o && o[i++],
|
|
211
|
+
done: !o
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
216
|
+
}
|
|
203
217
|
var __create = Object.create;
|
|
204
218
|
var __defProp = Object.defineProperty;
|
|
205
219
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -252,7 +266,7 @@ var import_commander = require("commander");
|
|
|
252
266
|
// package.json
|
|
253
267
|
var package_default = {
|
|
254
268
|
name: "react-email",
|
|
255
|
-
version: "2.1.0",
|
|
269
|
+
version: "2.1.1-canary.0",
|
|
256
270
|
description: "A live preview of your emails right in your browser.",
|
|
257
271
|
bin: {
|
|
258
272
|
email: "./cli/index.js"
|
|
@@ -280,11 +294,11 @@ var package_default = {
|
|
|
280
294
|
dependencies: {
|
|
281
295
|
"@radix-ui/colors": "1.0.1",
|
|
282
296
|
"@radix-ui/react-collapsible": "1.0.3",
|
|
283
|
-
"@radix-ui/react-popover": "1.0.
|
|
297
|
+
"@radix-ui/react-popover": "1.0.7",
|
|
284
298
|
"@radix-ui/react-slot": "1.0.2",
|
|
285
299
|
"@radix-ui/react-toggle-group": "1.0.4",
|
|
286
300
|
"@radix-ui/react-tooltip": "1.0.6",
|
|
287
|
-
"@react-email/components": "0.0.
|
|
301
|
+
"@react-email/components": "0.0.16-canary.0",
|
|
288
302
|
"@react-email/render": "0.0.12",
|
|
289
303
|
"@swc/core": "1.3.101",
|
|
290
304
|
"@types/react": "^18.2.0",
|
|
@@ -318,7 +332,6 @@ var package_default = {
|
|
|
318
332
|
"stacktrace-parser": "0.1.10",
|
|
319
333
|
"tailwind-merge": "2.2.0",
|
|
320
334
|
tailwindcss: "3.4.0",
|
|
321
|
-
"tree-cli": "0.6.7",
|
|
322
335
|
typescript: "5.1.6"
|
|
323
336
|
},
|
|
324
337
|
devDependencies: {
|
|
@@ -330,43 +343,158 @@ var package_default = {
|
|
|
330
343
|
"@vercel/style-guide": "5.1.0",
|
|
331
344
|
eslint: "8.50.0",
|
|
332
345
|
tsup: "7.2.0",
|
|
333
|
-
tsx: "4.7.
|
|
346
|
+
tsx: "4.7.1",
|
|
334
347
|
vitest: "1.1.3",
|
|
335
348
|
watch: "1.0.2"
|
|
336
349
|
}
|
|
337
350
|
};
|
|
338
351
|
// src/cli/commands/dev.ts
|
|
339
|
-
var
|
|
352
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
340
353
|
// src/cli/utils/tree.ts
|
|
341
|
-
var
|
|
342
|
-
var
|
|
343
|
-
|
|
344
|
-
|
|
354
|
+
var import_node_fs = require("fs");
|
|
355
|
+
var import_node_os = __toESM(require("os"));
|
|
356
|
+
var import_node_path = __toESM(require("path"));
|
|
357
|
+
var SYMBOLS = {
|
|
358
|
+
BRANCH: "├── ",
|
|
359
|
+
EMPTY: "",
|
|
360
|
+
INDENT: " ",
|
|
361
|
+
LAST_BRANCH: "└── ",
|
|
362
|
+
VERTICAL: "│ "
|
|
363
|
+
};
|
|
364
|
+
var getTreeLines = function() {
|
|
365
|
+
var _ref = _async_to_generator(function(dirPath, depth) {
|
|
366
|
+
var currentDepth, base, dirFullpath, dirname, lines, dirStat, _loop, childDirents, i;
|
|
367
|
+
var _arguments = arguments;
|
|
345
368
|
return _ts_generator(this, function(_state) {
|
|
346
369
|
switch(_state.label){
|
|
347
370
|
case 0:
|
|
371
|
+
currentDepth = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : 0;
|
|
372
|
+
base = process.cwd();
|
|
373
|
+
dirFullpath = import_node_path.default.resolve(base, dirPath);
|
|
374
|
+
dirname = import_node_path.default.basename(dirFullpath);
|
|
375
|
+
lines = [
|
|
376
|
+
dirname
|
|
377
|
+
];
|
|
348
378
|
return [
|
|
349
379
|
4,
|
|
350
|
-
(
|
|
351
|
-
|
|
352
|
-
|
|
380
|
+
import_node_fs.promises.stat(dirFullpath)
|
|
381
|
+
];
|
|
382
|
+
case 1:
|
|
383
|
+
dirStat = _state.sent();
|
|
384
|
+
if (!(dirStat.isDirectory() && currentDepth < depth)) return [
|
|
385
|
+
3,
|
|
386
|
+
6
|
|
387
|
+
];
|
|
388
|
+
_loop = function(i) {
|
|
389
|
+
var dirent, isLast, branchingSymbol, verticalSymbol, pathToDirectory, treeLinesForSubDirectory;
|
|
390
|
+
return _ts_generator(this, function(_state) {
|
|
391
|
+
switch(_state.label){
|
|
392
|
+
case 0:
|
|
393
|
+
dirent = childDirents[i];
|
|
394
|
+
isLast = i === childDirents.length - 1;
|
|
395
|
+
branchingSymbol = isLast ? SYMBOLS.LAST_BRANCH : SYMBOLS.BRANCH;
|
|
396
|
+
verticalSymbol = isLast ? SYMBOLS.INDENT : SYMBOLS.VERTICAL;
|
|
397
|
+
if (!dirent.isFile()) return [
|
|
398
|
+
3,
|
|
399
|
+
1
|
|
400
|
+
];
|
|
401
|
+
lines.push("".concat(branchingSymbol).concat(dirent.name));
|
|
402
|
+
return [
|
|
403
|
+
3,
|
|
404
|
+
3
|
|
405
|
+
];
|
|
406
|
+
case 1:
|
|
407
|
+
pathToDirectory = import_node_path.default.join(dirFullpath, dirent.name);
|
|
408
|
+
return [
|
|
409
|
+
4,
|
|
410
|
+
getTreeLines(pathToDirectory, depth, currentDepth + 1)
|
|
411
|
+
];
|
|
412
|
+
case 2:
|
|
413
|
+
treeLinesForSubDirectory = _state.sent();
|
|
414
|
+
lines = lines.concat(treeLinesForSubDirectory.map(function(line, index) {
|
|
415
|
+
return index === 0 ? "".concat(branchingSymbol).concat(line) : "".concat(verticalSymbol).concat(line);
|
|
416
|
+
}));
|
|
417
|
+
_state.label = 3;
|
|
418
|
+
case 3:
|
|
419
|
+
return [
|
|
420
|
+
2
|
|
421
|
+
];
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
};
|
|
425
|
+
return [
|
|
426
|
+
4,
|
|
427
|
+
import_node_fs.promises.readdir(dirFullpath, {
|
|
428
|
+
withFileTypes: true
|
|
353
429
|
})
|
|
354
430
|
];
|
|
431
|
+
case 2:
|
|
432
|
+
childDirents = _state.sent();
|
|
433
|
+
childDirents.sort(function(a, b) {
|
|
434
|
+
if (a.isDirectory() && b.isFile()) {
|
|
435
|
+
return -1;
|
|
436
|
+
} else if (a.isFile() && b.isDirectory()) {
|
|
437
|
+
return 1;
|
|
438
|
+
}
|
|
439
|
+
return b.name > a.name ? -1 : 1;
|
|
440
|
+
});
|
|
441
|
+
i = 0;
|
|
442
|
+
_state.label = 3;
|
|
443
|
+
case 3:
|
|
444
|
+
if (!(i < childDirents.length)) return [
|
|
445
|
+
3,
|
|
446
|
+
6
|
|
447
|
+
];
|
|
448
|
+
return [
|
|
449
|
+
5,
|
|
450
|
+
_ts_values(_loop(i))
|
|
451
|
+
];
|
|
452
|
+
case 4:
|
|
453
|
+
_state.sent();
|
|
454
|
+
_state.label = 5;
|
|
455
|
+
case 5:
|
|
456
|
+
i++;
|
|
457
|
+
return [
|
|
458
|
+
3,
|
|
459
|
+
3
|
|
460
|
+
];
|
|
461
|
+
case 6:
|
|
462
|
+
return [
|
|
463
|
+
2,
|
|
464
|
+
lines
|
|
465
|
+
];
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
return function getTreeLines(dirPath, depth) {
|
|
470
|
+
return _ref.apply(this, arguments);
|
|
471
|
+
};
|
|
472
|
+
}();
|
|
473
|
+
var tree = function() {
|
|
474
|
+
var _ref = _async_to_generator(function(dirPath, depth) {
|
|
475
|
+
var lines;
|
|
476
|
+
return _ts_generator(this, function(_state) {
|
|
477
|
+
switch(_state.label){
|
|
478
|
+
case 0:
|
|
479
|
+
return [
|
|
480
|
+
4,
|
|
481
|
+
getTreeLines(dirPath, depth)
|
|
482
|
+
];
|
|
355
483
|
case 1:
|
|
356
|
-
|
|
484
|
+
lines = _state.sent();
|
|
357
485
|
return [
|
|
358
486
|
2,
|
|
359
|
-
|
|
487
|
+
lines.join(import_node_os.default.EOL)
|
|
360
488
|
];
|
|
361
489
|
}
|
|
362
490
|
});
|
|
363
491
|
});
|
|
364
|
-
return function tree(
|
|
492
|
+
return function tree(dirPath, depth) {
|
|
365
493
|
return _ref.apply(this, arguments);
|
|
366
494
|
};
|
|
367
495
|
}();
|
|
368
496
|
// src/cli/utils/preview/setup-hot-reloading.ts
|
|
369
|
-
var
|
|
497
|
+
var import_node_path2 = __toESM(require("path"));
|
|
370
498
|
var import_socket = require("socket.io");
|
|
371
499
|
var import_chokidar = require("chokidar");
|
|
372
500
|
var import_debounce = __toESM(require("debounce"));
|
|
@@ -383,7 +511,7 @@ var setupHotreloading = function(devServer2, emailDirRelativePath) {
|
|
|
383
511
|
});
|
|
384
512
|
var watcher = (0, import_chokidar.watch)(emailDirRelativePath, {
|
|
385
513
|
ignoreInitial: true,
|
|
386
|
-
cwd:
|
|
514
|
+
cwd: import_node_path2.default.resolve(process.cwd()),
|
|
387
515
|
// eslint-disable-next-line prefer-named-capture-group
|
|
388
516
|
ignored: /(^|[/\\])\../
|
|
389
517
|
});
|
|
@@ -400,7 +528,7 @@ var setupHotreloading = function(devServer2, emailDirRelativePath) {
|
|
|
400
528
|
changes = [];
|
|
401
529
|
}, 150);
|
|
402
530
|
watcher.on("all", function(event, filename) {
|
|
403
|
-
var file = filename.split(
|
|
531
|
+
var file = filename.split(import_node_path2.default.sep);
|
|
404
532
|
if (file.length === 0) {
|
|
405
533
|
return;
|
|
406
534
|
}
|
|
@@ -413,7 +541,7 @@ var setupHotreloading = function(devServer2, emailDirRelativePath) {
|
|
|
413
541
|
return watcher;
|
|
414
542
|
};
|
|
415
543
|
// src/cli/utils/preview/start-dev-server.ts
|
|
416
|
-
var
|
|
544
|
+
var import_node_path4 = __toESM(require("path"));
|
|
417
545
|
var import_node_http = __toESM(require("http"));
|
|
418
546
|
var import_node_url = __toESM(require("url"));
|
|
419
547
|
var import_next = __toESM(require("next"));
|
|
@@ -427,8 +555,8 @@ var closeOraOnSIGNIT = function(spinner) {
|
|
|
427
555
|
});
|
|
428
556
|
};
|
|
429
557
|
// src/cli/utils/preview/serve-static-file.ts
|
|
430
|
-
var
|
|
431
|
-
var
|
|
558
|
+
var import_node_path3 = __toESM(require("path"));
|
|
559
|
+
var import_node_fs2 = require("fs");
|
|
432
560
|
var import_mime_types = require("mime-types");
|
|
433
561
|
var serveStaticFile = function() {
|
|
434
562
|
var _ref = _async_to_generator(function(res, parsedUrl, staticDirRelativePath) {
|
|
@@ -436,11 +564,11 @@ var serveStaticFile = function() {
|
|
|
436
564
|
return _ts_generator(this, function(_state) {
|
|
437
565
|
switch(_state.label){
|
|
438
566
|
case 0:
|
|
439
|
-
staticBaseDir =
|
|
567
|
+
staticBaseDir = import_node_path3.default.join(process.cwd(), staticDirRelativePath);
|
|
440
568
|
pathname = parsedUrl.pathname;
|
|
441
|
-
ext =
|
|
442
|
-
fileAbsolutePath =
|
|
443
|
-
doesFileExist = (0,
|
|
569
|
+
ext = import_node_path3.default.parse(pathname).ext;
|
|
570
|
+
fileAbsolutePath = import_node_path3.default.join(staticBaseDir, pathname);
|
|
571
|
+
doesFileExist = (0, import_node_fs2.existsSync)(fileAbsolutePath);
|
|
444
572
|
if (!!doesFileExist) return [
|
|
445
573
|
3,
|
|
446
574
|
1
|
|
@@ -454,7 +582,7 @@ var serveStaticFile = function() {
|
|
|
454
582
|
case 1:
|
|
455
583
|
return [
|
|
456
584
|
4,
|
|
457
|
-
|
|
585
|
+
import_node_fs2.promises.stat(fileAbsolutePath)
|
|
458
586
|
];
|
|
459
587
|
case 2:
|
|
460
588
|
fileStat = _state.sent();
|
|
@@ -463,7 +591,7 @@ var serveStaticFile = function() {
|
|
|
463
591
|
}
|
|
464
592
|
return [
|
|
465
593
|
4,
|
|
466
|
-
|
|
594
|
+
import_node_fs2.promises.readFile(fileAbsolutePath)
|
|
467
595
|
];
|
|
468
596
|
case 3:
|
|
469
597
|
fileData = _state.sent();
|
|
@@ -509,8 +637,8 @@ var safeAsyncServerListen = function(server, port) {
|
|
|
509
637
|
});
|
|
510
638
|
});
|
|
511
639
|
};
|
|
512
|
-
var isRunningBuilt = __filename.endsWith(
|
|
513
|
-
var cliPacakgeLocation = isRunningBuilt ?
|
|
640
|
+
var isRunningBuilt = __filename.endsWith(import_node_path4.default.join("cli", "index.js"));
|
|
641
|
+
var cliPacakgeLocation = isRunningBuilt ? import_node_path4.default.resolve(__dirname, "..") : import_node_path4.default.resolve(__dirname, "../../../..");
|
|
514
642
|
var startDevServer = function() {
|
|
515
643
|
var _ref = _async_to_generator(function(emailsDirRelativePath, staticBaseDirRelativePath, port) {
|
|
516
644
|
var portAlreadyInUse, nextPortToTry, spinner, timeBeforeNextReady, app, isNextReady, nextReadyPromise, nextHandleRequest, secondsToNextReady;
|
|
@@ -664,7 +792,7 @@ var dev = function() {
|
|
|
664
792
|
,
|
|
665
793
|
4
|
|
666
794
|
]);
|
|
667
|
-
if (!
|
|
795
|
+
if (!import_node_fs3.default.existsSync(emailsDirRelativePath)) {
|
|
668
796
|
throw new Error("Missing ".concat(emailsDirRelativePath, " folder"));
|
|
669
797
|
}
|
|
670
798
|
return [
|
|
@@ -699,8 +827,8 @@ var dev = function() {
|
|
|
699
827
|
};
|
|
700
828
|
}();
|
|
701
829
|
// src/cli/commands/export.ts
|
|
702
|
-
var
|
|
703
|
-
var
|
|
830
|
+
var import_node_fs5 = __toESM(require("fs"));
|
|
831
|
+
var import_node_path6 = __toESM(require("path"));
|
|
704
832
|
var import_glob = require("glob");
|
|
705
833
|
var import_esbuild = require("esbuild");
|
|
706
834
|
var import_ora2 = __toESM(require("ora"));
|
|
@@ -709,18 +837,18 @@ var import_render = require("@react-email/render");
|
|
|
709
837
|
var import_normalize_path = __toESM(require("normalize-path"));
|
|
710
838
|
var import_shelljs = require("shelljs");
|
|
711
839
|
// src/actions/get-emails-directory-metadata.ts
|
|
712
|
-
var
|
|
713
|
-
var
|
|
840
|
+
var import_node_fs4 = __toESM(require("fs"));
|
|
841
|
+
var import_node_path5 = __toESM(require("path"));
|
|
714
842
|
var isFileAnEmail = function(fullPath) {
|
|
715
|
-
var stat =
|
|
843
|
+
var stat = import_node_fs4.default.statSync(fullPath);
|
|
716
844
|
if (stat.isDirectory()) return false;
|
|
717
|
-
var ext =
|
|
845
|
+
var ext = import_node_path5.default.parse(fullPath).ext;
|
|
718
846
|
if (![
|
|
719
847
|
".js",
|
|
720
848
|
".tsx",
|
|
721
849
|
".jsx"
|
|
722
850
|
].includes(ext)) return false;
|
|
723
|
-
var fileContents =
|
|
851
|
+
var fileContents = import_node_fs4.default.readFileSync(fullPath, "utf8");
|
|
724
852
|
return /\bexport\s+default\b/gm.test(fileContents);
|
|
725
853
|
};
|
|
726
854
|
var mergeDirectoriesWithSubDirectories = function(emailsDirectoryMetadata) {
|
|
@@ -731,7 +859,7 @@ var mergeDirectoriesWithSubDirectories = function(emailsDirectoryMetadata) {
|
|
|
731
859
|
subDirectories: onlySubDirectory.subDirectories,
|
|
732
860
|
emailFilenames: onlySubDirectory.emailFilenames,
|
|
733
861
|
absolutePath: onlySubDirectory.absolutePath,
|
|
734
|
-
directoryName:
|
|
862
|
+
directoryName: import_node_path5.default.join(currentResultingMergedDirectory.directoryName, onlySubDirectory.directoryName)
|
|
735
863
|
};
|
|
736
864
|
}
|
|
737
865
|
return currentResultingMergedDirectory;
|
|
@@ -742,28 +870,28 @@ var getEmailsDirectoryMetadata = function() {
|
|
|
742
870
|
return _ts_generator(this, function(_state) {
|
|
743
871
|
switch(_state.label){
|
|
744
872
|
case 0:
|
|
745
|
-
if (!
|
|
873
|
+
if (!import_node_fs4.default.existsSync(absolutePathToEmailsDirectory)) return [
|
|
746
874
|
2
|
|
747
875
|
];
|
|
748
876
|
return [
|
|
749
877
|
4,
|
|
750
|
-
|
|
878
|
+
import_node_fs4.default.promises.readdir(absolutePathToEmailsDirectory, {
|
|
751
879
|
withFileTypes: true
|
|
752
880
|
})
|
|
753
881
|
];
|
|
754
882
|
case 1:
|
|
755
883
|
dirents = _state.sent();
|
|
756
884
|
emailFilenames = dirents.filter(function(dirent) {
|
|
757
|
-
return isFileAnEmail(
|
|
885
|
+
return isFileAnEmail(import_node_path5.default.join(absolutePathToEmailsDirectory, dirent.name));
|
|
758
886
|
}).map(function(dirent) {
|
|
759
|
-
return dirent.name.replace(
|
|
887
|
+
return dirent.name.replace(import_node_path5.default.extname(dirent.name), "");
|
|
760
888
|
});
|
|
761
889
|
return [
|
|
762
890
|
4,
|
|
763
891
|
Promise.all(dirents.filter(function(dirent) {
|
|
764
892
|
return dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static";
|
|
765
893
|
}).map(function(dirent) {
|
|
766
|
-
return getEmailsDirectoryMetadata(
|
|
894
|
+
return getEmailsDirectoryMetadata(import_node_path5.default.join(absolutePathToEmailsDirectory, dirent.name));
|
|
767
895
|
}))
|
|
768
896
|
];
|
|
769
897
|
case 2:
|
|
@@ -772,7 +900,7 @@ var getEmailsDirectoryMetadata = function() {
|
|
|
772
900
|
2,
|
|
773
901
|
mergeDirectoriesWithSubDirectories({
|
|
774
902
|
absolutePath: absolutePathToEmailsDirectory,
|
|
775
|
-
directoryName: absolutePathToEmailsDirectory.split(
|
|
903
|
+
directoryName: absolutePathToEmailsDirectory.split(import_node_path5.default.sep).pop(),
|
|
776
904
|
emailFilenames: emailFilenames,
|
|
777
905
|
subDirectories: subDirectories
|
|
778
906
|
})
|
|
@@ -788,7 +916,7 @@ var getEmailsDirectoryMetadata = function() {
|
|
|
788
916
|
var getEmailTemplatesFromDirectory = function(emailDirectory) {
|
|
789
917
|
var templatePaths = [];
|
|
790
918
|
emailDirectory.emailFilenames.forEach(function(filename) {
|
|
791
|
-
return templatePaths.push(
|
|
919
|
+
return templatePaths.push(import_node_path6.default.join(emailDirectory.absolutePath, filename));
|
|
792
920
|
});
|
|
793
921
|
emailDirectory.subDirectories.forEach(function(directory) {
|
|
794
922
|
var _templatePaths;
|
|
@@ -806,7 +934,7 @@ var exportTemplates = function() {
|
|
|
806
934
|
closeOraOnSIGNIT(spinner);
|
|
807
935
|
return [
|
|
808
936
|
4,
|
|
809
|
-
getEmailsDirectoryMetadata(
|
|
937
|
+
getEmailsDirectoryMetadata(import_node_path6.default.join(process.cwd(), emailsDirectoryPath))
|
|
810
938
|
];
|
|
811
939
|
case 1:
|
|
812
940
|
emailsDirectoryMetadata = _state.sent();
|
|
@@ -863,8 +991,8 @@ var exportTemplates = function() {
|
|
|
863
991
|
component = require(template);
|
|
864
992
|
rendered = (0, import_render.render)(component.default({}), options);
|
|
865
993
|
htmlPath = template.replace(".cjs", options.plainText ? ".txt" : ".html");
|
|
866
|
-
(0,
|
|
867
|
-
(0,
|
|
994
|
+
(0, import_node_fs5.writeFileSync)(htmlPath, rendered);
|
|
995
|
+
(0, import_node_fs5.unlinkSync)(template);
|
|
868
996
|
} catch (exception) {
|
|
869
997
|
spinner.stopAndPersist({
|
|
870
998
|
symbol: import_log_symbols2.default.error,
|
|
@@ -891,19 +1019,19 @@ var exportTemplates = function() {
|
|
|
891
1019
|
spinner.succeed("Rendered all files");
|
|
892
1020
|
spinner.text = "Copying static files";
|
|
893
1021
|
spinner.render();
|
|
894
|
-
staticDirectoryPath =
|
|
895
|
-
if (!
|
|
1022
|
+
staticDirectoryPath = import_node_path6.default.join(emailsDirectoryPath, "static");
|
|
1023
|
+
if (!import_node_fs5.default.existsSync(staticDirectoryPath)) return [
|
|
896
1024
|
3,
|
|
897
1025
|
4
|
|
898
1026
|
];
|
|
899
|
-
pathToDumpStaticFilesInto =
|
|
900
|
-
if (!
|
|
1027
|
+
pathToDumpStaticFilesInto = import_node_path6.default.join(pathToWhereEmailMarkupShouldBeDumped, "static");
|
|
1028
|
+
if (!import_node_fs5.default.existsSync(pathToDumpStaticFilesInto)) return [
|
|
901
1029
|
3,
|
|
902
1030
|
3
|
|
903
1031
|
];
|
|
904
1032
|
return [
|
|
905
1033
|
4,
|
|
906
|
-
|
|
1034
|
+
import_node_fs5.default.promises.rm(pathToDumpStaticFilesInto, {
|
|
907
1035
|
recursive: true
|
|
908
1036
|
})
|
|
909
1037
|
];
|
|
@@ -911,7 +1039,7 @@ var exportTemplates = function() {
|
|
|
911
1039
|
_state.sent();
|
|
912
1040
|
_state.label = 3;
|
|
913
1041
|
case 3:
|
|
914
|
-
result = (0, import_shelljs.cp)("-r", staticDirectoryPath,
|
|
1042
|
+
result = (0, import_shelljs.cp)("-r", staticDirectoryPath, import_node_path6.default.join(pathToWhereEmailMarkupShouldBeDumped, "static"));
|
|
915
1043
|
if (result.code > 0) {
|
|
916
1044
|
spinner.stopAndPersist({
|
|
917
1045
|
symbol: import_log_symbols2.default.error,
|
|
@@ -945,8 +1073,8 @@ var exportTemplates = function() {
|
|
|
945
1073
|
};
|
|
946
1074
|
}();
|
|
947
1075
|
// src/cli/commands/build.ts
|
|
948
|
-
var
|
|
949
|
-
var
|
|
1076
|
+
var import_node_fs6 = __toESM(require("fs"));
|
|
1077
|
+
var import_node_path7 = __toESM(require("path"));
|
|
950
1078
|
var import_ora3 = __toESM(require("ora"));
|
|
951
1079
|
var import_shelljs2 = __toESM(require("shelljs"));
|
|
952
1080
|
var import_node_child_process = require("child_process");
|
|
@@ -986,7 +1114,7 @@ var setNextEnvironmentVariablesForBuild = function() {
|
|
|
986
1114
|
nextConfigContents = "\nconst path = require('path');\n/** @type {import('next').NextConfig} */\nmodule.exports = {\n env: {\n ...".concat(JSON.stringify(envVariables), ",\n NEXT_PUBLIC_USER_PROJECT_LOCATION: path.resolve(process.cwd(), '../'),\n NEXT_PUBLIC_CLI_PACKAGE_LOCATION: process.cwd(),\n },\n // this is needed so that the code for building emails works properly\n webpack: (\n /** @type {import('webpack').Configuration & { externals: string[] }} */\n config,\n { isServer }\n ) => {\n if (isServer) {\n config.externals.push('esbuild');\n }\n\n return config;\n },\n typescript: {\n ignoreBuildErrors: true\n },\n eslint: {\n ignoreDuringBuilds: true\n },\n experimental: {\n webpackBuildWorker: true,\n serverComponentsExternalPackages: [\n '@react-email/components',\n '@react-email/render',\n '@react-email/tailwind',\n ],\n },\n}");
|
|
987
1115
|
return [
|
|
988
1116
|
4,
|
|
989
|
-
|
|
1117
|
+
import_node_fs6.default.promises.writeFile(import_node_path7.default.resolve(builtPreviewAppPath, "./next.config.js"), nextConfigContents, "utf8")
|
|
990
1118
|
];
|
|
991
1119
|
case 1:
|
|
992
1120
|
_state.sent();
|
|
@@ -1004,7 +1132,7 @@ var getEmailSlugsFromEmailDirectory = function(emailDirectory, emailsDirectoryAb
|
|
|
1004
1132
|
var directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
|
|
1005
1133
|
var slugs = [];
|
|
1006
1134
|
emailDirectory.emailFilenames.forEach(function(filename) {
|
|
1007
|
-
return slugs.push(
|
|
1135
|
+
return slugs.push(import_node_path7.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path7.default.sep).filter(function(segment) {
|
|
1008
1136
|
return segment.length > 0;
|
|
1009
1137
|
}));
|
|
1010
1138
|
});
|
|
@@ -1034,7 +1162,7 @@ var forceSSGForEmailPreviews = function() {
|
|
|
1034
1162
|
});
|
|
1035
1163
|
return [
|
|
1036
1164
|
4,
|
|
1037
|
-
|
|
1165
|
+
import_node_fs6.default.promises.appendFile(import_node_path7.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"), "\n\nexport async function generateStaticParams() { \n return ".concat(JSON.stringify(parameters), ";\n}"), "utf8")
|
|
1038
1166
|
];
|
|
1039
1167
|
case 2:
|
|
1040
1168
|
_state.sent();
|
|
@@ -1054,11 +1182,11 @@ var updatePackageJson = function() {
|
|
|
1054
1182
|
return _ts_generator(this, function(_state) {
|
|
1055
1183
|
switch(_state.label){
|
|
1056
1184
|
case 0:
|
|
1057
|
-
packageJsonPath =
|
|
1185
|
+
packageJsonPath = import_node_path7.default.resolve(builtPreviewAppPath, "./package.json");
|
|
1058
1186
|
_ = JSON.parse;
|
|
1059
1187
|
return [
|
|
1060
1188
|
4,
|
|
1061
|
-
|
|
1189
|
+
import_node_fs6.default.promises.readFile(packageJsonPath, "utf8")
|
|
1062
1190
|
];
|
|
1063
1191
|
case 1:
|
|
1064
1192
|
packageJson = _.apply(JSON, [
|
|
@@ -1069,7 +1197,7 @@ var updatePackageJson = function() {
|
|
|
1069
1197
|
packageJson.dependencies.sharp = "0.33.2";
|
|
1070
1198
|
return [
|
|
1071
1199
|
4,
|
|
1072
|
-
|
|
1200
|
+
import_node_fs6.default.promises.writeFile(packageJsonPath, JSON.stringify(packageJson), "utf8")
|
|
1073
1201
|
];
|
|
1074
1202
|
case 2:
|
|
1075
1203
|
_state.sent();
|
|
@@ -1127,20 +1255,20 @@ var build = function() {
|
|
|
1127
1255
|
}).start();
|
|
1128
1256
|
closeOraOnSIGNIT(spinner);
|
|
1129
1257
|
spinner.text = "Checking if emails folder exists";
|
|
1130
|
-
if (!
|
|
1258
|
+
if (!import_node_fs6.default.existsSync(emailsDirRelativePath)) {
|
|
1131
1259
|
throw new Error("Missing ".concat(emailsDirRelativePath, " folder"));
|
|
1132
1260
|
}
|
|
1133
|
-
emailsDirPath =
|
|
1134
|
-
staticPath =
|
|
1135
|
-
builtPreviewAppPath =
|
|
1136
|
-
if (!
|
|
1261
|
+
emailsDirPath = import_node_path7.default.join(process.cwd(), emailsDirRelativePath);
|
|
1262
|
+
staticPath = import_node_path7.default.join(emailsDirPath, "static");
|
|
1263
|
+
builtPreviewAppPath = import_node_path7.default.join(process.cwd(), ".react-email");
|
|
1264
|
+
if (!import_node_fs6.default.existsSync(builtPreviewAppPath)) return [
|
|
1137
1265
|
3,
|
|
1138
1266
|
3
|
|
1139
1267
|
];
|
|
1140
1268
|
spinner.text = "Deleting pre-existing `.react-email` folder";
|
|
1141
1269
|
return [
|
|
1142
1270
|
4,
|
|
1143
|
-
|
|
1271
|
+
import_node_fs6.default.promises.rm(builtPreviewAppPath, {
|
|
1144
1272
|
recursive: true
|
|
1145
1273
|
})
|
|
1146
1274
|
];
|
|
@@ -1151,7 +1279,7 @@ var build = function() {
|
|
|
1151
1279
|
spinner.text = "Copying preview app from CLI to `.react-email`";
|
|
1152
1280
|
return [
|
|
1153
1281
|
4,
|
|
1154
|
-
|
|
1282
|
+
import_node_fs6.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
|
|
1155
1283
|
recursive: true,
|
|
1156
1284
|
filter: function(source) {
|
|
1157
1285
|
return !source.includes("/cli/") && !source.includes("/.next/") && !/\/node_modules\/?$/.test(source);
|
|
@@ -1160,15 +1288,15 @@ var build = function() {
|
|
|
1160
1288
|
];
|
|
1161
1289
|
case 4:
|
|
1162
1290
|
_state.sent();
|
|
1163
|
-
if (!
|
|
1291
|
+
if (!import_node_fs6.default.existsSync(staticPath)) return [
|
|
1164
1292
|
3,
|
|
1165
1293
|
6
|
|
1166
1294
|
];
|
|
1167
1295
|
spinner.text = "Copying `static` folder into `.react-email/public/static`";
|
|
1168
|
-
builtStaticDirectory =
|
|
1296
|
+
builtStaticDirectory = import_node_path7.default.resolve(builtPreviewAppPath, "./public/static");
|
|
1169
1297
|
return [
|
|
1170
1298
|
4,
|
|
1171
|
-
|
|
1299
|
+
import_node_fs6.default.promises.cp(staticPath, builtStaticDirectory, {
|
|
1172
1300
|
recursive: true
|
|
1173
1301
|
})
|
|
1174
1302
|
];
|
|
@@ -1238,8 +1366,8 @@ var build = function() {
|
|
|
1238
1366
|
};
|
|
1239
1367
|
}();
|
|
1240
1368
|
// src/cli/commands/start.ts
|
|
1241
|
-
var
|
|
1242
|
-
var
|
|
1369
|
+
var import_node_fs7 = __toESM(require("fs"));
|
|
1370
|
+
var import_node_path8 = __toESM(require("path"));
|
|
1243
1371
|
var import_node_child_process2 = require("child_process");
|
|
1244
1372
|
var start = function() {
|
|
1245
1373
|
var _ref = _async_to_generator(function() {
|
|
@@ -1247,8 +1375,8 @@ var start = function() {
|
|
|
1247
1375
|
return _ts_generator(this, function(_state) {
|
|
1248
1376
|
try {
|
|
1249
1377
|
usersProjectLocation = process.cwd();
|
|
1250
|
-
builtPreviewPath =
|
|
1251
|
-
if (!
|
|
1378
|
+
builtPreviewPath = import_node_path8.default.resolve(usersProjectLocation, "./.react-email");
|
|
1379
|
+
if (!import_node_fs7.default.existsSync(builtPreviewPath)) {
|
|
1252
1380
|
throw new Error("Could not find `.react-email`, maybe you haven't ran `email build`?");
|
|
1253
1381
|
}
|
|
1254
1382
|
nextStart = (0, import_node_child_process2.spawn)("npm", [
|
package/cli/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { program } from "commander";
|
|
|
13
13
|
// package.json
|
|
14
14
|
var package_default = {
|
|
15
15
|
name: "react-email",
|
|
16
|
-
version: "2.1.0",
|
|
16
|
+
version: "2.1.1-canary.0",
|
|
17
17
|
description: "A live preview of your emails right in your browser.",
|
|
18
18
|
bin: {
|
|
19
19
|
email: "./cli/index.js"
|
|
@@ -41,11 +41,11 @@ var package_default = {
|
|
|
41
41
|
dependencies: {
|
|
42
42
|
"@radix-ui/colors": "1.0.1",
|
|
43
43
|
"@radix-ui/react-collapsible": "1.0.3",
|
|
44
|
-
"@radix-ui/react-popover": "1.0.
|
|
44
|
+
"@radix-ui/react-popover": "1.0.7",
|
|
45
45
|
"@radix-ui/react-slot": "1.0.2",
|
|
46
46
|
"@radix-ui/react-toggle-group": "1.0.4",
|
|
47
47
|
"@radix-ui/react-tooltip": "1.0.6",
|
|
48
|
-
"@react-email/components": "0.0.
|
|
48
|
+
"@react-email/components": "0.0.16-canary.0",
|
|
49
49
|
"@react-email/render": "0.0.12",
|
|
50
50
|
"@swc/core": "1.3.101",
|
|
51
51
|
"@types/react": "^18.2.0",
|
|
@@ -79,7 +79,6 @@ var package_default = {
|
|
|
79
79
|
"stacktrace-parser": "0.1.10",
|
|
80
80
|
"tailwind-merge": "2.2.0",
|
|
81
81
|
tailwindcss: "3.4.0",
|
|
82
|
-
"tree-cli": "0.6.7",
|
|
83
82
|
typescript: "5.1.6"
|
|
84
83
|
},
|
|
85
84
|
devDependencies: {
|
|
@@ -91,27 +90,73 @@ var package_default = {
|
|
|
91
90
|
"@vercel/style-guide": "5.1.0",
|
|
92
91
|
eslint: "8.50.0",
|
|
93
92
|
tsup: "7.2.0",
|
|
94
|
-
tsx: "4.7.
|
|
93
|
+
tsx: "4.7.1",
|
|
95
94
|
vitest: "1.1.3",
|
|
96
95
|
watch: "1.0.2"
|
|
97
96
|
}
|
|
98
97
|
};
|
|
99
98
|
|
|
100
99
|
// src/cli/commands/dev.ts
|
|
101
|
-
import
|
|
100
|
+
import fs3 from "fs";
|
|
102
101
|
|
|
103
102
|
// src/cli/utils/tree.ts
|
|
104
|
-
import
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
import { promises as fs } from "fs";
|
|
104
|
+
import os from "os";
|
|
105
|
+
import path from "path";
|
|
106
|
+
var SYMBOLS = {
|
|
107
|
+
BRANCH: "\u251C\u2500\u2500 ",
|
|
108
|
+
EMPTY: "",
|
|
109
|
+
INDENT: " ",
|
|
110
|
+
LAST_BRANCH: "\u2514\u2500\u2500 ",
|
|
111
|
+
VERTICAL: "\u2502 "
|
|
112
|
+
};
|
|
113
|
+
var getTreeLines = async (dirPath, depth, currentDepth = 0) => {
|
|
114
|
+
const base = process.cwd();
|
|
115
|
+
const dirFullpath = path.resolve(base, dirPath);
|
|
116
|
+
const dirname = path.basename(dirFullpath);
|
|
117
|
+
let lines = [dirname];
|
|
118
|
+
const dirStat = await fs.stat(dirFullpath);
|
|
119
|
+
if (dirStat.isDirectory() && currentDepth < depth) {
|
|
120
|
+
const childDirents = await fs.readdir(dirFullpath, { withFileTypes: true });
|
|
121
|
+
childDirents.sort((a, b) => {
|
|
122
|
+
if (a.isDirectory() && b.isFile()) {
|
|
123
|
+
return -1;
|
|
124
|
+
} else if (a.isFile() && b.isDirectory()) {
|
|
125
|
+
return 1;
|
|
126
|
+
}
|
|
127
|
+
return b.name > a.name ? -1 : 1;
|
|
128
|
+
});
|
|
129
|
+
for (let i = 0; i < childDirents.length; i++) {
|
|
130
|
+
const dirent = childDirents[i];
|
|
131
|
+
const isLast = i === childDirents.length - 1;
|
|
132
|
+
const branchingSymbol = isLast ? SYMBOLS.LAST_BRANCH : SYMBOLS.BRANCH;
|
|
133
|
+
const verticalSymbol = isLast ? SYMBOLS.INDENT : SYMBOLS.VERTICAL;
|
|
134
|
+
if (dirent.isFile()) {
|
|
135
|
+
lines.push(`${branchingSymbol}${dirent.name}`);
|
|
136
|
+
} else {
|
|
137
|
+
const pathToDirectory = path.join(dirFullpath, dirent.name);
|
|
138
|
+
const treeLinesForSubDirectory = await getTreeLines(
|
|
139
|
+
pathToDirectory,
|
|
140
|
+
depth,
|
|
141
|
+
currentDepth + 1
|
|
142
|
+
);
|
|
143
|
+
lines = lines.concat(
|
|
144
|
+
treeLinesForSubDirectory.map(
|
|
145
|
+
(line, index) => index === 0 ? `${branchingSymbol}${line}` : `${verticalSymbol}${line}`
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return lines;
|
|
152
|
+
};
|
|
153
|
+
var tree = async (dirPath, depth) => {
|
|
154
|
+
const lines = await getTreeLines(dirPath, depth);
|
|
155
|
+
return lines.join(os.EOL);
|
|
111
156
|
};
|
|
112
157
|
|
|
113
158
|
// src/cli/utils/preview/setup-hot-reloading.ts
|
|
114
|
-
import
|
|
159
|
+
import path2 from "path";
|
|
115
160
|
import { Server as SocketServer } from "socket.io";
|
|
116
161
|
import { watch } from "chokidar";
|
|
117
162
|
import debounce from "debounce";
|
|
@@ -126,7 +171,7 @@ var setupHotreloading = (devServer2, emailDirRelativePath) => {
|
|
|
126
171
|
});
|
|
127
172
|
const watcher = watch(emailDirRelativePath, {
|
|
128
173
|
ignoreInitial: true,
|
|
129
|
-
cwd:
|
|
174
|
+
cwd: path2.resolve(process.cwd()),
|
|
130
175
|
// eslint-disable-next-line prefer-named-capture-group
|
|
131
176
|
ignored: /(^|[/\\])\../
|
|
132
177
|
});
|
|
@@ -143,7 +188,7 @@ var setupHotreloading = (devServer2, emailDirRelativePath) => {
|
|
|
143
188
|
changes = [];
|
|
144
189
|
}, 150);
|
|
145
190
|
watcher.on("all", (event, filename) => {
|
|
146
|
-
const file = filename.split(
|
|
191
|
+
const file = filename.split(path2.sep);
|
|
147
192
|
if (file.length === 0) {
|
|
148
193
|
return;
|
|
149
194
|
}
|
|
@@ -157,7 +202,7 @@ var setupHotreloading = (devServer2, emailDirRelativePath) => {
|
|
|
157
202
|
};
|
|
158
203
|
|
|
159
204
|
// src/cli/utils/preview/start-dev-server.ts
|
|
160
|
-
import
|
|
205
|
+
import path5 from "path";
|
|
161
206
|
import http from "http";
|
|
162
207
|
import url from "url";
|
|
163
208
|
import next from "next";
|
|
@@ -173,36 +218,36 @@ var closeOraOnSIGNIT = (spinner) => {
|
|
|
173
218
|
};
|
|
174
219
|
|
|
175
220
|
// src/cli/utils/preview/serve-static-file.ts
|
|
176
|
-
import
|
|
177
|
-
import { promises as
|
|
221
|
+
import path3 from "path";
|
|
222
|
+
import { promises as fs2, existsSync } from "fs";
|
|
178
223
|
import { lookup } from "mime-types";
|
|
179
224
|
var serveStaticFile = async (res, parsedUrl, staticDirRelativePath) => {
|
|
180
|
-
const staticBaseDir =
|
|
225
|
+
const staticBaseDir = path3.join(process.cwd(), staticDirRelativePath);
|
|
181
226
|
const pathname = parsedUrl.pathname;
|
|
182
|
-
const ext =
|
|
183
|
-
let fileAbsolutePath =
|
|
227
|
+
const ext = path3.parse(pathname).ext;
|
|
228
|
+
let fileAbsolutePath = path3.join(staticBaseDir, pathname);
|
|
184
229
|
const doesFileExist = existsSync(fileAbsolutePath);
|
|
185
230
|
if (!doesFileExist) {
|
|
186
231
|
res.statusCode = 404;
|
|
187
232
|
res.end(`File ${pathname} not found!`);
|
|
188
233
|
} else {
|
|
189
|
-
const fileStat = await
|
|
234
|
+
const fileStat = await fs2.stat(fileAbsolutePath);
|
|
190
235
|
if (fileStat.isDirectory()) {
|
|
191
236
|
fileAbsolutePath += `/index${ext}`;
|
|
192
237
|
}
|
|
193
|
-
const fileData = await
|
|
238
|
+
const fileData = await fs2.readFile(fileAbsolutePath);
|
|
194
239
|
res.setHeader("Content-type", lookup(ext) || "text/plain");
|
|
195
240
|
res.end(fileData);
|
|
196
241
|
}
|
|
197
242
|
};
|
|
198
243
|
|
|
199
244
|
// src/cli/utils/preview/get-env-variables-for-preview-app.ts
|
|
200
|
-
import
|
|
245
|
+
import path4 from "path";
|
|
201
246
|
var getEnvVariablesForPreviewApp = (relativePathToEmailsDirectory, cliPackageLocation, cwd) => {
|
|
202
247
|
return {
|
|
203
248
|
NEXT_PUBLIC_EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
|
|
204
249
|
NEXT_PUBLIC_CLI_PACKAGE_LOCATION: cliPackageLocation,
|
|
205
|
-
NEXT_PUBLIC_OS_PATH_SEPARATOR:
|
|
250
|
+
NEXT_PUBLIC_OS_PATH_SEPARATOR: path4.sep,
|
|
206
251
|
NEXT_PUBLIC_USER_PROJECT_LOCATION: cwd
|
|
207
252
|
};
|
|
208
253
|
};
|
|
@@ -221,8 +266,8 @@ var safeAsyncServerListen = (server, port) => {
|
|
|
221
266
|
});
|
|
222
267
|
});
|
|
223
268
|
};
|
|
224
|
-
var isRunningBuilt = __filename.endsWith(
|
|
225
|
-
var cliPacakgeLocation = isRunningBuilt ?
|
|
269
|
+
var isRunningBuilt = __filename.endsWith(path5.join("cli", "index.js"));
|
|
270
|
+
var cliPacakgeLocation = isRunningBuilt ? path5.resolve(__dirname, "..") : path5.resolve(__dirname, "../../../..");
|
|
226
271
|
var startDevServer = async (emailsDirRelativePath, staticBaseDirRelativePath, port) => {
|
|
227
272
|
devServer = http.createServer((req, res) => {
|
|
228
273
|
if (!req.url) {
|
|
@@ -343,7 +388,7 @@ process.on(
|
|
|
343
388
|
// src/cli/commands/dev.ts
|
|
344
389
|
var dev = async ({ dir: emailsDirRelativePath, port }) => {
|
|
345
390
|
try {
|
|
346
|
-
if (!
|
|
391
|
+
if (!fs3.existsSync(emailsDirRelativePath)) {
|
|
347
392
|
throw new Error(`Missing ${emailsDirRelativePath} folder`);
|
|
348
393
|
}
|
|
349
394
|
const devServer2 = await startDevServer(
|
|
@@ -360,8 +405,8 @@ var dev = async ({ dir: emailsDirRelativePath, port }) => {
|
|
|
360
405
|
};
|
|
361
406
|
|
|
362
407
|
// src/cli/commands/export.ts
|
|
363
|
-
import
|
|
364
|
-
import
|
|
408
|
+
import fs5, { unlinkSync, writeFileSync } from "fs";
|
|
409
|
+
import path7 from "path";
|
|
365
410
|
import { glob } from "glob";
|
|
366
411
|
import { buildSync } from "esbuild";
|
|
367
412
|
import ora2 from "ora";
|
|
@@ -371,16 +416,16 @@ import normalize from "normalize-path";
|
|
|
371
416
|
import { cp } from "shelljs";
|
|
372
417
|
|
|
373
418
|
// src/actions/get-emails-directory-metadata.ts
|
|
374
|
-
import
|
|
375
|
-
import
|
|
419
|
+
import fs4 from "fs";
|
|
420
|
+
import path6 from "path";
|
|
376
421
|
var isFileAnEmail = (fullPath) => {
|
|
377
|
-
const stat =
|
|
422
|
+
const stat = fs4.statSync(fullPath);
|
|
378
423
|
if (stat.isDirectory())
|
|
379
424
|
return false;
|
|
380
|
-
const { ext } =
|
|
425
|
+
const { ext } = path6.parse(fullPath);
|
|
381
426
|
if (![".js", ".tsx", ".jsx"].includes(ext))
|
|
382
427
|
return false;
|
|
383
|
-
const fileContents =
|
|
428
|
+
const fileContents = fs4.readFileSync(fullPath, "utf8");
|
|
384
429
|
return /\bexport\s+default\b/gm.test(fileContents);
|
|
385
430
|
};
|
|
386
431
|
var mergeDirectoriesWithSubDirectories = (emailsDirectoryMetadata) => {
|
|
@@ -391,7 +436,7 @@ var mergeDirectoriesWithSubDirectories = (emailsDirectoryMetadata) => {
|
|
|
391
436
|
subDirectories: onlySubDirectory.subDirectories,
|
|
392
437
|
emailFilenames: onlySubDirectory.emailFilenames,
|
|
393
438
|
absolutePath: onlySubDirectory.absolutePath,
|
|
394
|
-
directoryName:
|
|
439
|
+
directoryName: path6.join(
|
|
395
440
|
currentResultingMergedDirectory.directoryName,
|
|
396
441
|
onlySubDirectory.directoryName
|
|
397
442
|
)
|
|
@@ -400,26 +445,26 @@ var mergeDirectoriesWithSubDirectories = (emailsDirectoryMetadata) => {
|
|
|
400
445
|
return currentResultingMergedDirectory;
|
|
401
446
|
};
|
|
402
447
|
var getEmailsDirectoryMetadata = async (absolutePathToEmailsDirectory) => {
|
|
403
|
-
if (!
|
|
448
|
+
if (!fs4.existsSync(absolutePathToEmailsDirectory))
|
|
404
449
|
return;
|
|
405
|
-
const dirents = await
|
|
450
|
+
const dirents = await fs4.promises.readdir(absolutePathToEmailsDirectory, {
|
|
406
451
|
withFileTypes: true
|
|
407
452
|
});
|
|
408
453
|
const emailFilenames = dirents.filter(
|
|
409
|
-
(dirent) => isFileAnEmail(
|
|
410
|
-
).map((dirent) => dirent.name.replace(
|
|
454
|
+
(dirent) => isFileAnEmail(path6.join(absolutePathToEmailsDirectory, dirent.name))
|
|
455
|
+
).map((dirent) => dirent.name.replace(path6.extname(dirent.name), ""));
|
|
411
456
|
const subDirectories = await Promise.all(
|
|
412
457
|
dirents.filter(
|
|
413
458
|
(dirent) => dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static"
|
|
414
459
|
).map(
|
|
415
460
|
(dirent) => getEmailsDirectoryMetadata(
|
|
416
|
-
|
|
461
|
+
path6.join(absolutePathToEmailsDirectory, dirent.name)
|
|
417
462
|
)
|
|
418
463
|
)
|
|
419
464
|
);
|
|
420
465
|
return mergeDirectoriesWithSubDirectories({
|
|
421
466
|
absolutePath: absolutePathToEmailsDirectory,
|
|
422
|
-
directoryName: absolutePathToEmailsDirectory.split(
|
|
467
|
+
directoryName: absolutePathToEmailsDirectory.split(path6.sep).pop(),
|
|
423
468
|
emailFilenames,
|
|
424
469
|
subDirectories
|
|
425
470
|
});
|
|
@@ -429,7 +474,7 @@ var getEmailsDirectoryMetadata = async (absolutePathToEmailsDirectory) => {
|
|
|
429
474
|
var getEmailTemplatesFromDirectory = (emailDirectory) => {
|
|
430
475
|
const templatePaths = [];
|
|
431
476
|
emailDirectory.emailFilenames.forEach(
|
|
432
|
-
(filename) => templatePaths.push(
|
|
477
|
+
(filename) => templatePaths.push(path7.join(emailDirectory.absolutePath, filename))
|
|
433
478
|
);
|
|
434
479
|
emailDirectory.subDirectories.forEach((directory) => {
|
|
435
480
|
templatePaths.push(...getEmailTemplatesFromDirectory(directory));
|
|
@@ -440,7 +485,7 @@ var exportTemplates = async (pathToWhereEmailMarkupShouldBeDumped, emailsDirecto
|
|
|
440
485
|
const spinner = ora2("Preparing files...\n").start();
|
|
441
486
|
closeOraOnSIGNIT(spinner);
|
|
442
487
|
const emailsDirectoryMetadata = await getEmailsDirectoryMetadata(
|
|
443
|
-
|
|
488
|
+
path7.join(process.cwd(), emailsDirectoryPath)
|
|
444
489
|
);
|
|
445
490
|
if (typeof emailsDirectoryMetadata === "undefined") {
|
|
446
491
|
spinner.stopAndPersist({
|
|
@@ -507,18 +552,18 @@ ${allTemplates.map((p) => `- ${p}`).join("\n")}`
|
|
|
507
552
|
spinner.succeed("Rendered all files");
|
|
508
553
|
spinner.text = `Copying static files`;
|
|
509
554
|
spinner.render();
|
|
510
|
-
const staticDirectoryPath =
|
|
511
|
-
if (
|
|
512
|
-
const pathToDumpStaticFilesInto =
|
|
555
|
+
const staticDirectoryPath = path7.join(emailsDirectoryPath, "static");
|
|
556
|
+
if (fs5.existsSync(staticDirectoryPath)) {
|
|
557
|
+
const pathToDumpStaticFilesInto = path7.join(
|
|
513
558
|
pathToWhereEmailMarkupShouldBeDumped,
|
|
514
559
|
"static"
|
|
515
560
|
);
|
|
516
|
-
if (
|
|
517
|
-
await
|
|
561
|
+
if (fs5.existsSync(pathToDumpStaticFilesInto))
|
|
562
|
+
await fs5.promises.rm(pathToDumpStaticFilesInto, { recursive: true });
|
|
518
563
|
const result = cp(
|
|
519
564
|
"-r",
|
|
520
565
|
staticDirectoryPath,
|
|
521
|
-
|
|
566
|
+
path7.join(pathToWhereEmailMarkupShouldBeDumped, "static")
|
|
522
567
|
);
|
|
523
568
|
if (result.code > 0) {
|
|
524
569
|
spinner.stopAndPersist({
|
|
@@ -541,8 +586,8 @@ ${allTemplates.map((p) => `- ${p}`).join("\n")}`
|
|
|
541
586
|
};
|
|
542
587
|
|
|
543
588
|
// src/cli/commands/build.ts
|
|
544
|
-
import
|
|
545
|
-
import
|
|
589
|
+
import fs6 from "fs";
|
|
590
|
+
import path8 from "path";
|
|
546
591
|
import ora3 from "ora";
|
|
547
592
|
import shell from "shelljs";
|
|
548
593
|
import { spawn } from "child_process";
|
|
@@ -616,8 +661,8 @@ module.exports = {
|
|
|
616
661
|
],
|
|
617
662
|
},
|
|
618
663
|
}`;
|
|
619
|
-
await
|
|
620
|
-
|
|
664
|
+
await fs6.promises.writeFile(
|
|
665
|
+
path8.resolve(builtPreviewAppPath, "./next.config.js"),
|
|
621
666
|
nextConfigContents,
|
|
622
667
|
"utf8"
|
|
623
668
|
);
|
|
@@ -627,7 +672,7 @@ var getEmailSlugsFromEmailDirectory = (emailDirectory, emailsDirectoryAbsolutePa
|
|
|
627
672
|
const slugs = [];
|
|
628
673
|
emailDirectory.emailFilenames.forEach(
|
|
629
674
|
(filename) => slugs.push(
|
|
630
|
-
|
|
675
|
+
path8.join(directoryPathRelativeToEmailsDirectory, filename).split(path8.sep).filter((segment) => segment.length > 0)
|
|
631
676
|
)
|
|
632
677
|
);
|
|
633
678
|
emailDirectory.subDirectories.forEach((directory) => {
|
|
@@ -649,8 +694,8 @@ var forceSSGForEmailPreviews = async (emailsDirPath, builtPreviewAppPath) => {
|
|
|
649
694
|
emailDirectoryMetadata,
|
|
650
695
|
emailsDirPath
|
|
651
696
|
).map((slug) => ({ slug }));
|
|
652
|
-
await
|
|
653
|
-
|
|
697
|
+
await fs6.promises.appendFile(
|
|
698
|
+
path8.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"),
|
|
654
699
|
`
|
|
655
700
|
|
|
656
701
|
export async function generateStaticParams() {
|
|
@@ -660,14 +705,14 @@ export async function generateStaticParams() {
|
|
|
660
705
|
);
|
|
661
706
|
};
|
|
662
707
|
var updatePackageJson = async (builtPreviewAppPath) => {
|
|
663
|
-
const packageJsonPath =
|
|
708
|
+
const packageJsonPath = path8.resolve(builtPreviewAppPath, "./package.json");
|
|
664
709
|
const packageJson = JSON.parse(
|
|
665
|
-
await
|
|
710
|
+
await fs6.promises.readFile(packageJsonPath, "utf8")
|
|
666
711
|
);
|
|
667
712
|
packageJson.scripts.build = "next build";
|
|
668
713
|
packageJson.scripts.start = "next start";
|
|
669
714
|
packageJson.dependencies.sharp = "0.33.2";
|
|
670
|
-
await
|
|
715
|
+
await fs6.promises.writeFile(
|
|
671
716
|
packageJsonPath,
|
|
672
717
|
JSON.stringify(packageJson),
|
|
673
718
|
"utf8"
|
|
@@ -703,30 +748,30 @@ var build = async ({
|
|
|
703
748
|
}).start();
|
|
704
749
|
closeOraOnSIGNIT(spinner);
|
|
705
750
|
spinner.text = "Checking if emails folder exists";
|
|
706
|
-
if (!
|
|
751
|
+
if (!fs6.existsSync(emailsDirRelativePath)) {
|
|
707
752
|
throw new Error(`Missing ${emailsDirRelativePath} folder`);
|
|
708
753
|
}
|
|
709
|
-
const emailsDirPath =
|
|
710
|
-
const staticPath =
|
|
711
|
-
const builtPreviewAppPath =
|
|
712
|
-
if (
|
|
754
|
+
const emailsDirPath = path8.join(process.cwd(), emailsDirRelativePath);
|
|
755
|
+
const staticPath = path8.join(emailsDirPath, "static");
|
|
756
|
+
const builtPreviewAppPath = path8.join(process.cwd(), ".react-email");
|
|
757
|
+
if (fs6.existsSync(builtPreviewAppPath)) {
|
|
713
758
|
spinner.text = "Deleting pre-existing `.react-email` folder";
|
|
714
|
-
await
|
|
759
|
+
await fs6.promises.rm(builtPreviewAppPath, { recursive: true });
|
|
715
760
|
}
|
|
716
761
|
spinner.text = "Copying preview app from CLI to `.react-email`";
|
|
717
|
-
await
|
|
762
|
+
await fs6.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
|
|
718
763
|
recursive: true,
|
|
719
764
|
filter: (source) => {
|
|
720
765
|
return !source.includes("/cli/") && !source.includes("/.next/") && !/\/node_modules\/?$/.test(source);
|
|
721
766
|
}
|
|
722
767
|
});
|
|
723
|
-
if (
|
|
768
|
+
if (fs6.existsSync(staticPath)) {
|
|
724
769
|
spinner.text = "Copying `static` folder into `.react-email/public/static`";
|
|
725
|
-
const builtStaticDirectory =
|
|
770
|
+
const builtStaticDirectory = path8.resolve(
|
|
726
771
|
builtPreviewAppPath,
|
|
727
772
|
"./public/static"
|
|
728
773
|
);
|
|
729
|
-
await
|
|
774
|
+
await fs6.promises.cp(staticPath, builtStaticDirectory, {
|
|
730
775
|
recursive: true
|
|
731
776
|
});
|
|
732
777
|
}
|
|
@@ -753,17 +798,17 @@ var build = async ({
|
|
|
753
798
|
};
|
|
754
799
|
|
|
755
800
|
// src/cli/commands/start.ts
|
|
756
|
-
import
|
|
757
|
-
import
|
|
801
|
+
import fs7 from "fs";
|
|
802
|
+
import path9 from "path";
|
|
758
803
|
import { spawn as spawn2 } from "child_process";
|
|
759
804
|
var start = async () => {
|
|
760
805
|
try {
|
|
761
806
|
const usersProjectLocation = process.cwd();
|
|
762
|
-
const builtPreviewPath =
|
|
807
|
+
const builtPreviewPath = path9.resolve(
|
|
763
808
|
usersProjectLocation,
|
|
764
809
|
"./.react-email"
|
|
765
810
|
);
|
|
766
|
-
if (!
|
|
811
|
+
if (!fs7.existsSync(builtPreviewPath)) {
|
|
767
812
|
throw new Error(
|
|
768
813
|
"Could not find `.react-email`, maybe you haven't ran `email build`?"
|
|
769
814
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-email",
|
|
3
|
-
"version": "2.1.0",
|
|
3
|
+
"version": "2.1.1-canary.0",
|
|
4
4
|
"description": "A live preview of your emails right in your browser.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"email": "./cli/index.js"
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@radix-ui/colors": "1.0.1",
|
|
23
23
|
"@radix-ui/react-collapsible": "1.0.3",
|
|
24
|
-
"@radix-ui/react-popover": "1.0.
|
|
24
|
+
"@radix-ui/react-popover": "1.0.7",
|
|
25
25
|
"@radix-ui/react-slot": "1.0.2",
|
|
26
26
|
"@radix-ui/react-toggle-group": "1.0.4",
|
|
27
27
|
"@radix-ui/react-tooltip": "1.0.6",
|
|
28
|
-
"@react-email/components": "0.0.
|
|
28
|
+
"@react-email/components": "0.0.16-canary.0",
|
|
29
29
|
"@react-email/render": "0.0.12",
|
|
30
30
|
"@swc/core": "1.3.101",
|
|
31
31
|
"@types/react": "^18.2.0",
|
|
@@ -59,7 +59,6 @@
|
|
|
59
59
|
"stacktrace-parser": "0.1.10",
|
|
60
60
|
"tailwind-merge": "2.2.0",
|
|
61
61
|
"tailwindcss": "3.4.0",
|
|
62
|
-
"tree-cli": "0.6.7",
|
|
63
62
|
"typescript": "5.1.6"
|
|
64
63
|
},
|
|
65
64
|
"devDependencies": {
|
|
@@ -71,7 +70,7 @@
|
|
|
71
70
|
"@vercel/style-guide": "5.1.0",
|
|
72
71
|
"eslint": "8.50.0",
|
|
73
72
|
"tsup": "7.2.0",
|
|
74
|
-
"tsx": "4.7.
|
|
73
|
+
"tsx": "4.7.1",
|
|
75
74
|
"vitest": "1.1.3",
|
|
76
75
|
"watch": "1.0.2"
|
|
77
76
|
},
|
|
@@ -56,6 +56,12 @@ export const getEmailComponent = async (
|
|
|
56
56
|
...global,
|
|
57
57
|
console,
|
|
58
58
|
Buffer,
|
|
59
|
+
TextDecoder,
|
|
60
|
+
TextDecoderStream,
|
|
61
|
+
TextEncoder,
|
|
62
|
+
TextEncoderStream,
|
|
63
|
+
ReadableStream,
|
|
64
|
+
URL,
|
|
59
65
|
module: { exports: { default: undefined as unknown } },
|
|
60
66
|
__filanem: emailPath,
|
|
61
67
|
__dirname: path.dirname(emailPath),
|