react-email 3.0.6 → 3.0.7-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.
Files changed (67) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cli/index.js +761 -765
  3. package/dist/cli/index.mjs +473 -481
  4. package/dist/preview/.next/BUILD_ID +1 -1
  5. package/dist/preview/.next/app-build-manifest.json +6 -6
  6. package/dist/preview/.next/build-manifest.json +2 -2
  7. package/dist/preview/.next/cache/.rscinfo +1 -1
  8. package/dist/preview/.next/cache/webpack/client-production/0.pack +0 -0
  9. package/dist/preview/.next/cache/webpack/client-production/index.pack +0 -0
  10. package/dist/preview/.next/cache/webpack/edge-server-production/index.pack +0 -0
  11. package/dist/preview/.next/cache/webpack/server-production/0.pack +0 -0
  12. package/dist/preview/.next/cache/webpack/server-production/index.pack +0 -0
  13. package/dist/preview/.next/next-minimal-server.js.nft.json +1 -1
  14. package/dist/preview/.next/next-server.js.nft.json +1 -1
  15. package/dist/preview/.next/prerender-manifest.json +1 -1
  16. package/dist/preview/.next/server/app/_not-found/page.js +1 -1
  17. package/dist/preview/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/dist/preview/.next/server/app/page.js +1 -1
  19. package/dist/preview/.next/server/app/page.js.nft.json +1 -1
  20. package/dist/preview/.next/server/app/page_client-reference-manifest.js +1 -1
  21. package/dist/preview/.next/server/app/preview/[...slug]/page.js +6 -6
  22. package/dist/preview/.next/server/app/preview/[...slug]/page.js.nft.json +1 -1
  23. package/dist/preview/.next/server/app/preview/[...slug]/page_client-reference-manifest.js +1 -1
  24. package/dist/preview/.next/server/chunks/{391.js → 650.js} +1 -1
  25. package/dist/preview/.next/server/pages/500.html +1 -1
  26. package/dist/preview/.next/server/server-reference-manifest.js +1 -1
  27. package/dist/preview/.next/server/server-reference-manifest.json +1 -1
  28. package/dist/preview/.next/static/chunks/154-ca55c1fde27d0922.js +1 -0
  29. package/dist/preview/.next/static/chunks/app/{layout-a2901ed1c2c53661.js → layout-7b9224888c7ffd05.js} +1 -1
  30. package/dist/preview/.next/static/chunks/app/{page-54a86772095e22e0.js → page-36853df2e13e583f.js} +1 -1
  31. package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-48ce00470ce06446.js +1 -0
  32. package/dist/preview/.next/static/css/{eb0a93282704d7ab.css → a34876a6c565fff8.css} +1 -1
  33. package/dist/preview/.next/trace +21 -21
  34. package/package.json +4 -8
  35. package/postcss.config.js +1 -1
  36. package/src/actions/get-email-path-from-slug.ts +7 -4
  37. package/src/actions/render-email-by-path.tsx +3 -3
  38. package/src/app/layout.tsx +1 -1
  39. package/src/app/page.tsx +1 -1
  40. package/src/app/preview/[...slug]/page.tsx +2 -2
  41. package/src/app/preview/[...slug]/preview.tsx +2 -2
  42. package/src/components/button.tsx +1 -1
  43. package/src/components/code-container.tsx +1 -1
  44. package/src/components/heading.tsx +1 -1
  45. package/src/components/sidebar/sidebar-directory-children.tsx +5 -8
  46. package/src/components/sidebar/sidebar-directory.tsx +2 -2
  47. package/src/components/sidebar/sidebar.tsx +2 -2
  48. package/src/components/text.tsx +1 -1
  49. package/src/components/tooltip-content.tsx +1 -1
  50. package/src/components/tooltip.tsx +1 -1
  51. package/src/components/topbar.tsx +1 -1
  52. package/src/hooks/use-email-rendering-result.ts +2 -2
  53. package/src/utils/cn.ts +1 -1
  54. package/src/utils/esbuild/renderring-utilities-exporter.ts +1 -1
  55. package/src/utils/get-email-component.ts +6 -6
  56. package/src/utils/get-emails-directory-metadata.spec.ts +0 -1
  57. package/src/utils/improve-error-with-sourcemap.ts +1 -1
  58. package/src/utils/static-node-modules-for-vm.ts +6 -6
  59. package/tsconfig.json +1 -6
  60. package/.eslintrc.js +0 -52
  61. package/.prettierignore +0 -3
  62. package/.prettierrc.js +0 -8
  63. package/dist/preview/.next/cache/eslint/.cache_1c3sgg +0 -1
  64. package/dist/preview/.next/static/chunks/154-4202f86af36ccff4.js +0 -1
  65. package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-2bfad134b65ddd79.js +0 -1
  66. /package/dist/preview/.next/static/{Trk1e7GzgKOLunAXBDCy- → 3Ni4t_kYMdpL72HxSPHgK}/_buildManifest.js +0 -0
  67. /package/dist/preview/.next/static/{Trk1e7GzgKOLunAXBDCy- → 3Ni4t_kYMdpL72HxSPHgK}/_ssgManifest.js +0 -0
package/dist/cli/index.js CHANGED
@@ -340,7 +340,7 @@ var import_commander = require("commander");
340
340
  // package.json
341
341
  var package_default = {
342
342
  name: "react-email",
343
- version: "3.0.6",
343
+ version: "3.0.7-canary.0",
344
344
  description: "A live preview of your emails right in your browser.",
345
345
  bin: {
346
346
  email: "./dist/cli/index.js"
@@ -350,8 +350,7 @@ var package_default = {
350
350
  dev: "tsup-node --watch",
351
351
  test: "vitest run",
352
352
  "test:watch": "vitest",
353
- clean: "rm -rf dist",
354
- lint: "eslint . && tsc"
353
+ clean: "rm -rf dist"
355
354
  },
356
355
  license: "MIT",
357
356
  repository: {
@@ -373,7 +372,7 @@ var package_default = {
373
372
  chokidar: "4.0.3",
374
373
  commander: "11.1.0",
375
374
  debounce: "2.0.0",
376
- esbuild: "0.19.11",
375
+ esbuild: "0.23.0",
377
376
  glob: "10.3.4",
378
377
  "log-symbols": "4.1.0",
379
378
  "mime-types": "2.1.35",
@@ -402,9 +401,6 @@ var package_default = {
402
401
  "@vercel/style-guide": "5.1.0",
403
402
  autoprefixer: "10.4.20",
404
403
  clsx: "2.1.0",
405
- eslint: "8.50.0",
406
- "eslint-config-prettier": "9.0.0",
407
- "eslint-config-turbo": "2.1.0",
408
404
  "framer-motion": "12.0.0-alpha.2",
409
405
  postcss: "8.4.40",
410
406
  "prism-react-renderer": "2.1.0",
@@ -423,12 +419,121 @@ var package_default = {
423
419
  vitest: "1.1.3"
424
420
  }
425
421
  };
426
- // src/cli/commands/dev.ts
427
- var import_node_fs4 = __toESM(require("fs"));
422
+ // src/cli/commands/build.ts
423
+ var import_node_child_process = require("child_process");
424
+ var import_node_fs5 = __toESM(require("fs"));
425
+ var import_node_path8 = __toESM(require("path"));
426
+ var import_log_symbols3 = __toESM(require("log-symbols"));
427
+ var import_ora2 = __toESM(require("ora"));
428
+ // src/utils/get-emails-directory-metadata.ts
429
+ var import_node_fs = __toESM(require("fs"));
430
+ var import_node_path = __toESM(require("path"));
431
+ var isFileAnEmail = function(fullPath) {
432
+ var stat = import_node_fs.default.statSync(fullPath);
433
+ if (stat.isDirectory()) return false;
434
+ var ext = import_node_path.default.parse(fullPath).ext;
435
+ if (![
436
+ ".js",
437
+ ".tsx",
438
+ ".jsx"
439
+ ].includes(ext)) return false;
440
+ if (!import_node_fs.default.existsSync(fullPath)) {
441
+ return false;
442
+ }
443
+ var fileContents = import_node_fs.default.readFileSync(fullPath, "utf8");
444
+ return /\bexport\s+default\b/gm.test(fileContents);
445
+ };
446
+ var mergeDirectoriesWithSubDirectories = function(emailsDirectoryMetadata) {
447
+ var currentResultingMergedDirectory = emailsDirectoryMetadata;
448
+ while(currentResultingMergedDirectory.emailFilenames.length === 0 && currentResultingMergedDirectory.subDirectories.length === 1){
449
+ var onlySubDirectory = currentResultingMergedDirectory.subDirectories[0];
450
+ currentResultingMergedDirectory = _object_spread_props(_object_spread({}, onlySubDirectory), {
451
+ directoryName: import_node_path.default.join(currentResultingMergedDirectory.directoryName, onlySubDirectory.directoryName)
452
+ });
453
+ }
454
+ return currentResultingMergedDirectory;
455
+ };
456
+ var getEmailsDirectoryMetadata = function() {
457
+ var _ref = _async_to_generator(function(absolutePathToEmailsDirectory) {
458
+ var keepFileExtensions, isSubDirectory, baseDirectoryPath, dirents, emailFilenames, subDirectories, emailsMetadata;
459
+ var _arguments = arguments;
460
+ return _ts_generator(this, function(_state) {
461
+ switch(_state.label){
462
+ case 0:
463
+ keepFileExtensions = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : false, isSubDirectory = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : false, baseDirectoryPath = _arguments.length > 3 && _arguments[3] !== void 0 ? _arguments[3] : absolutePathToEmailsDirectory;
464
+ if (!import_node_fs.default.existsSync(absolutePathToEmailsDirectory)) return [
465
+ 2
466
+ ];
467
+ return [
468
+ 4,
469
+ import_node_fs.default.promises.readdir(absolutePathToEmailsDirectory, {
470
+ withFileTypes: true
471
+ })
472
+ ];
473
+ case 1:
474
+ dirents = _state.sent();
475
+ emailFilenames = dirents.filter(function(dirent) {
476
+ return isFileAnEmail(import_node_path.default.join(absolutePathToEmailsDirectory, dirent.name));
477
+ }).map(function(dirent) {
478
+ return keepFileExtensions ? dirent.name : dirent.name.replace(import_node_path.default.extname(dirent.name), "");
479
+ });
480
+ return [
481
+ 4,
482
+ Promise.all(dirents.filter(function(dirent) {
483
+ return dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static";
484
+ }).map(function(dirent) {
485
+ var direntAbsolutePath = import_node_path.default.join(absolutePathToEmailsDirectory, dirent.name);
486
+ return getEmailsDirectoryMetadata(direntAbsolutePath, keepFileExtensions, true, baseDirectoryPath);
487
+ }))
488
+ ];
489
+ case 2:
490
+ subDirectories = _state.sent();
491
+ emailsMetadata = {
492
+ absolutePath: absolutePathToEmailsDirectory,
493
+ relativePath: import_node_path.default.relative(baseDirectoryPath, absolutePathToEmailsDirectory),
494
+ directoryName: absolutePathToEmailsDirectory.split(import_node_path.default.sep).pop(),
495
+ emailFilenames: emailFilenames,
496
+ subDirectories: subDirectories
497
+ };
498
+ return [
499
+ 2,
500
+ isSubDirectory ? mergeDirectoriesWithSubDirectories(emailsMetadata) : emailsMetadata
501
+ ];
502
+ }
503
+ });
504
+ });
505
+ return function getEmailsDirectoryMetadata(absolutePathToEmailsDirectory) {
506
+ return _ref.apply(this, arguments);
507
+ };
508
+ }();
509
+ // src/utils/register-spinner-autostopping.ts
510
+ var import_log_symbols = __toESM(require("log-symbols"));
511
+ var spinners = /* @__PURE__ */ new Set();
512
+ process.on("SIGINT", function() {
513
+ spinners.forEach(function(spinner) {
514
+ if (spinner.isSpinning) {
515
+ spinner.stop();
516
+ }
517
+ });
518
+ });
519
+ process.on("exit", function(code) {
520
+ if (code !== 0) {
521
+ spinners.forEach(function(spinner) {
522
+ if (spinner.isSpinning) {
523
+ spinner.stopAndPersist({
524
+ symbol: import_log_symbols.default.error
525
+ });
526
+ }
527
+ });
528
+ }
529
+ });
530
+ var registerSpinnerAutostopping = function(spinner) {
531
+ spinners.add(spinner);
532
+ };
428
533
  // src/cli/utils/tree.ts
429
- var import_node_fs = require("fs");
534
+ var import_node_fs2 = require("fs");
430
535
  var import_node_os = __toESM(require("os"));
431
- var import_node_path = __toESM(require("path"));
536
+ var import_node_path2 = __toESM(require("path"));
432
537
  var SYMBOLS = {
433
538
  BRANCH: "├── ",
434
539
  EMPTY: "",
@@ -445,14 +550,14 @@ var getTreeLines = function() {
445
550
  case 0:
446
551
  currentDepth = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : 0;
447
552
  base = process.cwd();
448
- dirFullpath = import_node_path.default.resolve(base, dirPath);
449
- dirname = import_node_path.default.basename(dirFullpath);
553
+ dirFullpath = import_node_path2.default.resolve(base, dirPath);
554
+ dirname = import_node_path2.default.basename(dirFullpath);
450
555
  lines = [
451
556
  dirname
452
557
  ];
453
558
  return [
454
559
  4,
455
- import_node_fs.promises.stat(dirFullpath)
560
+ import_node_fs2.promises.stat(dirFullpath)
456
561
  ];
457
562
  case 1:
458
563
  dirStat = _state.sent();
@@ -479,7 +584,7 @@ var getTreeLines = function() {
479
584
  3
480
585
  ];
481
586
  case 1:
482
- pathToDirectory = import_node_path.default.join(dirFullpath, dirent.name);
587
+ pathToDirectory = import_node_path2.default.join(dirFullpath, dirent.name);
483
588
  return [
484
589
  4,
485
590
  getTreeLines(pathToDirectory, depth, currentDepth + 1)
@@ -499,7 +604,7 @@ var getTreeLines = function() {
499
604
  };
500
605
  return [
501
606
  4,
502
- import_node_fs.promises.readdir(dirFullpath, {
607
+ import_node_fs2.promises.readdir(dirFullpath, {
503
608
  withFileTypes: true
504
609
  })
505
610
  ];
@@ -570,92 +675,33 @@ var tree = function() {
570
675
  };
571
676
  }();
572
677
  // src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
573
- var import_node_path6 = __toESM(require("path"));
574
- var import_socket = require("socket.io");
678
+ var import_node_path7 = __toESM(require("path"));
575
679
  var import_chokidar = require("chokidar");
576
680
  var import_debounce = __toESM(require("debounce"));
681
+ var import_socket = require("socket.io");
577
682
  // src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
578
- var import_node_path5 = __toESM(require("path"));
579
- var import_node_fs3 = require("fs");
580
- // src/cli/utils/preview/hot-reloading/get-imported-modules.ts
581
- var import_core = require("@babel/core");
582
- var import_parser = require("@babel/parser");
583
- var getImportedModules = function(contents) {
584
- var importedPaths = [];
585
- var parsedContents = (0, import_parser.parse)(contents, {
586
- sourceType: "unambiguous",
587
- strictMode: false,
588
- errorRecovery: true,
589
- plugins: [
590
- "jsx",
591
- "typescript",
592
- "decorators"
593
- ]
594
- });
595
- (0, import_core.traverse)(parsedContents, {
596
- ImportDeclaration: function ImportDeclaration(param) {
597
- var node = param.node;
598
- importedPaths.push(node.source.value);
599
- },
600
- ExportAllDeclaration: function ExportAllDeclaration(param) {
601
- var node = param.node;
602
- importedPaths.push(node.source.value);
603
- },
604
- ExportNamedDeclaration: function ExportNamedDeclaration(param) {
605
- var node = param.node;
606
- if (node.source) {
607
- importedPaths.push(node.source.value);
608
- }
609
- },
610
- CallExpression: function CallExpression(param) {
611
- var node = param.node;
612
- if ("name" in node.callee && node.callee.name === "require") {
613
- if (node.arguments.length === 1) {
614
- var importPathNode = node.arguments[0];
615
- if (importPathNode.type === "StringLiteral") {
616
- importedPaths.push(importPathNode.value);
617
- }
618
- }
619
- }
620
- }
621
- });
622
- return importedPaths;
623
- };
683
+ var import_node_fs4 = require("fs");
684
+ var import_node_path6 = __toESM(require("path"));
624
685
  // src/cli/utils/preview/start-dev-server.ts
625
- var import_node_path4 = __toESM(require("path"));
626
686
  var import_node_http = __toESM(require("http"));
687
+ var import_node_path5 = __toESM(require("path"));
627
688
  var import_node_url = __toESM(require("url"));
689
+ var import_chalk = __toESM(require("chalk"));
690
+ var import_log_symbols2 = __toESM(require("log-symbols"));
628
691
  var import_next = __toESM(require("next"));
629
692
  var import_ora = __toESM(require("ora"));
630
- var import_log_symbols2 = __toESM(require("log-symbols"));
631
- var import_chalk = __toESM(require("chalk"));
632
- // src/utils/register-spinner-autostopping.ts
633
- var import_log_symbols = __toESM(require("log-symbols"));
634
- var spinners = /* @__PURE__ */ new Set();
635
- process.on("SIGINT", function() {
636
- spinners.forEach(function(spinner) {
637
- if (spinner.isSpinning) {
638
- spinner.stop();
639
- }
640
- });
641
- });
642
- process.on("exit", function(code) {
643
- if (code !== 0) {
644
- spinners.forEach(function(spinner) {
645
- if (spinner.isSpinning) {
646
- spinner.stopAndPersist({
647
- symbol: import_log_symbols.default.error
648
- });
649
- }
650
- });
651
- }
652
- });
653
- var registerSpinnerAutostopping = function(spinner) {
654
- spinners.add(spinner);
693
+ // src/cli/utils/preview/get-env-variables-for-preview-app.ts
694
+ var import_node_path3 = __toESM(require("path"));
695
+ var getEnvVariablesForPreviewApp = function(relativePathToEmailsDirectory, cwd) {
696
+ return {
697
+ EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
698
+ EMAILS_DIR_ABSOLUTE_PATH: import_node_path3.default.resolve(cwd, relativePathToEmailsDirectory),
699
+ USER_PROJECT_LOCATION: cwd
700
+ };
655
701
  };
656
702
  // src/cli/utils/preview/serve-static-file.ts
657
- var import_node_path2 = __toESM(require("path"));
658
- var import_node_fs2 = require("fs");
703
+ var import_node_fs3 = require("fs");
704
+ var import_node_path4 = __toESM(require("path"));
659
705
  var import_mime_types = require("mime-types");
660
706
  var serveStaticFile = function() {
661
707
  var _ref = _async_to_generator(function(res, parsedUrl, staticDirRelativePath) {
@@ -663,13 +709,13 @@ var serveStaticFile = function() {
663
709
  return _ts_generator(this, function(_state) {
664
710
  switch(_state.label){
665
711
  case 0:
666
- staticBaseDir = import_node_path2.default.join(process.cwd(), staticDirRelativePath);
712
+ staticBaseDir = import_node_path4.default.join(process.cwd(), staticDirRelativePath);
667
713
  pathname = parsedUrl.pathname;
668
- ext = import_node_path2.default.parse(pathname).ext;
669
- fileAbsolutePath = import_node_path2.default.join(staticBaseDir, pathname);
714
+ ext = import_node_path4.default.parse(pathname).ext;
715
+ fileAbsolutePath = import_node_path4.default.join(staticBaseDir, pathname);
670
716
  return [
671
717
  4,
672
- import_node_fs2.promises.open(fileAbsolutePath, "r")
718
+ import_node_fs3.promises.open(fileAbsolutePath, "r")
673
719
  ];
674
720
  case 1:
675
721
  fileHandle = _state.sent();
@@ -683,7 +729,7 @@ var serveStaticFile = function() {
683
729
  ]);
684
730
  return [
685
731
  4,
686
- import_node_fs2.promises.readFile(fileHandle)
732
+ import_node_fs3.promises.readFile(fileHandle)
687
733
  ];
688
734
  case 3:
689
735
  fileData = _state.sent();
@@ -718,15 +764,6 @@ var serveStaticFile = function() {
718
764
  return _ref.apply(this, arguments);
719
765
  };
720
766
  }();
721
- // src/cli/utils/preview/get-env-variables-for-preview-app.ts
722
- var import_node_path3 = __toESM(require("path"));
723
- var getEnvVariablesForPreviewApp = function(relativePathToEmailsDirectory, cwd) {
724
- return {
725
- EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
726
- EMAILS_DIR_ABSOLUTE_PATH: import_node_path3.default.resolve(cwd, relativePathToEmailsDirectory),
727
- USER_PROJECT_LOCATION: cwd
728
- };
729
- };
730
767
  // src/cli/utils/preview/start-dev-server.ts
731
768
  var devServer;
732
769
  var safeAsyncServerListen = function(server, port) {
@@ -745,9 +782,9 @@ var safeAsyncServerListen = function(server, port) {
745
782
  });
746
783
  });
747
784
  };
748
- var isDev = !__filename.endsWith(import_node_path4.default.join("cli", "index.js"));
749
- var cliPacakgeLocation = isDev ? import_node_path4.default.resolve(__dirname, "../../../..") : import_node_path4.default.resolve(__dirname, "../..");
750
- var previewServerLocation = isDev ? import_node_path4.default.resolve(__dirname, "../../../..") : import_node_path4.default.resolve(__dirname, "../preview");
785
+ var isDev = !__filename.endsWith(import_node_path5.default.join("cli", "index.js"));
786
+ var cliPacakgeLocation = isDev ? import_node_path5.default.resolve(__dirname, "../../../..") : import_node_path5.default.resolve(__dirname, "../..");
787
+ var previewServerLocation = isDev ? import_node_path5.default.resolve(__dirname, "../../../..") : import_node_path5.default.resolve(__dirname, "../preview");
751
788
  var startDevServer = function() {
752
789
  var _ref = _async_to_generator(function(emailsDirRelativePath, staticBaseDirRelativePath, port) {
753
790
  var portAlreadyInUse, nextPortToTry, spinner, timeBeforeNextReady, app, isNextReady, nextReadyPromise, nextHandleRequest, secondsToNextReady;
@@ -764,7 +801,8 @@ var startDevServer = function() {
764
801
  res.setHeader("Pragma", "no-cache");
765
802
  res.setHeader("Expires", "-1");
766
803
  try {
767
- if (parsedUrl.path && parsedUrl.path.includes("static/") && !parsedUrl.path.includes("_next/static/")) {
804
+ var _parsedUrl_path;
805
+ if (((_parsedUrl_path = parsedUrl.path) === null || _parsedUrl_path === void 0 ? void 0 : _parsedUrl_path.includes("static/")) && !parsedUrl.path.includes("_next/static/")) {
768
806
  void serveStaticFile(res, parsedUrl, staticBaseDirRelativePath);
769
807
  } else if (!isNextReady) {
770
808
  void nextReadyPromise.then(function() {
@@ -822,10 +860,10 @@ var startDevServer = function() {
822
860
  }).start();
823
861
  registerSpinnerAutostopping(spinner);
824
862
  timeBeforeNextReady = performance.now();
825
- process.env = _object_spread(_object_spread_props(_object_spread({}, process.env), {
863
+ process.env = _object_spread({
826
864
  NODE_ENV: "development"
827
- }), getEnvVariablesForPreviewApp(// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
828
- import_node_path4.default.normalize(emailsDirRelativePath), process.cwd()));
865
+ }, process.env, getEnvVariablesForPreviewApp(// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
866
+ import_node_path5.default.normalize(emailsDirRelativePath), process.cwd()));
829
867
  app = (0, import_next.default)({
830
868
  // passing in env here does not get the environment variables there
831
869
  dev: isDev,
@@ -894,6 +932,50 @@ process.on("uncaughtException", makeExitHandler({
894
932
  shouldKillProcess: true,
895
933
  killWithErrorCode: true
896
934
  }));
935
+ // src/cli/utils/preview/hot-reloading/get-imported-modules.ts
936
+ var import_core = require("@babel/core");
937
+ var import_parser = require("@babel/parser");
938
+ var getImportedModules = function(contents) {
939
+ var importedPaths = [];
940
+ var parsedContents = (0, import_parser.parse)(contents, {
941
+ sourceType: "unambiguous",
942
+ strictMode: false,
943
+ errorRecovery: true,
944
+ plugins: [
945
+ "jsx",
946
+ "typescript",
947
+ "decorators"
948
+ ]
949
+ });
950
+ (0, import_core.traverse)(parsedContents, {
951
+ ImportDeclaration: function ImportDeclaration(param) {
952
+ var node = param.node;
953
+ importedPaths.push(node.source.value);
954
+ },
955
+ ExportAllDeclaration: function ExportAllDeclaration(param) {
956
+ var node = param.node;
957
+ importedPaths.push(node.source.value);
958
+ },
959
+ ExportNamedDeclaration: function ExportNamedDeclaration(param) {
960
+ var node = param.node;
961
+ if (node.source) {
962
+ importedPaths.push(node.source.value);
963
+ }
964
+ },
965
+ CallExpression: function CallExpression(param) {
966
+ var node = param.node;
967
+ if ("name" in node.callee && node.callee.name === "require") {
968
+ if (node.arguments.length === 1) {
969
+ var importPathNode = node.arguments[0];
970
+ if (importPathNode.type === "StringLiteral") {
971
+ importedPaths.push(importPathNode.value);
972
+ }
973
+ }
974
+ }
975
+ }
976
+ });
977
+ return importedPaths;
978
+ };
897
979
  // src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
898
980
  var readAllFilesInsideDirectory = function() {
899
981
  var _ref = _async_to_generator(function(directory) {
@@ -904,7 +986,7 @@ var readAllFilesInsideDirectory = function() {
904
986
  allFilePaths = [];
905
987
  return [
906
988
  4,
907
- import_node_fs3.promises.readdir(directory, {
989
+ import_node_fs4.promises.readdir(directory, {
908
990
  withFileTypes: true
909
991
  })
910
992
  ];
@@ -933,7 +1015,7 @@ var readAllFilesInsideDirectory = function() {
933
1015
  ];
934
1016
  _value = _step.value;
935
1017
  dirent = _value;
936
- pathToDirent = import_node_path5.default.join(directory, dirent.name);
1018
+ pathToDirent = import_node_path6.default.join(directory, dirent.name);
937
1019
  if (!dirent.isDirectory()) return [
938
1020
  3,
939
1021
  6
@@ -1020,7 +1102,7 @@ var readAllFilesInsideDirectory = function() {
1020
1102
  };
1021
1103
  }();
1022
1104
  var isJavascriptModule = function(filePath) {
1023
- var extensionName = import_node_path5.default.extname(filePath);
1105
+ var extensionName = import_node_path6.default.extname(filePath);
1024
1106
  return [
1025
1107
  ".js",
1026
1108
  ".ts",
@@ -1031,22 +1113,22 @@ var isJavascriptModule = function(filePath) {
1031
1113
  ].includes(extensionName);
1032
1114
  };
1033
1115
  var checkFileExtensionsUntilItExists = function(pathWithoutExtension) {
1034
- if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".ts"))) {
1116
+ if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".ts"))) {
1035
1117
  return "".concat(pathWithoutExtension, ".ts");
1036
1118
  }
1037
- if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".tsx"))) {
1119
+ if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".tsx"))) {
1038
1120
  return "".concat(pathWithoutExtension, ".tsx");
1039
1121
  }
1040
- if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".js"))) {
1122
+ if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".js"))) {
1041
1123
  return "".concat(pathWithoutExtension, ".js");
1042
1124
  }
1043
- if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".jsx"))) {
1125
+ if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".jsx"))) {
1044
1126
  return "".concat(pathWithoutExtension, ".jsx");
1045
1127
  }
1046
- if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".mjs"))) {
1128
+ if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".mjs"))) {
1047
1129
  return "".concat(pathWithoutExtension, ".mjs");
1048
1130
  }
1049
- if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".cjs"))) {
1131
+ if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".cjs"))) {
1050
1132
  return "".concat(pathWithoutExtension, ".cjs");
1051
1133
  }
1052
1134
  };
@@ -1082,52 +1164,51 @@ var createDependencyGraph = function() {
1082
1164
  case 0:
1083
1165
  return [
1084
1166
  4,
1085
- import_node_fs3.promises.readFile(filePath, "utf8")
1167
+ import_node_fs4.promises.readFile(filePath, "utf8")
1086
1168
  ];
1087
1169
  case 1:
1088
1170
  contents = _state.sent();
1089
1171
  importedPaths = getImportedModules(contents);
1090
1172
  importedPathsRelativeToDirectory = importedPaths.map(function(dependencyPath) {
1091
1173
  var isModulePath = !dependencyPath.startsWith(".");
1092
- if (!isModulePath && !import_node_path5.default.isAbsolute(dependencyPath)) {
1093
- var pathToDependencyFromDirectory = import_node_path5.default.resolve(/*
1094
- path.resolve resolves paths differently from what imports on javascript do.
1095
-
1096
- So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependecy path of "./other-email"
1097
- would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
1098
- one the import is meant to go to
1099
- */ import_node_path5.default.dirname(filePath), dependencyPath);
1100
- var isDirectory = false;
1101
- try {
1102
- isDirectory = (0, import_node_fs3.statSync)(pathToDependencyFromDirectory).isDirectory();
1103
- } catch (_) {}
1104
- if (isDirectory) {
1105
- var pathToSubDirectory = pathToDependencyFromDirectory;
1106
- var pathWithExtension = checkFileExtensionsUntilItExists("".concat(pathToSubDirectory, "/index"));
1107
- if (pathWithExtension) {
1108
- pathToDependencyFromDirectory = pathWithExtension;
1109
- } else if (isDev) {
1110
- console.warn("Could not find index file for directory at ".concat(pathToDependencyFromDirectory, ". This is probably going to cause issues with both hot reloading and your code."));
1111
- }
1174
+ if (isModulePath || import_node_path6.default.isAbsolute(dependencyPath)) {
1175
+ return dependencyPath;
1176
+ }
1177
+ var pathToDependencyFromDirectory = import_node_path6.default.resolve(/*
1178
+ path.resolve resolves paths differently from what imports on javascript do.
1179
+
1180
+ So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependecy path of "./other-email"
1181
+ would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
1182
+ one the import is meant to go to
1183
+ */ import_node_path6.default.dirname(filePath), dependencyPath);
1184
+ var isDirectory = false;
1185
+ try {
1186
+ isDirectory = (0, import_node_fs4.statSync)(pathToDependencyFromDirectory).isDirectory();
1187
+ } catch (_) {}
1188
+ if (isDirectory) {
1189
+ var pathToSubDirectory = pathToDependencyFromDirectory;
1190
+ var pathWithExtension = checkFileExtensionsUntilItExists("".concat(pathToSubDirectory, "/index"));
1191
+ if (pathWithExtension) {
1192
+ pathToDependencyFromDirectory = pathWithExtension;
1193
+ } else if (isDev) {
1194
+ console.warn("Could not find index file for directory at ".concat(pathToDependencyFromDirectory, ". This is probably going to cause issues with both hot reloading and your code."));
1112
1195
  }
1113
- if (!isJavascriptModule(pathToDependencyFromDirectory)) {
1114
- var pathWithExtension1 = checkFileExtensionsUntilItExists(pathToDependencyFromDirectory);
1115
- if (pathWithExtension1) {
1116
- pathToDependencyFromDirectory = pathWithExtension1;
1117
- } else if (isDev) {
1118
- console.warn("Could not determine the file extension for the file at ".concat(pathToDependencyFromDirectory));
1119
- }
1196
+ }
1197
+ if (!isJavascriptModule(pathToDependencyFromDirectory)) {
1198
+ var pathWithExtension1 = checkFileExtensionsUntilItExists(pathToDependencyFromDirectory);
1199
+ if (pathWithExtension1) {
1200
+ pathToDependencyFromDirectory = pathWithExtension1;
1201
+ } else if (isDev) {
1202
+ console.warn("Could not determine the file extension for the file at ".concat(pathToDependencyFromDirectory));
1120
1203
  }
1121
- return pathToDependencyFromDirectory;
1122
- } else {
1123
- return dependencyPath;
1124
1204
  }
1205
+ return pathToDependencyFromDirectory;
1125
1206
  });
1126
1207
  moduleDependencies = importedPathsRelativeToDirectory.filter(function(dependencyPath) {
1127
- return !dependencyPath.startsWith(".") && !import_node_path5.default.isAbsolute(dependencyPath);
1208
+ return !dependencyPath.startsWith(".") && !import_node_path6.default.isAbsolute(dependencyPath);
1128
1209
  });
1129
1210
  nonNodeModuleImportPathsRelativeToDirectory = importedPathsRelativeToDirectory.filter(function(dependencyPath) {
1130
- return dependencyPath.startsWith(".") || import_node_path5.default.isAbsolute(dependencyPath);
1211
+ return dependencyPath.startsWith(".") || import_node_path6.default.isAbsolute(dependencyPath);
1131
1212
  });
1132
1213
  return [
1133
1214
  2,
@@ -1665,7 +1746,7 @@ var setupHotreloading = function() {
1665
1746
  });
1666
1747
  changes = [];
1667
1748
  }, 150);
1668
- absolutePathToEmailsDirectory = import_node_path6.default.resolve(process.cwd(), emailDirRelativePath);
1749
+ absolutePathToEmailsDirectory = import_node_path7.default.resolve(process.cwd(), emailDirRelativePath);
1669
1750
  return [
1670
1751
  4,
1671
1752
  createDependencyGraph(absolutePathToEmailsDirectory)
@@ -1681,7 +1762,7 @@ var setupHotreloading = function() {
1681
1762
  });
1682
1763
  getFilesOutsideEmailsDirectory = function() {
1683
1764
  return Object.keys(dependencyGraph).filter(function(p) {
1684
- return import_node_path6.default.relative(absolutePathToEmailsDirectory, p).startsWith("..");
1765
+ return import_node_path7.default.relative(absolutePathToEmailsDirectory, p).startsWith("..");
1685
1766
  });
1686
1767
  };
1687
1768
  filesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
@@ -1734,13 +1815,13 @@ var setupHotreloading = function() {
1734
1815
  return _ts_generator(this, function(_state) {
1735
1816
  switch(_state.label){
1736
1817
  case 0:
1737
- file = relativePathToChangeTarget.split(import_node_path6.default.sep);
1818
+ file = relativePathToChangeTarget.split(import_node_path7.default.sep);
1738
1819
  if (file.length === 0) {
1739
1820
  return [
1740
1821
  2
1741
1822
  ];
1742
1823
  }
1743
- pathToChangeTarget = import_node_path6.default.resolve(absolutePathToEmailsDirectory, relativePathToChangeTarget);
1824
+ pathToChangeTarget = import_node_path7.default.resolve(absolutePathToEmailsDirectory, relativePathToChangeTarget);
1744
1825
  return [
1745
1826
  4,
1746
1827
  updateDependencyGraph(event, pathToChangeTarget)
@@ -1803,7 +1884,7 @@ var setupHotreloading = function() {
1803
1884
  dependentPath = _step2.value;
1804
1885
  changes.push({
1805
1886
  event: "change",
1806
- filename: import_node_path6.default.relative(absolutePathToEmailsDirectory, dependentPath)
1887
+ filename: import_node_path7.default.relative(absolutePathToEmailsDirectory, dependentPath)
1807
1888
  });
1808
1889
  }
1809
1890
  } catch (err) {
@@ -1842,195 +1923,446 @@ var setupHotreloading = function() {
1842
1923
  return _ref.apply(this, arguments);
1843
1924
  };
1844
1925
  }();
1845
- // src/cli/commands/dev.ts
1846
- var dev = function() {
1847
- var _ref = _async_to_generator(function(param) {
1848
- var emailsDirRelativePath, port, devServer2, error;
1926
+ // src/cli/commands/build.ts
1927
+ var buildPreviewApp = function(absoluteDirectory) {
1928
+ return new Promise(function(resolve, reject) {
1929
+ var nextBuild = (0, import_node_child_process.spawn)("npm", [
1930
+ "run",
1931
+ "build"
1932
+ ], {
1933
+ cwd: absoluteDirectory,
1934
+ shell: true
1935
+ });
1936
+ nextBuild.stdout.pipe(process.stdout);
1937
+ nextBuild.stderr.pipe(process.stderr);
1938
+ nextBuild.on("close", function(code) {
1939
+ if (code === 0) {
1940
+ resolve();
1941
+ } else {
1942
+ reject(new Error("Unable to build the Next app and it exited with code: ".concat(code)));
1943
+ }
1944
+ });
1945
+ });
1946
+ };
1947
+ var setNextEnvironmentVariablesForBuild = function() {
1948
+ var _ref = _async_to_generator(function(emailsDirRelativePath, builtPreviewAppPath) {
1949
+ var nextConfigContents;
1849
1950
  return _ts_generator(this, function(_state) {
1850
1951
  switch(_state.label){
1851
1952
  case 0:
1852
- emailsDirRelativePath = param.dir, port = param.port;
1853
- _state.label = 1;
1953
+ nextConfigContents = "\nconst path = require('path');\nconst emailsDirRelativePath = path.normalize('".concat(emailsDirRelativePath, "');\nconst userProjectLocation = path.resolve(process.cwd(), '../');\n/** @type {import('next').NextConfig} */\nmodule.exports = {\n env: {\n NEXT_PUBLIC_IS_BUILDING: 'true',\n EMAILS_DIR_RELATIVE_PATH: emailsDirRelativePath,\n EMAILS_DIR_ABSOLUTE_PATH: path.resolve(userProjectLocation, emailsDirRelativePath),\n USER_PROJECT_LOCATION: userProjectLocation\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 },\n}");
1954
+ return [
1955
+ 4,
1956
+ import_node_fs5.default.promises.writeFile(import_node_path8.default.resolve(builtPreviewAppPath, "./next.config.js"), nextConfigContents, "utf8")
1957
+ ];
1854
1958
  case 1:
1855
- _state.trys.push([
1856
- 1,
1959
+ _state.sent();
1960
+ return [
1961
+ 2
1962
+ ];
1963
+ }
1964
+ });
1965
+ });
1966
+ return function setNextEnvironmentVariablesForBuild(emailsDirRelativePath, builtPreviewAppPath) {
1967
+ return _ref.apply(this, arguments);
1968
+ };
1969
+ }();
1970
+ var getEmailSlugsFromEmailDirectory = function(emailDirectory, emailsDirectoryAbsolutePath) {
1971
+ var directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
1972
+ var slugs = [];
1973
+ emailDirectory.emailFilenames.forEach(function(filename) {
1974
+ return slugs.push(import_node_path8.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path8.default.sep).filter(function(segment) {
1975
+ return segment.length > 0;
1976
+ }));
1977
+ });
1978
+ emailDirectory.subDirectories.forEach(function(directory) {
1979
+ var _slugs;
1980
+ (_slugs = slugs).push.apply(_slugs, _to_consumable_array(getEmailSlugsFromEmailDirectory(directory, emailsDirectoryAbsolutePath)));
1981
+ });
1982
+ return slugs;
1983
+ };
1984
+ var forceSSGForEmailPreviews = function() {
1985
+ var _ref = _async_to_generator(function(emailsDirPath, builtPreviewAppPath) {
1986
+ var emailDirectoryMetadata, parameters, removeForceDynamic;
1987
+ return _ts_generator(this, function(_state) {
1988
+ switch(_state.label){
1989
+ case 0:
1990
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1991
+ return [
1857
1992
  4,
1858
- ,
1859
- 5
1860
- ]);
1861
- if (!import_node_fs4.default.existsSync(emailsDirRelativePath)) {
1862
- console.error("Missing ".concat(emailsDirRelativePath, " folder"));
1863
- process.exit(1);
1864
- }
1993
+ getEmailsDirectoryMetadata(emailsDirPath)
1994
+ ];
1995
+ case 1:
1996
+ emailDirectoryMetadata = _state.sent();
1997
+ parameters = getEmailSlugsFromEmailDirectory(emailDirectoryMetadata, emailsDirPath).map(function(slug) {
1998
+ return {
1999
+ slug: slug
2000
+ };
2001
+ });
2002
+ removeForceDynamic = function() {
2003
+ var _ref = _async_to_generator(function(filePath) {
2004
+ var contents;
2005
+ return _ts_generator(this, function(_state) {
2006
+ switch(_state.label){
2007
+ case 0:
2008
+ return [
2009
+ 4,
2010
+ import_node_fs5.default.promises.readFile(filePath, "utf8")
2011
+ ];
2012
+ case 1:
2013
+ contents = _state.sent();
2014
+ return [
2015
+ 4,
2016
+ import_node_fs5.default.promises.writeFile(filePath, contents.replace("export const dynamic = 'force-dynamic';", ""), "utf8")
2017
+ ];
2018
+ case 2:
2019
+ _state.sent();
2020
+ return [
2021
+ 2
2022
+ ];
2023
+ }
2024
+ });
2025
+ });
2026
+ return function removeForceDynamic(filePath) {
2027
+ return _ref.apply(this, arguments);
2028
+ };
2029
+ }();
1865
2030
  return [
1866
2031
  4,
1867
- startDevServer(emailsDirRelativePath, emailsDirRelativePath, // defaults to ./emails/static for the static files that are served to the preview
1868
- Number.parseInt(port))
2032
+ removeForceDynamic(import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/layout.tsx"))
1869
2033
  ];
1870
2034
  case 2:
1871
- devServer2 = _state.sent();
2035
+ _state.sent();
1872
2036
  return [
1873
2037
  4,
1874
- setupHotreloading(devServer2, emailsDirRelativePath)
2038
+ removeForceDynamic(import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"))
1875
2039
  ];
1876
2040
  case 3:
1877
2041
  _state.sent();
1878
2042
  return [
1879
- 3,
1880
- 5
2043
+ 4,
2044
+ import_node_fs5.default.promises.appendFile(import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"), "\n\nexport function generateStaticParams() { \n return Promise.resolve(\n ".concat(JSON.stringify(parameters), "\n );\n}"), "utf8")
1881
2045
  ];
1882
2046
  case 4:
1883
- error = _state.sent();
1884
- console.log(error);
1885
- process.exit(1);
1886
- return [
1887
- 3,
1888
- 5
1889
- ];
1890
- case 5:
2047
+ _state.sent();
1891
2048
  return [
1892
2049
  2
1893
2050
  ];
1894
2051
  }
1895
2052
  });
1896
2053
  });
1897
- return function dev(_) {
2054
+ return function forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath) {
1898
2055
  return _ref.apply(this, arguments);
1899
2056
  };
1900
2057
  }();
1901
- // src/cli/commands/export.ts
1902
- var import_node_fs7 = __toESM(require("fs"));
1903
- var import_node_path9 = __toESM(require("path"));
1904
- var import_glob = require("glob");
1905
- var import_esbuild = require("esbuild");
1906
- var import_ora2 = __toESM(require("ora"));
1907
- var import_log_symbols3 = __toESM(require("log-symbols"));
1908
- var import_normalize_path = __toESM(require("normalize-path"));
1909
- // src/utils/get-emails-directory-metadata.ts
1910
- var import_node_fs5 = __toESM(require("fs"));
1911
- var import_node_path7 = __toESM(require("path"));
1912
- var isFileAnEmail = function(fullPath) {
1913
- var stat = import_node_fs5.default.statSync(fullPath);
1914
- if (stat.isDirectory()) return false;
1915
- var ext = import_node_path7.default.parse(fullPath).ext;
1916
- if (![
1917
- ".js",
1918
- ".tsx",
1919
- ".jsx"
1920
- ].includes(ext)) return false;
1921
- if (!import_node_fs5.default.existsSync(fullPath)) {
1922
- return false;
1923
- }
1924
- var fileContents = import_node_fs5.default.readFileSync(fullPath, "utf8");
1925
- return /\bexport\s+default\b/gm.test(fileContents);
1926
- };
1927
- var mergeDirectoriesWithSubDirectories = function(emailsDirectoryMetadata) {
1928
- var currentResultingMergedDirectory = emailsDirectoryMetadata;
1929
- while(currentResultingMergedDirectory.emailFilenames.length === 0 && currentResultingMergedDirectory.subDirectories.length === 1){
1930
- var onlySubDirectory = currentResultingMergedDirectory.subDirectories[0];
1931
- currentResultingMergedDirectory = _object_spread_props(_object_spread({}, onlySubDirectory), {
1932
- directoryName: import_node_path7.default.join(currentResultingMergedDirectory.directoryName, onlySubDirectory.directoryName)
1933
- });
1934
- }
1935
- return currentResultingMergedDirectory;
1936
- };
1937
- var getEmailsDirectoryMetadata = function() {
1938
- var _ref = _async_to_generator(function(absolutePathToEmailsDirectory) {
1939
- var keepFileExtensions, isSubDirectory, baseDirectoryPath, dirents, emailFilenames, subDirectories, emailsMetadata;
1940
- var _arguments = arguments;
2058
+ var updatePackageJson = function() {
2059
+ var _ref = _async_to_generator(function(builtPreviewAppPath) {
2060
+ var packageJsonPath, packageJson, _;
1941
2061
  return _ts_generator(this, function(_state) {
1942
2062
  switch(_state.label){
1943
2063
  case 0:
1944
- keepFileExtensions = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : false, isSubDirectory = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : false, baseDirectoryPath = _arguments.length > 3 && _arguments[3] !== void 0 ? _arguments[3] : absolutePathToEmailsDirectory;
1945
- if (!import_node_fs5.default.existsSync(absolutePathToEmailsDirectory)) return [
1946
- 2
1947
- ];
2064
+ packageJsonPath = import_node_path8.default.resolve(builtPreviewAppPath, "./package.json");
2065
+ _ = JSON.parse;
1948
2066
  return [
1949
2067
  4,
1950
- import_node_fs5.default.promises.readdir(absolutePathToEmailsDirectory, {
1951
- withFileTypes: true
1952
- })
2068
+ import_node_fs5.default.promises.readFile(packageJsonPath, "utf8")
1953
2069
  ];
1954
2070
  case 1:
1955
- dirents = _state.sent();
1956
- emailFilenames = dirents.filter(function(dirent) {
1957
- return isFileAnEmail(import_node_path7.default.join(absolutePathToEmailsDirectory, dirent.name));
1958
- }).map(function(dirent) {
1959
- return keepFileExtensions ? dirent.name : dirent.name.replace(import_node_path7.default.extname(dirent.name), "");
1960
- });
2071
+ packageJson = _.apply(JSON, [
2072
+ _state.sent()
2073
+ ]);
2074
+ packageJson.scripts.build = "next build";
2075
+ packageJson.scripts.start = "next start";
2076
+ packageJson.name = "preview-server";
2077
+ delete packageJson.devDependencies["@react-email/render"];
2078
+ delete packageJson.devDependencies["@react-email/components"];
1961
2079
  return [
1962
2080
  4,
1963
- Promise.all(dirents.filter(function(dirent) {
1964
- return dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static";
1965
- }).map(function(dirent) {
1966
- var direntAbsolutePath = import_node_path7.default.join(absolutePathToEmailsDirectory, dirent.name);
1967
- return getEmailsDirectoryMetadata(direntAbsolutePath, keepFileExtensions, true, baseDirectoryPath);
1968
- }))
2081
+ import_node_fs5.default.promises.writeFile(packageJsonPath, JSON.stringify(packageJson), "utf8")
1969
2082
  ];
1970
2083
  case 2:
1971
- subDirectories = _state.sent();
1972
- emailsMetadata = {
1973
- absolutePath: absolutePathToEmailsDirectory,
1974
- relativePath: import_node_path7.default.relative(baseDirectoryPath, absolutePathToEmailsDirectory),
1975
- directoryName: absolutePathToEmailsDirectory.split(import_node_path7.default.sep).pop(),
1976
- emailFilenames: emailFilenames,
1977
- subDirectories: subDirectories
1978
- };
2084
+ _state.sent();
1979
2085
  return [
1980
- 2,
1981
- isSubDirectory ? mergeDirectoriesWithSubDirectories(emailsMetadata) : emailsMetadata
2086
+ 2
1982
2087
  ];
1983
2088
  }
1984
2089
  });
1985
2090
  });
1986
- return function getEmailsDirectoryMetadata(absolutePathToEmailsDirectory) {
2091
+ return function updatePackageJson(builtPreviewAppPath) {
1987
2092
  return _ref.apply(this, arguments);
1988
2093
  };
1989
2094
  }();
1990
- // src/utils/esbuild/renderring-utilities-exporter.ts
1991
- var import_node_path8 = __toESM(require("path"));
1992
- var import_node_fs6 = require("fs");
1993
- // src/utils/esbuild/escape-string-for-regex.ts
1994
- function escapeStringForRegex(string) {
1995
- return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
1996
- }
1997
- // src/utils/esbuild/renderring-utilities-exporter.ts
1998
- var renderingUtilitiesExporter = function(emailTemplates) {
1999
- return {
2000
- name: "rendering-utilities-exporter",
2001
- setup: function(b) {
2002
- b.onLoad({
2003
- filter: new RegExp(emailTemplates.map(function(emailPath) {
2004
- return escapeStringForRegex(emailPath);
2005
- }).join("|"))
2006
- }, function() {
2007
- var _ref = _async_to_generator(function(param) {
2008
- var pathToFile, _tmp, _, _1;
2009
- return _ts_generator(this, function(_state) {
2010
- switch(_state.label){
2011
- case 0:
2012
- pathToFile = param.path;
2013
- _tmp = {};
2014
- _1 = (_ = "").concat;
2015
- return [
2016
- 4,
2017
- import_node_fs6.promises.readFile(pathToFile, "utf8")
2018
- ];
2019
- case 1:
2020
- return [
2021
- 2,
2022
- (_tmp.contents = _1.apply(_, [
2023
- _state.sent(),
2024
- ";\n export { render } from 'react-email-module-that-will-export-render'\n export { createElement as reactEmailCreateReactElement } from 'react';\n "
2025
- ]), _tmp.loader = import_node_path8.default.extname(pathToFile).slice(1), _tmp)
2026
- ];
2095
+ var npmInstall = function() {
2096
+ var _ref = _async_to_generator(function(builtPreviewAppPath, packageManager) {
2097
+ return _ts_generator(this, function(_state) {
2098
+ return [
2099
+ 2,
2100
+ new Promise(function(resolve, reject) {
2101
+ var childProc = (0, import_node_child_process.spawn)(packageManager, [
2102
+ "install",
2103
+ "--silent",
2104
+ "--include=dev"
2105
+ ], {
2106
+ cwd: builtPreviewAppPath,
2107
+ shell: true
2108
+ });
2109
+ childProc.stdout.pipe(process.stdout);
2110
+ childProc.stderr.pipe(process.stderr);
2111
+ childProc.on("close", function(code) {
2112
+ if (code === 0) {
2113
+ resolve();
2114
+ } else {
2115
+ reject(new Error("Unable to install the dependencies and it exited with code: ".concat(code)));
2027
2116
  }
2028
2117
  });
2029
- });
2030
- return function(_) {
2031
- return _ref.apply(this, arguments);
2032
- };
2033
- }());
2118
+ })
2119
+ ];
2120
+ });
2121
+ });
2122
+ return function npmInstall(builtPreviewAppPath, packageManager) {
2123
+ return _ref.apply(this, arguments);
2124
+ };
2125
+ }();
2126
+ var build = function() {
2127
+ var _ref = _async_to_generator(function(param) {
2128
+ var emailsDirRelativePath, packageManager, spinner, emailsDirPath, staticPath, builtPreviewAppPath, builtStaticDirectory, error;
2129
+ return _ts_generator(this, function(_state) {
2130
+ switch(_state.label){
2131
+ case 0:
2132
+ emailsDirRelativePath = param.dir, packageManager = param.packageManager;
2133
+ _state.label = 1;
2134
+ case 1:
2135
+ _state.trys.push([
2136
+ 1,
2137
+ 12,
2138
+ ,
2139
+ 13
2140
+ ]);
2141
+ spinner = (0, import_ora2.default)({
2142
+ text: "Starting build process...",
2143
+ prefixText: " "
2144
+ }).start();
2145
+ registerSpinnerAutostopping(spinner);
2146
+ spinner.text = "Checking if ".concat(emailsDirRelativePath, " folder exists");
2147
+ if (!import_node_fs5.default.existsSync(emailsDirRelativePath)) {
2148
+ process.exit(1);
2149
+ }
2150
+ emailsDirPath = import_node_path8.default.join(process.cwd(), emailsDirRelativePath);
2151
+ staticPath = import_node_path8.default.join(emailsDirPath, "static");
2152
+ builtPreviewAppPath = import_node_path8.default.join(process.cwd(), ".react-email");
2153
+ if (!import_node_fs5.default.existsSync(builtPreviewAppPath)) return [
2154
+ 3,
2155
+ 3
2156
+ ];
2157
+ spinner.text = "Deleting pre-existing `.react-email` folder";
2158
+ return [
2159
+ 4,
2160
+ import_node_fs5.default.promises.rm(builtPreviewAppPath, {
2161
+ recursive: true
2162
+ })
2163
+ ];
2164
+ case 2:
2165
+ _state.sent();
2166
+ _state.label = 3;
2167
+ case 3:
2168
+ spinner.text = "Copying preview app from CLI to `.react-email`";
2169
+ return [
2170
+ 4,
2171
+ import_node_fs5.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
2172
+ recursive: true,
2173
+ filter: function(source) {
2174
+ return !/(\/|\\)cli(\/|\\)?/.test(source) && !/(\/|\\)\.next(\/|\\)?/.test(source) && !/(\/|\\)\.turbo(\/|\\)?/.test(source) && !/(\/|\\)node_modules(\/|\\)?$/.test(source);
2175
+ }
2176
+ })
2177
+ ];
2178
+ case 4:
2179
+ _state.sent();
2180
+ if (!import_node_fs5.default.existsSync(staticPath)) return [
2181
+ 3,
2182
+ 6
2183
+ ];
2184
+ spinner.text = "Copying `static` folder into `.react-email/public/static`";
2185
+ builtStaticDirectory = import_node_path8.default.resolve(builtPreviewAppPath, "./public/static");
2186
+ return [
2187
+ 4,
2188
+ import_node_fs5.default.promises.cp(staticPath, builtStaticDirectory, {
2189
+ recursive: true
2190
+ })
2191
+ ];
2192
+ case 5:
2193
+ _state.sent();
2194
+ _state.label = 6;
2195
+ case 6:
2196
+ spinner.text = "Setting Next environment variables for preview app to work properly";
2197
+ return [
2198
+ 4,
2199
+ setNextEnvironmentVariablesForBuild(emailsDirRelativePath, builtPreviewAppPath)
2200
+ ];
2201
+ case 7:
2202
+ _state.sent();
2203
+ spinner.text = "Setting server side generation for the email preview pages";
2204
+ return [
2205
+ 4,
2206
+ forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath)
2207
+ ];
2208
+ case 8:
2209
+ _state.sent();
2210
+ spinner.text = "Updating package.json's build and start scripts";
2211
+ return [
2212
+ 4,
2213
+ updatePackageJson(builtPreviewAppPath)
2214
+ ];
2215
+ case 9:
2216
+ _state.sent();
2217
+ spinner.text = "Installing dependencies on `.react-email`";
2218
+ return [
2219
+ 4,
2220
+ npmInstall(builtPreviewAppPath, packageManager)
2221
+ ];
2222
+ case 10:
2223
+ _state.sent();
2224
+ spinner.stopAndPersist({
2225
+ text: "Successfully prepared `.react-email` for `next build`",
2226
+ symbol: import_log_symbols3.default.success
2227
+ });
2228
+ return [
2229
+ 4,
2230
+ buildPreviewApp(builtPreviewAppPath)
2231
+ ];
2232
+ case 11:
2233
+ _state.sent();
2234
+ return [
2235
+ 3,
2236
+ 13
2237
+ ];
2238
+ case 12:
2239
+ error = _state.sent();
2240
+ console.log(error);
2241
+ process.exit(1);
2242
+ return [
2243
+ 3,
2244
+ 13
2245
+ ];
2246
+ case 13:
2247
+ return [
2248
+ 2
2249
+ ];
2250
+ }
2251
+ });
2252
+ });
2253
+ return function build(_) {
2254
+ return _ref.apply(this, arguments);
2255
+ };
2256
+ }();
2257
+ // src/cli/commands/dev.ts
2258
+ var import_node_fs6 = __toESM(require("fs"));
2259
+ var dev = function() {
2260
+ var _ref = _async_to_generator(function(param) {
2261
+ var emailsDirRelativePath, port, devServer2, error;
2262
+ return _ts_generator(this, function(_state) {
2263
+ switch(_state.label){
2264
+ case 0:
2265
+ emailsDirRelativePath = param.dir, port = param.port;
2266
+ _state.label = 1;
2267
+ case 1:
2268
+ _state.trys.push([
2269
+ 1,
2270
+ 4,
2271
+ ,
2272
+ 5
2273
+ ]);
2274
+ if (!import_node_fs6.default.existsSync(emailsDirRelativePath)) {
2275
+ console.error("Missing ".concat(emailsDirRelativePath, " folder"));
2276
+ process.exit(1);
2277
+ }
2278
+ return [
2279
+ 4,
2280
+ startDevServer(emailsDirRelativePath, emailsDirRelativePath, // defaults to ./emails/static for the static files that are served to the preview
2281
+ Number.parseInt(port))
2282
+ ];
2283
+ case 2:
2284
+ devServer2 = _state.sent();
2285
+ return [
2286
+ 4,
2287
+ setupHotreloading(devServer2, emailsDirRelativePath)
2288
+ ];
2289
+ case 3:
2290
+ _state.sent();
2291
+ return [
2292
+ 3,
2293
+ 5
2294
+ ];
2295
+ case 4:
2296
+ error = _state.sent();
2297
+ console.log(error);
2298
+ process.exit(1);
2299
+ return [
2300
+ 3,
2301
+ 5
2302
+ ];
2303
+ case 5:
2304
+ return [
2305
+ 2
2306
+ ];
2307
+ }
2308
+ });
2309
+ });
2310
+ return function dev(_) {
2311
+ return _ref.apply(this, arguments);
2312
+ };
2313
+ }();
2314
+ // src/cli/commands/export.ts
2315
+ var import_node_fs8 = __toESM(require("fs"));
2316
+ var import_node_path10 = __toESM(require("path"));
2317
+ var import_esbuild = require("esbuild");
2318
+ var import_glob = require("glob");
2319
+ var import_log_symbols4 = __toESM(require("log-symbols"));
2320
+ var import_normalize_path = __toESM(require("normalize-path"));
2321
+ var import_ora3 = __toESM(require("ora"));
2322
+ // src/utils/esbuild/renderring-utilities-exporter.ts
2323
+ var import_node_fs7 = require("fs");
2324
+ var import_node_path9 = __toESM(require("path"));
2325
+ // src/utils/esbuild/escape-string-for-regex.ts
2326
+ function escapeStringForRegex(string) {
2327
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
2328
+ }
2329
+ // src/utils/esbuild/renderring-utilities-exporter.ts
2330
+ var renderingUtilitiesExporter = function(emailTemplates) {
2331
+ return {
2332
+ name: "rendering-utilities-exporter",
2333
+ setup: function(b) {
2334
+ b.onLoad({
2335
+ filter: new RegExp(emailTemplates.map(function(emailPath) {
2336
+ return escapeStringForRegex(emailPath);
2337
+ }).join("|"))
2338
+ }, function() {
2339
+ var _ref = _async_to_generator(function(param) {
2340
+ var pathToFile, _tmp, _, _1;
2341
+ return _ts_generator(this, function(_state) {
2342
+ switch(_state.label){
2343
+ case 0:
2344
+ pathToFile = param.path;
2345
+ _tmp = {};
2346
+ _1 = (_ = "").concat;
2347
+ return [
2348
+ 4,
2349
+ import_node_fs7.promises.readFile(pathToFile, "utf8")
2350
+ ];
2351
+ case 1:
2352
+ return [
2353
+ 2,
2354
+ (_tmp.contents = _1.apply(_, [
2355
+ _state.sent(),
2356
+ ";\n export { render } from 'react-email-module-that-will-export-render'\n export { createElement as reactEmailCreateReactElement } from 'react';\n "
2357
+ ]), _tmp.loader = import_node_path9.default.extname(pathToFile).slice(1), _tmp)
2358
+ ];
2359
+ }
2360
+ });
2361
+ });
2362
+ return function(_) {
2363
+ return _ref.apply(this, arguments);
2364
+ };
2365
+ }());
2034
2366
  b.onResolve({
2035
2367
  filter: /^react-email-module-that-will-export-render$/
2036
2368
  }, function() {
@@ -2084,7 +2416,7 @@ var renderingUtilitiesExporter = function(emailTemplates) {
2084
2416
  var getEmailTemplatesFromDirectory = function(emailDirectory) {
2085
2417
  var templatePaths = [];
2086
2418
  emailDirectory.emailFilenames.forEach(function(filename) {
2087
- return templatePaths.push(import_node_path9.default.join(emailDirectory.absolutePath, filename));
2419
+ return templatePaths.push(import_node_path10.default.join(emailDirectory.absolutePath, filename));
2088
2420
  });
2089
2421
  emailDirectory.subDirectories.forEach(function(directory) {
2090
2422
  var _templatePaths;
@@ -2098,25 +2430,25 @@ var exportTemplates = function() {
2098
2430
  return _ts_generator(this, function(_state) {
2099
2431
  switch(_state.label){
2100
2432
  case 0:
2101
- if (import_node_fs7.default.existsSync(pathToWhereEmailMarkupShouldBeDumped)) {
2102
- import_node_fs7.default.rmSync(pathToWhereEmailMarkupShouldBeDumped, {
2433
+ if (import_node_fs8.default.existsSync(pathToWhereEmailMarkupShouldBeDumped)) {
2434
+ import_node_fs8.default.rmSync(pathToWhereEmailMarkupShouldBeDumped, {
2103
2435
  recursive: true
2104
2436
  });
2105
2437
  }
2106
2438
  if (!options.silent) {
2107
- spinner = (0, import_ora2.default)("Preparing files...\n").start();
2439
+ spinner = (0, import_ora3.default)("Preparing files...\n").start();
2108
2440
  registerSpinnerAutostopping(spinner);
2109
2441
  }
2110
2442
  return [
2111
2443
  4,
2112
- getEmailsDirectoryMetadata(import_node_path9.default.resolve(process.cwd(), emailsDirectoryPath), true)
2444
+ getEmailsDirectoryMetadata(import_node_path10.default.resolve(process.cwd(), emailsDirectoryPath), true)
2113
2445
  ];
2114
2446
  case 1:
2115
2447
  emailsDirectoryMetadata = _state.sent();
2116
2448
  if (typeof emailsDirectoryMetadata === "undefined") {
2117
2449
  if (spinner) {
2118
2450
  spinner.stopAndPersist({
2119
- symbol: import_log_symbols3.default.error,
2451
+ symbol: import_log_symbols4.default.error,
2120
2452
  text: "Could not find the directory at ".concat(emailsDirectoryPath)
2121
2453
  });
2122
2454
  }
@@ -2165,7 +2497,7 @@ var exportTemplates = function() {
2165
2497
  buildFailure = exception;
2166
2498
  if (spinner) {
2167
2499
  spinner.stopAndPersist({
2168
- symbol: import_log_symbols3.default.error,
2500
+ symbol: import_log_symbols4.default.error,
2169
2501
  text: "Failed to build emails"
2170
2502
  });
2171
2503
  }
@@ -2213,519 +2545,183 @@ var exportTemplates = function() {
2213
2545
  12
2214
2546
  ]);
2215
2547
  if (spinner) {
2216
- spinner.text = "rendering ".concat(template.split("/").pop());
2217
- spinner.render();
2218
- }
2219
- delete require.cache[template];
2220
- emailModule = require(template);
2221
- return [
2222
- 4,
2223
- emailModule.render(emailModule.reactEmailCreateReactElement(emailModule.default, {}), options)
2224
- ];
2225
- case 10:
2226
- rendered = _state.sent();
2227
- htmlPath = template.replace(".cjs", options.plainText ? ".txt" : ".html");
2228
- (0, import_node_fs7.writeFileSync)(htmlPath, rendered);
2229
- (0, import_node_fs7.unlinkSync)(template);
2230
- return [
2231
- 3,
2232
- 12
2233
- ];
2234
- case 11:
2235
- exception1 = _state.sent();
2236
- if (spinner) {
2237
- spinner.stopAndPersist({
2238
- symbol: import_log_symbols3.default.error,
2239
- text: "failed when rendering ".concat(template.split("/").pop())
2240
- });
2241
- }
2242
- console.error(exception1);
2243
- process.exit(1);
2244
- return [
2245
- 3,
2246
- 12
2247
- ];
2248
- case 12:
2249
- _iteratorAbruptCompletion = false;
2250
- return [
2251
- 3,
2252
- 7
2253
- ];
2254
- case 13:
2255
- return [
2256
- 3,
2257
- 20
2258
- ];
2259
- case 14:
2260
- err = _state.sent();
2261
- _didIteratorError = true;
2262
- _iteratorError = err;
2263
- return [
2264
- 3,
2265
- 20
2266
- ];
2267
- case 15:
2268
- _state.trys.push([
2269
- 15,
2270
- ,
2271
- 18,
2272
- 19
2273
- ]);
2274
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
2275
- 3,
2276
- 17
2277
- ];
2278
- return [
2279
- 4,
2280
- _iterator.return()
2281
- ];
2282
- case 16:
2283
- _state.sent();
2284
- _state.label = 17;
2285
- case 17:
2286
- return [
2287
- 3,
2288
- 19
2289
- ];
2290
- case 18:
2291
- if (_didIteratorError) {
2292
- throw _iteratorError;
2293
- }
2294
- return [
2295
- 7
2296
- ];
2297
- case 19:
2298
- return [
2299
- 7
2300
- ];
2301
- case 20:
2302
- if (spinner) {
2303
- spinner.succeed("Rendered all files");
2304
- spinner.text = "Copying static files";
2305
- spinner.render();
2306
- }
2307
- staticDirectoryPath = import_node_path9.default.join(emailsDirectoryPath, "static");
2308
- if (!import_node_fs7.default.existsSync(staticDirectoryPath)) return [
2309
- 3,
2310
- 25
2311
- ];
2312
- pathToDumpStaticFilesInto = import_node_path9.default.join(pathToWhereEmailMarkupShouldBeDumped, "static");
2313
- if (!import_node_fs7.default.existsSync(pathToDumpStaticFilesInto)) return [
2314
- 3,
2315
- 22
2316
- ];
2317
- return [
2318
- 4,
2319
- import_node_fs7.default.promises.rm(pathToDumpStaticFilesInto, {
2320
- recursive: true
2321
- })
2322
- ];
2323
- case 21:
2324
- _state.sent();
2325
- _state.label = 22;
2326
- case 22:
2327
- _state.trys.push([
2328
- 22,
2329
- 24,
2330
- ,
2331
- 25
2332
- ]);
2333
- return [
2334
- 4,
2335
- import_node_fs7.default.promises.cp(staticDirectoryPath, pathToDumpStaticFilesInto, {
2336
- recursive: true
2337
- })
2338
- ];
2339
- case 23:
2340
- _state.sent();
2341
- return [
2342
- 3,
2343
- 25
2344
- ];
2345
- case 24:
2346
- exception2 = _state.sent();
2347
- console.error(exception2);
2348
- if (spinner) {
2349
- spinner.stopAndPersist({
2350
- symbol: import_log_symbols3.default.error,
2351
- text: "Failed to copy static files"
2352
- });
2353
- }
2354
- console.error("Something went wrong while copying the file to ".concat(pathToWhereEmailMarkupShouldBeDumped, "/static, ").concat(exception2));
2355
- process.exit(1);
2356
- return [
2357
- 3,
2358
- 25
2359
- ];
2360
- case 25:
2361
- if (!(spinner && !options.silent)) return [
2362
- 3,
2363
- 27
2364
- ];
2365
- spinner.succeed();
2366
- return [
2367
- 4,
2368
- tree(pathToWhereEmailMarkupShouldBeDumped, 4)
2369
- ];
2370
- case 26:
2371
- fileTree = _state.sent();
2372
- console.log(fileTree);
2373
- spinner.stopAndPersist({
2374
- symbol: import_log_symbols3.default.success,
2375
- text: "Successfully exported emails"
2376
- });
2377
- _state.label = 27;
2378
- case 27:
2379
- return [
2380
- 2
2381
- ];
2382
- }
2383
- });
2384
- });
2385
- return function exportTemplates(pathToWhereEmailMarkupShouldBeDumped, emailsDirectoryPath, options) {
2386
- return _ref.apply(this, arguments);
2387
- };
2388
- }();
2389
- // src/cli/commands/build.ts
2390
- var import_node_fs8 = __toESM(require("fs"));
2391
- var import_node_path10 = __toESM(require("path"));
2392
- var import_ora3 = __toESM(require("ora"));
2393
- var import_node_child_process = require("child_process");
2394
- var import_log_symbols4 = __toESM(require("log-symbols"));
2395
- var buildPreviewApp = function(absoluteDirectory) {
2396
- return new Promise(function(resolve, reject) {
2397
- var nextBuild = (0, import_node_child_process.spawn)("npm", [
2398
- "run",
2399
- "build"
2400
- ], {
2401
- cwd: absoluteDirectory,
2402
- shell: true
2403
- });
2404
- nextBuild.stdout.pipe(process.stdout);
2405
- nextBuild.stderr.pipe(process.stderr);
2406
- nextBuild.on("close", function(code) {
2407
- if (code === 0) {
2408
- resolve();
2409
- } else {
2410
- reject(new Error("Unable to build the Next app and it exited with code: ".concat(code)));
2411
- }
2412
- });
2413
- });
2414
- };
2415
- var setNextEnvironmentVariablesForBuild = function() {
2416
- var _ref = _async_to_generator(function(emailsDirRelativePath, builtPreviewAppPath) {
2417
- var nextConfigContents;
2418
- return _ts_generator(this, function(_state) {
2419
- switch(_state.label){
2420
- case 0:
2421
- nextConfigContents = "\nconst path = require('path');\nconst emailsDirRelativePath = path.normalize('".concat(emailsDirRelativePath, "');\nconst userProjectLocation = path.resolve(process.cwd(), '../');\n/** @type {import('next').NextConfig} */\nmodule.exports = {\n env: {\n NEXT_PUBLIC_IS_BUILDING: 'true',\n EMAILS_DIR_RELATIVE_PATH: emailsDirRelativePath,\n EMAILS_DIR_ABSOLUTE_PATH: path.resolve(userProjectLocation, emailsDirRelativePath),\n USER_PROJECT_LOCATION: userProjectLocation\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 },\n}");
2422
- return [
2423
- 4,
2424
- import_node_fs8.default.promises.writeFile(import_node_path10.default.resolve(builtPreviewAppPath, "./next.config.js"), nextConfigContents, "utf8")
2425
- ];
2426
- case 1:
2427
- _state.sent();
2428
- return [
2429
- 2
2430
- ];
2431
- }
2432
- });
2433
- });
2434
- return function setNextEnvironmentVariablesForBuild(emailsDirRelativePath, builtPreviewAppPath) {
2435
- return _ref.apply(this, arguments);
2436
- };
2437
- }();
2438
- var getEmailSlugsFromEmailDirectory = function(emailDirectory, emailsDirectoryAbsolutePath) {
2439
- var directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
2440
- var slugs = [];
2441
- emailDirectory.emailFilenames.forEach(function(filename) {
2442
- return slugs.push(import_node_path10.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path10.default.sep).filter(function(segment) {
2443
- return segment.length > 0;
2444
- }));
2445
- });
2446
- emailDirectory.subDirectories.forEach(function(directory) {
2447
- var _slugs;
2448
- (_slugs = slugs).push.apply(_slugs, _to_consumable_array(getEmailSlugsFromEmailDirectory(directory, emailsDirectoryAbsolutePath)));
2449
- });
2450
- return slugs;
2451
- };
2452
- var forceSSGForEmailPreviews = function() {
2453
- var _ref = _async_to_generator(function(emailsDirPath, builtPreviewAppPath) {
2454
- var emailDirectoryMetadata, parameters, removeForceDynamic;
2455
- return _ts_generator(this, function(_state) {
2456
- switch(_state.label){
2457
- case 0:
2458
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2459
- return [
2460
- 4,
2461
- getEmailsDirectoryMetadata(emailsDirPath)
2462
- ];
2463
- case 1:
2464
- emailDirectoryMetadata = _state.sent();
2465
- parameters = getEmailSlugsFromEmailDirectory(emailDirectoryMetadata, emailsDirPath).map(function(slug) {
2466
- return {
2467
- slug: slug
2468
- };
2469
- });
2470
- removeForceDynamic = function() {
2471
- var _ref = _async_to_generator(function(filePath) {
2472
- var contents;
2473
- return _ts_generator(this, function(_state) {
2474
- switch(_state.label){
2475
- case 0:
2476
- return [
2477
- 4,
2478
- import_node_fs8.default.promises.readFile(filePath, "utf8")
2479
- ];
2480
- case 1:
2481
- contents = _state.sent();
2482
- return [
2483
- 4,
2484
- import_node_fs8.default.promises.writeFile(filePath, contents.replace("export const dynamic = 'force-dynamic';", ""), "utf8")
2485
- ];
2486
- case 2:
2487
- _state.sent();
2488
- return [
2489
- 2
2490
- ];
2491
- }
2492
- });
2493
- });
2494
- return function removeForceDynamic(filePath) {
2495
- return _ref.apply(this, arguments);
2496
- };
2497
- }();
2498
- return [
2499
- 4,
2500
- removeForceDynamic(import_node_path10.default.resolve(builtPreviewAppPath, "./src/app/layout.tsx"))
2501
- ];
2502
- case 2:
2503
- _state.sent();
2548
+ spinner.text = "rendering ".concat(template.split("/").pop());
2549
+ spinner.render();
2550
+ }
2551
+ delete require.cache[template];
2552
+ emailModule = require(template);
2504
2553
  return [
2505
2554
  4,
2506
- removeForceDynamic(import_node_path10.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"))
2555
+ emailModule.render(emailModule.reactEmailCreateReactElement(emailModule.default, {}), options)
2507
2556
  ];
2508
- case 3:
2509
- _state.sent();
2557
+ case 10:
2558
+ rendered = _state.sent();
2559
+ htmlPath = template.replace(".cjs", options.plainText ? ".txt" : ".html");
2560
+ (0, import_node_fs8.writeFileSync)(htmlPath, rendered);
2561
+ (0, import_node_fs8.unlinkSync)(template);
2510
2562
  return [
2511
- 4,
2512
- import_node_fs8.default.promises.appendFile(import_node_path10.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"), "\n\nexport function generateStaticParams() { \n return Promise.resolve(\n ".concat(JSON.stringify(parameters), "\n );\n}"), "utf8")
2563
+ 3,
2564
+ 12
2513
2565
  ];
2514
- case 4:
2515
- _state.sent();
2566
+ case 11:
2567
+ exception1 = _state.sent();
2568
+ if (spinner) {
2569
+ spinner.stopAndPersist({
2570
+ symbol: import_log_symbols4.default.error,
2571
+ text: "failed when rendering ".concat(template.split("/").pop())
2572
+ });
2573
+ }
2574
+ console.error(exception1);
2575
+ process.exit(1);
2516
2576
  return [
2517
- 2
2577
+ 3,
2578
+ 12
2518
2579
  ];
2519
- }
2520
- });
2521
- });
2522
- return function forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath) {
2523
- return _ref.apply(this, arguments);
2524
- };
2525
- }();
2526
- var updatePackageJson = function() {
2527
- var _ref = _async_to_generator(function(builtPreviewAppPath) {
2528
- var packageJsonPath, packageJson, _;
2529
- return _ts_generator(this, function(_state) {
2530
- switch(_state.label){
2531
- case 0:
2532
- packageJsonPath = import_node_path10.default.resolve(builtPreviewAppPath, "./package.json");
2533
- _ = JSON.parse;
2580
+ case 12:
2581
+ _iteratorAbruptCompletion = false;
2534
2582
  return [
2535
- 4,
2536
- import_node_fs8.default.promises.readFile(packageJsonPath, "utf8")
2583
+ 3,
2584
+ 7
2537
2585
  ];
2538
- case 1:
2539
- packageJson = _.apply(JSON, [
2540
- _state.sent()
2541
- ]);
2542
- packageJson.scripts.build = "next build";
2543
- packageJson.scripts.start = "next start";
2544
- packageJson.name = "preview-server";
2545
- delete packageJson.devDependencies["@react-email/render"];
2546
- delete packageJson.devDependencies["@react-email/components"];
2586
+ case 13:
2547
2587
  return [
2548
- 4,
2549
- import_node_fs8.default.promises.writeFile(packageJsonPath, JSON.stringify(packageJson), "utf8")
2588
+ 3,
2589
+ 20
2550
2590
  ];
2551
- case 2:
2552
- _state.sent();
2591
+ case 14:
2592
+ err = _state.sent();
2593
+ _didIteratorError = true;
2594
+ _iteratorError = err;
2553
2595
  return [
2554
- 2
2596
+ 3,
2597
+ 20
2555
2598
  ];
2556
- }
2557
- });
2558
- });
2559
- return function updatePackageJson(builtPreviewAppPath) {
2560
- return _ref.apply(this, arguments);
2561
- };
2562
- }();
2563
- var npmInstall = function() {
2564
- var _ref = _async_to_generator(function(builtPreviewAppPath, packageManager) {
2565
- return _ts_generator(this, function(_state) {
2566
- return [
2567
- 2,
2568
- new Promise(function(resolve, reject) {
2569
- var childProc = (0, import_node_child_process.spawn)(packageManager, [
2570
- "install",
2571
- "--silent",
2572
- "--include=dev"
2573
- ], {
2574
- cwd: builtPreviewAppPath,
2575
- shell: true
2576
- });
2577
- childProc.stdout.pipe(process.stdout);
2578
- childProc.stderr.pipe(process.stderr);
2579
- childProc.on("close", function(code) {
2580
- if (code === 0) {
2581
- resolve();
2582
- } else {
2583
- reject(new Error("Unable to install the dependencies and it exited with code: ".concat(code)));
2584
- }
2585
- });
2586
- })
2587
- ];
2588
- });
2589
- });
2590
- return function npmInstall(builtPreviewAppPath, packageManager) {
2591
- return _ref.apply(this, arguments);
2592
- };
2593
- }();
2594
- var build2 = function() {
2595
- var _ref = _async_to_generator(function(param) {
2596
- var emailsDirRelativePath, packageManager, spinner, emailsDirPath, staticPath, builtPreviewAppPath, builtStaticDirectory, error;
2597
- return _ts_generator(this, function(_state) {
2598
- switch(_state.label){
2599
- case 0:
2600
- emailsDirRelativePath = param.dir, packageManager = param.packageManager;
2601
- _state.label = 1;
2602
- case 1:
2599
+ case 15:
2603
2600
  _state.trys.push([
2604
- 1,
2605
- 12,
2601
+ 15,
2606
2602
  ,
2607
- 13
2603
+ 18,
2604
+ 19
2608
2605
  ]);
2609
- spinner = (0, import_ora3.default)({
2610
- text: "Starting build process...",
2611
- prefixText: " "
2612
- }).start();
2613
- registerSpinnerAutostopping(spinner);
2614
- spinner.text = "Checking if ".concat(emailsDirRelativePath, " folder exists");
2615
- if (!import_node_fs8.default.existsSync(emailsDirRelativePath)) {
2616
- process.exit(1);
2617
- }
2618
- emailsDirPath = import_node_path10.default.join(process.cwd(), emailsDirRelativePath);
2619
- staticPath = import_node_path10.default.join(emailsDirPath, "static");
2620
- builtPreviewAppPath = import_node_path10.default.join(process.cwd(), ".react-email");
2621
- if (!import_node_fs8.default.existsSync(builtPreviewAppPath)) return [
2606
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
2622
2607
  3,
2623
- 3
2608
+ 17
2624
2609
  ];
2625
- spinner.text = "Deleting pre-existing `.react-email` folder";
2626
2610
  return [
2627
2611
  4,
2628
- import_node_fs8.default.promises.rm(builtPreviewAppPath, {
2629
- recursive: true
2630
- })
2612
+ _iterator.return()
2631
2613
  ];
2632
- case 2:
2614
+ case 16:
2633
2615
  _state.sent();
2634
- _state.label = 3;
2635
- case 3:
2636
- spinner.text = "Copying preview app from CLI to `.react-email`";
2616
+ _state.label = 17;
2617
+ case 17:
2637
2618
  return [
2638
- 4,
2639
- import_node_fs8.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
2640
- recursive: true,
2641
- filter: function(source) {
2642
- return !/(\/|\\)cli(\/|\\)?/.test(source) && !/(\/|\\)\.next(\/|\\)?/.test(source) && !/(\/|\\)\.turbo(\/|\\)?/.test(source) && !/(\/|\\)node_modules(\/|\\)?$/.test(source);
2643
- }
2644
- })
2645
- ];
2646
- case 4:
2647
- _state.sent();
2648
- if (!import_node_fs8.default.existsSync(staticPath)) return [
2649
2619
  3,
2650
- 6
2620
+ 19
2651
2621
  ];
2652
- spinner.text = "Copying `static` folder into `.react-email/public/static`";
2653
- builtStaticDirectory = import_node_path10.default.resolve(builtPreviewAppPath, "./public/static");
2622
+ case 18:
2623
+ if (_didIteratorError) {
2624
+ throw _iteratorError;
2625
+ }
2654
2626
  return [
2655
- 4,
2656
- import_node_fs8.default.promises.cp(staticPath, builtStaticDirectory, {
2657
- recursive: true
2658
- })
2627
+ 7
2659
2628
  ];
2660
- case 5:
2661
- _state.sent();
2662
- _state.label = 6;
2663
- case 6:
2664
- spinner.text = "Setting Next environment variables for preview app to work properly";
2629
+ case 19:
2665
2630
  return [
2666
- 4,
2667
- setNextEnvironmentVariablesForBuild(emailsDirRelativePath, builtPreviewAppPath)
2631
+ 7
2668
2632
  ];
2669
- case 7:
2670
- _state.sent();
2671
- spinner.text = "Setting server side generation for the email preview pages";
2672
- return [
2673
- 4,
2674
- forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath)
2633
+ case 20:
2634
+ if (spinner) {
2635
+ spinner.succeed("Rendered all files");
2636
+ spinner.text = "Copying static files";
2637
+ spinner.render();
2638
+ }
2639
+ staticDirectoryPath = import_node_path10.default.join(emailsDirectoryPath, "static");
2640
+ if (!import_node_fs8.default.existsSync(staticDirectoryPath)) return [
2641
+ 3,
2642
+ 25
2675
2643
  ];
2676
- case 8:
2677
- _state.sent();
2678
- spinner.text = "Updating package.json's build and start scripts";
2679
- return [
2680
- 4,
2681
- updatePackageJson(builtPreviewAppPath)
2644
+ pathToDumpStaticFilesInto = import_node_path10.default.join(pathToWhereEmailMarkupShouldBeDumped, "static");
2645
+ if (!import_node_fs8.default.existsSync(pathToDumpStaticFilesInto)) return [
2646
+ 3,
2647
+ 22
2682
2648
  ];
2683
- case 9:
2684
- _state.sent();
2685
- spinner.text = "Installing dependencies on `.react-email`";
2686
2649
  return [
2687
2650
  4,
2688
- npmInstall(builtPreviewAppPath, packageManager)
2651
+ import_node_fs8.default.promises.rm(pathToDumpStaticFilesInto, {
2652
+ recursive: true
2653
+ })
2689
2654
  ];
2690
- case 10:
2655
+ case 21:
2691
2656
  _state.sent();
2692
- spinner.stopAndPersist({
2693
- text: "Successfully prepared `.react-email` for `next build`",
2694
- symbol: import_log_symbols4.default.success
2695
- });
2657
+ _state.label = 22;
2658
+ case 22:
2659
+ _state.trys.push([
2660
+ 22,
2661
+ 24,
2662
+ ,
2663
+ 25
2664
+ ]);
2696
2665
  return [
2697
2666
  4,
2698
- buildPreviewApp(builtPreviewAppPath)
2667
+ import_node_fs8.default.promises.cp(staticDirectoryPath, pathToDumpStaticFilesInto, {
2668
+ recursive: true
2669
+ })
2699
2670
  ];
2700
- case 11:
2671
+ case 23:
2701
2672
  _state.sent();
2702
2673
  return [
2703
2674
  3,
2704
- 13
2675
+ 25
2705
2676
  ];
2706
- case 12:
2707
- error = _state.sent();
2708
- console.log(error);
2677
+ case 24:
2678
+ exception2 = _state.sent();
2679
+ console.error(exception2);
2680
+ if (spinner) {
2681
+ spinner.stopAndPersist({
2682
+ symbol: import_log_symbols4.default.error,
2683
+ text: "Failed to copy static files"
2684
+ });
2685
+ }
2686
+ console.error("Something went wrong while copying the file to ".concat(pathToWhereEmailMarkupShouldBeDumped, "/static, ").concat(exception2));
2709
2687
  process.exit(1);
2710
2688
  return [
2711
2689
  3,
2712
- 13
2690
+ 25
2713
2691
  ];
2714
- case 13:
2692
+ case 25:
2693
+ if (!(spinner && !options.silent)) return [
2694
+ 3,
2695
+ 27
2696
+ ];
2697
+ spinner.succeed();
2698
+ return [
2699
+ 4,
2700
+ tree(pathToWhereEmailMarkupShouldBeDumped, 4)
2701
+ ];
2702
+ case 26:
2703
+ fileTree = _state.sent();
2704
+ console.log(fileTree);
2705
+ spinner.stopAndPersist({
2706
+ symbol: import_log_symbols4.default.success,
2707
+ text: "Successfully exported emails"
2708
+ });
2709
+ _state.label = 27;
2710
+ case 27:
2715
2711
  return [
2716
2712
  2
2717
2713
  ];
2718
2714
  }
2719
2715
  });
2720
2716
  });
2721
- return function build2(_) {
2717
+ return function exportTemplates(pathToWhereEmailMarkupShouldBeDumped, emailsDirectoryPath, options) {
2722
2718
  return _ref.apply(this, arguments);
2723
2719
  };
2724
2720
  }();
2725
2721
  // src/cli/commands/start.ts
2722
+ var import_node_child_process2 = require("child_process");
2726
2723
  var import_node_fs9 = __toESM(require("fs"));
2727
2724
  var import_node_path11 = __toESM(require("path"));
2728
- var import_node_child_process2 = require("child_process");
2729
2725
  var start = function() {
2730
2726
  var _ref = _async_to_generator(function() {
2731
2727
  var usersProjectLocation, builtPreviewPath, nextStart;
@@ -2766,7 +2762,7 @@ var start = function() {
2766
2762
  var PACKAGE_NAME = "react-email";
2767
2763
  import_commander.program.name(PACKAGE_NAME).description("A live preview of your emails right in your browser").version(package_default.version);
2768
2764
  import_commander.program.command("dev").description("Starts the preview email development app").option("-d, --dir <path>", "Directory with your email templates", "./emails").option("-p --port <port>", "Port to run dev server on", "3000").action(dev);
2769
- import_commander.program.command("build").description("Copies the preview app for onto .react-email and builds it").option("-d, --dir <path>", "Directory with your email templates", "./emails").option("-p --packageManager <name>", "Package name to use on installation on `.react-email`", "npm").action(build2);
2765
+ import_commander.program.command("build").description("Copies the preview app for onto .react-email and builds it").option("-d, --dir <path>", "Directory with your email templates", "./emails").option("-p --packageManager <name>", "Package name to use on installation on `.react-email`", "npm").action(build);
2770
2766
  import_commander.program.command("start").description('Runs the built preview app that is inside of ".react-email"').action(start);
2771
2767
  import_commander.program.command("export").description("Build the templates to the `out` directory").option("--outDir <path>", "Output directory", "out").option("-p, --pretty", "Pretty print the output", false).option("-t, --plainText", "Set output format as plain text", false).option("-d, --dir <path>", "Directory with your email templates", "./emails").option("-s, --silent", "To, or not to show a spinner with process information", false).action(function(param) {
2772
2768
  var outDir = param.outDir, pretty = param.pretty, plainText = param.plainText, silent = param.silent, srcDir = param.dir;