react-email 3.0.6 → 4.0.0-alpha.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/CHANGELOG.md +6 -0
- package/dist/cli/index.js +768 -763
- package/dist/cli/index.mjs +480 -476
- package/dist/preview/.next/BUILD_ID +1 -1
- package/dist/preview/.next/app-build-manifest.json +14 -12
- package/dist/preview/.next/build-manifest.json +5 -5
- package/dist/preview/.next/cache/.rscinfo +1 -1
- package/dist/preview/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/preview/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/preview/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/preview/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/preview/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/preview/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/preview/.next/next-server.js.nft.json +1 -1
- package/dist/preview/.next/prerender-manifest.json +1 -1
- package/dist/preview/.next/server/app/_not-found/page.js +1 -1
- package/dist/preview/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/app/page.js +1 -1
- package/dist/preview/.next/server/app/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/app/preview/[...slug]/page.js +6 -6
- package/dist/preview/.next/server/app/preview/[...slug]/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/preview/[...slug]/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/chunks/273.js +1 -0
- package/dist/preview/.next/server/chunks/594.js +10 -0
- package/dist/preview/.next/server/middleware-build-manifest.js +1 -1
- package/dist/preview/.next/server/pages/500.html +1 -1
- package/dist/preview/.next/server/server-reference-manifest.js +1 -1
- package/dist/preview/.next/server/server-reference-manifest.json +1 -1
- package/dist/preview/.next/server/webpack-runtime.js +1 -1
- package/dist/preview/.next/static/chunks/18b16e15-6ad9b58e10ff8891.js +1 -0
- package/dist/preview/.next/static/chunks/490-48951f2e19ae3aef.js +1 -0
- package/dist/preview/.next/static/chunks/600-2e2ca4c8bbd97b61.js +1 -0
- package/dist/preview/.next/static/chunks/app/{layout-a2901ed1c2c53661.js → layout-490964e2c3604d33.js} +1 -1
- package/dist/preview/.next/static/chunks/app/page-d2432acd08db8fc0.js +1 -0
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-f4e211e00c026401.js +1 -0
- package/dist/preview/.next/static/chunks/webpack-7bf1ffb05f5540be.js +1 -0
- package/dist/preview/.next/static/css/5e0736cafbb392a9.css +3 -0
- package/dist/preview/.next/trace +21 -21
- package/package.json +12 -7
- package/postcss.config.js +1 -1
- package/src/actions/email-validation/check-links.ts +88 -0
- package/src/actions/email-validation/get-line-and-column-from-index.spec.ts +22 -0
- package/src/actions/email-validation/get-line-and-column-from-index.ts +43 -0
- package/src/actions/email-validation/quick-fetch.ts +12 -0
- package/src/actions/get-email-path-from-slug.ts +7 -4
- package/src/actions/render-email-by-path.tsx +3 -3
- package/src/animated-icons-data/help.json +1082 -0
- package/src/animated-icons-data/link.json +1309 -0
- package/src/animated-icons-data/load.json +443 -0
- package/src/animated-icons-data/mail.json +1320 -0
- package/src/app/globals.css +0 -24
- package/src/app/layout.tsx +7 -3
- package/src/app/page.tsx +9 -10
- package/src/app/preview/[...slug]/page.tsx +3 -2
- package/src/app/preview/[...slug]/preview.tsx +5 -5
- package/src/app/preview/[...slug]/rendering-error.tsx +6 -6
- package/src/components/button.tsx +8 -8
- package/src/components/code-container.tsx +7 -7
- package/src/components/code-snippet.tsx +11 -0
- package/src/components/code.tsx +4 -4
- package/src/components/heading.tsx +1 -1
- package/src/components/icons/icon-button.tsx +1 -1
- package/src/components/icons/icon-circle-check.tsx +21 -0
- package/src/components/icons/icon-circle-close.tsx +17 -0
- package/src/components/icons/icon-circle-warning.tsx +17 -0
- package/src/components/icons/icon-email.tsx +18 -0
- package/src/components/icons/icon-link.tsx +14 -0
- package/src/components/icons/icon-stamp.tsx +14 -0
- package/src/components/send.tsx +9 -9
- package/src/components/shell.tsx +32 -34
- package/src/components/sidebar/{sidebar-directory-children.tsx → file-tree-directory-children.tsx} +22 -18
- package/src/components/sidebar/{sidebar-directory.tsx → file-tree-directory.tsx} +11 -12
- package/src/components/sidebar/file-tree.tsx +31 -0
- package/src/components/sidebar/link-checker.tsx +291 -0
- package/src/components/sidebar/sidebar.tsx +296 -22
- package/src/components/text.tsx +1 -1
- package/src/components/tooltip-content.tsx +3 -3
- package/src/components/tooltip.tsx +1 -1
- package/src/components/topbar.tsx +14 -17
- package/src/hooks/use-email-rendering-result.ts +2 -2
- package/src/hooks/use-icon-animation.ts +44 -0
- package/src/utils/cn.ts +1 -1
- package/src/utils/esbuild/renderring-utilities-exporter.ts +1 -1
- package/src/utils/get-email-component.ts +6 -6
- package/src/utils/get-emails-directory-metadata.spec.ts +0 -1
- package/src/utils/improve-error-with-sourcemap.ts +1 -1
- package/src/utils/static-node-modules-for-vm.ts +6 -6
- package/tsconfig.json +2 -6
- package/.eslintrc.js +0 -52
- package/.prettierignore +0 -3
- package/.prettierrc.js +0 -8
- package/dist/preview/.next/cache/eslint/.cache_1c3sgg +0 -1
- package/dist/preview/.next/server/chunks/391.js +0 -1
- package/dist/preview/.next/server/chunks/720.js +0 -10
- package/dist/preview/.next/static/chunks/12-b9450aa0845e7574.js +0 -1
- package/dist/preview/.next/static/chunks/154-4202f86af36ccff4.js +0 -1
- package/dist/preview/.next/static/chunks/app/page-54a86772095e22e0.js +0 -1
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-2bfad134b65ddd79.js +0 -1
- package/dist/preview/.next/static/chunks/webpack-9255716c9496e606.js +0 -1
- package/dist/preview/.next/static/css/eb0a93282704d7ab.css +0 -3
- /package/dist/preview/.next/static/{Trk1e7GzgKOLunAXBDCy- → fZaiKz58wDr55pxLu9uHa}/_buildManifest.js +0 -0
- /package/dist/preview/.next/static/{Trk1e7GzgKOLunAXBDCy- → fZaiKz58wDr55pxLu9uHa}/_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: "
|
|
343
|
+
version: "4.0.0-alpha.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: {
|
|
@@ -367,8 +366,8 @@ var package_default = {
|
|
|
367
366
|
node: ">=18.0.0"
|
|
368
367
|
},
|
|
369
368
|
dependencies: {
|
|
370
|
-
"@babel/core": "7.24.5",
|
|
371
369
|
"@babel/parser": "7.24.5",
|
|
370
|
+
"@babel/traverse": "7.25.6",
|
|
372
371
|
chalk: "4.1.2",
|
|
373
372
|
chokidar: "4.0.3",
|
|
374
373
|
commander: "11.1.0",
|
|
@@ -382,16 +381,22 @@ var package_default = {
|
|
|
382
381
|
ora: "5.4.1",
|
|
383
382
|
"socket.io": "4.8.0"
|
|
384
383
|
},
|
|
384
|
+
overrides: {
|
|
385
|
+
react: "^19",
|
|
386
|
+
"react-dom": "^19"
|
|
387
|
+
},
|
|
385
388
|
devDependencies: {
|
|
386
389
|
"@radix-ui/colors": "1.0.1",
|
|
387
390
|
"@radix-ui/react-collapsible": "1.1.0",
|
|
388
391
|
"@radix-ui/react-popover": "1.1.1",
|
|
389
392
|
"@radix-ui/react-slot": "1.1.0",
|
|
393
|
+
"@radix-ui/react-tabs": "1.1.1",
|
|
390
394
|
"@radix-ui/react-toggle-group": "1.1.0",
|
|
391
395
|
"@radix-ui/react-tooltip": "1.1.2",
|
|
392
396
|
"@react-email/render": "workspace:*",
|
|
393
397
|
"@swc/core": "1.4.15",
|
|
394
398
|
"@types/babel__core": "7.20.5",
|
|
399
|
+
"@types/babel__traverse": "*",
|
|
395
400
|
"@types/fs-extra": "11.0.1",
|
|
396
401
|
"@types/mime-types": "2.1.4",
|
|
397
402
|
"@types/node": "22.10.2",
|
|
@@ -402,11 +407,11 @@ var package_default = {
|
|
|
402
407
|
"@vercel/style-guide": "5.1.0",
|
|
403
408
|
autoprefixer: "10.4.20",
|
|
404
409
|
clsx: "2.1.0",
|
|
405
|
-
eslint: "8.50.0",
|
|
406
|
-
"eslint-config-prettier": "9.0.0",
|
|
407
|
-
"eslint-config-turbo": "2.1.0",
|
|
408
410
|
"framer-motion": "12.0.0-alpha.2",
|
|
411
|
+
"lottie-react": "^2.4.0",
|
|
412
|
+
"node-html-parser": "6.1.13",
|
|
409
413
|
postcss: "8.4.40",
|
|
414
|
+
"prettier-plugin-tailwindcss": "0.6.6",
|
|
410
415
|
"prism-react-renderer": "2.1.0",
|
|
411
416
|
react: "^19",
|
|
412
417
|
"react-dom": "^19",
|
|
@@ -423,12 +428,121 @@ var package_default = {
|
|
|
423
428
|
vitest: "1.1.3"
|
|
424
429
|
}
|
|
425
430
|
};
|
|
426
|
-
// src/cli/commands/
|
|
427
|
-
var
|
|
431
|
+
// src/cli/commands/build.ts
|
|
432
|
+
var import_node_child_process = require("child_process");
|
|
433
|
+
var import_node_fs5 = __toESM(require("fs"));
|
|
434
|
+
var import_node_path8 = __toESM(require("path"));
|
|
435
|
+
var import_log_symbols3 = __toESM(require("log-symbols"));
|
|
436
|
+
var import_ora2 = __toESM(require("ora"));
|
|
437
|
+
// src/utils/get-emails-directory-metadata.ts
|
|
438
|
+
var import_node_fs = __toESM(require("fs"));
|
|
439
|
+
var import_node_path = __toESM(require("path"));
|
|
440
|
+
var isFileAnEmail = function(fullPath) {
|
|
441
|
+
var stat = import_node_fs.default.statSync(fullPath);
|
|
442
|
+
if (stat.isDirectory()) return false;
|
|
443
|
+
var ext = import_node_path.default.parse(fullPath).ext;
|
|
444
|
+
if (![
|
|
445
|
+
".js",
|
|
446
|
+
".tsx",
|
|
447
|
+
".jsx"
|
|
448
|
+
].includes(ext)) return false;
|
|
449
|
+
if (!import_node_fs.default.existsSync(fullPath)) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
var fileContents = import_node_fs.default.readFileSync(fullPath, "utf8");
|
|
453
|
+
return /\bexport\s+default\b/gm.test(fileContents);
|
|
454
|
+
};
|
|
455
|
+
var mergeDirectoriesWithSubDirectories = function(emailsDirectoryMetadata) {
|
|
456
|
+
var currentResultingMergedDirectory = emailsDirectoryMetadata;
|
|
457
|
+
while(currentResultingMergedDirectory.emailFilenames.length === 0 && currentResultingMergedDirectory.subDirectories.length === 1){
|
|
458
|
+
var onlySubDirectory = currentResultingMergedDirectory.subDirectories[0];
|
|
459
|
+
currentResultingMergedDirectory = _object_spread_props(_object_spread({}, onlySubDirectory), {
|
|
460
|
+
directoryName: import_node_path.default.join(currentResultingMergedDirectory.directoryName, onlySubDirectory.directoryName)
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
return currentResultingMergedDirectory;
|
|
464
|
+
};
|
|
465
|
+
var getEmailsDirectoryMetadata = function() {
|
|
466
|
+
var _ref = _async_to_generator(function(absolutePathToEmailsDirectory) {
|
|
467
|
+
var keepFileExtensions, isSubDirectory, baseDirectoryPath, dirents, emailFilenames, subDirectories, emailsMetadata;
|
|
468
|
+
var _arguments = arguments;
|
|
469
|
+
return _ts_generator(this, function(_state) {
|
|
470
|
+
switch(_state.label){
|
|
471
|
+
case 0:
|
|
472
|
+
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;
|
|
473
|
+
if (!import_node_fs.default.existsSync(absolutePathToEmailsDirectory)) return [
|
|
474
|
+
2
|
|
475
|
+
];
|
|
476
|
+
return [
|
|
477
|
+
4,
|
|
478
|
+
import_node_fs.default.promises.readdir(absolutePathToEmailsDirectory, {
|
|
479
|
+
withFileTypes: true
|
|
480
|
+
})
|
|
481
|
+
];
|
|
482
|
+
case 1:
|
|
483
|
+
dirents = _state.sent();
|
|
484
|
+
emailFilenames = dirents.filter(function(dirent) {
|
|
485
|
+
return isFileAnEmail(import_node_path.default.join(absolutePathToEmailsDirectory, dirent.name));
|
|
486
|
+
}).map(function(dirent) {
|
|
487
|
+
return keepFileExtensions ? dirent.name : dirent.name.replace(import_node_path.default.extname(dirent.name), "");
|
|
488
|
+
});
|
|
489
|
+
return [
|
|
490
|
+
4,
|
|
491
|
+
Promise.all(dirents.filter(function(dirent) {
|
|
492
|
+
return dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static";
|
|
493
|
+
}).map(function(dirent) {
|
|
494
|
+
var direntAbsolutePath = import_node_path.default.join(absolutePathToEmailsDirectory, dirent.name);
|
|
495
|
+
return getEmailsDirectoryMetadata(direntAbsolutePath, keepFileExtensions, true, baseDirectoryPath);
|
|
496
|
+
}))
|
|
497
|
+
];
|
|
498
|
+
case 2:
|
|
499
|
+
subDirectories = _state.sent();
|
|
500
|
+
emailsMetadata = {
|
|
501
|
+
absolutePath: absolutePathToEmailsDirectory,
|
|
502
|
+
relativePath: import_node_path.default.relative(baseDirectoryPath, absolutePathToEmailsDirectory),
|
|
503
|
+
directoryName: absolutePathToEmailsDirectory.split(import_node_path.default.sep).pop(),
|
|
504
|
+
emailFilenames: emailFilenames,
|
|
505
|
+
subDirectories: subDirectories
|
|
506
|
+
};
|
|
507
|
+
return [
|
|
508
|
+
2,
|
|
509
|
+
isSubDirectory ? mergeDirectoriesWithSubDirectories(emailsMetadata) : emailsMetadata
|
|
510
|
+
];
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
return function getEmailsDirectoryMetadata(absolutePathToEmailsDirectory) {
|
|
515
|
+
return _ref.apply(this, arguments);
|
|
516
|
+
};
|
|
517
|
+
}();
|
|
518
|
+
// src/utils/register-spinner-autostopping.ts
|
|
519
|
+
var import_log_symbols = __toESM(require("log-symbols"));
|
|
520
|
+
var spinners = /* @__PURE__ */ new Set();
|
|
521
|
+
process.on("SIGINT", function() {
|
|
522
|
+
spinners.forEach(function(spinner) {
|
|
523
|
+
if (spinner.isSpinning) {
|
|
524
|
+
spinner.stop();
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
process.on("exit", function(code) {
|
|
529
|
+
if (code !== 0) {
|
|
530
|
+
spinners.forEach(function(spinner) {
|
|
531
|
+
if (spinner.isSpinning) {
|
|
532
|
+
spinner.stopAndPersist({
|
|
533
|
+
symbol: import_log_symbols.default.error
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
var registerSpinnerAutostopping = function(spinner) {
|
|
540
|
+
spinners.add(spinner);
|
|
541
|
+
};
|
|
428
542
|
// src/cli/utils/tree.ts
|
|
429
|
-
var
|
|
543
|
+
var import_node_fs2 = require("fs");
|
|
430
544
|
var import_node_os = __toESM(require("os"));
|
|
431
|
-
var
|
|
545
|
+
var import_node_path2 = __toESM(require("path"));
|
|
432
546
|
var SYMBOLS = {
|
|
433
547
|
BRANCH: "├── ",
|
|
434
548
|
EMPTY: "",
|
|
@@ -445,14 +559,14 @@ var getTreeLines = function() {
|
|
|
445
559
|
case 0:
|
|
446
560
|
currentDepth = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : 0;
|
|
447
561
|
base = process.cwd();
|
|
448
|
-
dirFullpath =
|
|
449
|
-
dirname =
|
|
562
|
+
dirFullpath = import_node_path2.default.resolve(base, dirPath);
|
|
563
|
+
dirname = import_node_path2.default.basename(dirFullpath);
|
|
450
564
|
lines = [
|
|
451
565
|
dirname
|
|
452
566
|
];
|
|
453
567
|
return [
|
|
454
568
|
4,
|
|
455
|
-
|
|
569
|
+
import_node_fs2.promises.stat(dirFullpath)
|
|
456
570
|
];
|
|
457
571
|
case 1:
|
|
458
572
|
dirStat = _state.sent();
|
|
@@ -479,7 +593,7 @@ var getTreeLines = function() {
|
|
|
479
593
|
3
|
|
480
594
|
];
|
|
481
595
|
case 1:
|
|
482
|
-
pathToDirectory =
|
|
596
|
+
pathToDirectory = import_node_path2.default.join(dirFullpath, dirent.name);
|
|
483
597
|
return [
|
|
484
598
|
4,
|
|
485
599
|
getTreeLines(pathToDirectory, depth, currentDepth + 1)
|
|
@@ -499,7 +613,7 @@ var getTreeLines = function() {
|
|
|
499
613
|
};
|
|
500
614
|
return [
|
|
501
615
|
4,
|
|
502
|
-
|
|
616
|
+
import_node_fs2.promises.readdir(dirFullpath, {
|
|
503
617
|
withFileTypes: true
|
|
504
618
|
})
|
|
505
619
|
];
|
|
@@ -570,92 +684,33 @@ var tree = function() {
|
|
|
570
684
|
};
|
|
571
685
|
}();
|
|
572
686
|
// src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
573
|
-
var
|
|
574
|
-
var import_socket = require("socket.io");
|
|
687
|
+
var import_node_path7 = __toESM(require("path"));
|
|
575
688
|
var import_chokidar = require("chokidar");
|
|
576
689
|
var import_debounce = __toESM(require("debounce"));
|
|
690
|
+
var import_socket = require("socket.io");
|
|
577
691
|
// src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
578
|
-
var
|
|
579
|
-
var
|
|
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
|
-
};
|
|
692
|
+
var import_node_fs4 = require("fs");
|
|
693
|
+
var import_node_path6 = __toESM(require("path"));
|
|
624
694
|
// src/cli/utils/preview/start-dev-server.ts
|
|
625
|
-
var import_node_path4 = __toESM(require("path"));
|
|
626
695
|
var import_node_http = __toESM(require("http"));
|
|
696
|
+
var import_node_path5 = __toESM(require("path"));
|
|
627
697
|
var import_node_url = __toESM(require("url"));
|
|
698
|
+
var import_chalk = __toESM(require("chalk"));
|
|
699
|
+
var import_log_symbols2 = __toESM(require("log-symbols"));
|
|
628
700
|
var import_next = __toESM(require("next"));
|
|
629
701
|
var import_ora = __toESM(require("ora"));
|
|
630
|
-
|
|
631
|
-
var
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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);
|
|
702
|
+
// src/cli/utils/preview/get-env-variables-for-preview-app.ts
|
|
703
|
+
var import_node_path3 = __toESM(require("path"));
|
|
704
|
+
var getEnvVariablesForPreviewApp = function(relativePathToEmailsDirectory, cwd) {
|
|
705
|
+
return {
|
|
706
|
+
EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
|
|
707
|
+
EMAILS_DIR_ABSOLUTE_PATH: import_node_path3.default.resolve(cwd, relativePathToEmailsDirectory),
|
|
708
|
+
USER_PROJECT_LOCATION: cwd
|
|
709
|
+
};
|
|
655
710
|
};
|
|
656
711
|
// src/cli/utils/preview/serve-static-file.ts
|
|
657
|
-
var
|
|
658
|
-
var
|
|
712
|
+
var import_node_fs3 = require("fs");
|
|
713
|
+
var import_node_path4 = __toESM(require("path"));
|
|
659
714
|
var import_mime_types = require("mime-types");
|
|
660
715
|
var serveStaticFile = function() {
|
|
661
716
|
var _ref = _async_to_generator(function(res, parsedUrl, staticDirRelativePath) {
|
|
@@ -663,13 +718,13 @@ var serveStaticFile = function() {
|
|
|
663
718
|
return _ts_generator(this, function(_state) {
|
|
664
719
|
switch(_state.label){
|
|
665
720
|
case 0:
|
|
666
|
-
staticBaseDir =
|
|
721
|
+
staticBaseDir = import_node_path4.default.join(process.cwd(), staticDirRelativePath);
|
|
667
722
|
pathname = parsedUrl.pathname;
|
|
668
|
-
ext =
|
|
669
|
-
fileAbsolutePath =
|
|
723
|
+
ext = import_node_path4.default.parse(pathname).ext;
|
|
724
|
+
fileAbsolutePath = import_node_path4.default.join(staticBaseDir, pathname);
|
|
670
725
|
return [
|
|
671
726
|
4,
|
|
672
|
-
|
|
727
|
+
import_node_fs3.promises.open(fileAbsolutePath, "r")
|
|
673
728
|
];
|
|
674
729
|
case 1:
|
|
675
730
|
fileHandle = _state.sent();
|
|
@@ -683,7 +738,7 @@ var serveStaticFile = function() {
|
|
|
683
738
|
]);
|
|
684
739
|
return [
|
|
685
740
|
4,
|
|
686
|
-
|
|
741
|
+
import_node_fs3.promises.readFile(fileHandle)
|
|
687
742
|
];
|
|
688
743
|
case 3:
|
|
689
744
|
fileData = _state.sent();
|
|
@@ -718,15 +773,6 @@ var serveStaticFile = function() {
|
|
|
718
773
|
return _ref.apply(this, arguments);
|
|
719
774
|
};
|
|
720
775
|
}();
|
|
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
776
|
// src/cli/utils/preview/start-dev-server.ts
|
|
731
777
|
var devServer;
|
|
732
778
|
var safeAsyncServerListen = function(server, port) {
|
|
@@ -745,9 +791,9 @@ var safeAsyncServerListen = function(server, port) {
|
|
|
745
791
|
});
|
|
746
792
|
});
|
|
747
793
|
};
|
|
748
|
-
var isDev = !__filename.endsWith(
|
|
749
|
-
var cliPacakgeLocation = isDev ?
|
|
750
|
-
var previewServerLocation = isDev ?
|
|
794
|
+
var isDev = !__filename.endsWith(import_node_path5.default.join("cli", "index.js"));
|
|
795
|
+
var cliPacakgeLocation = isDev ? import_node_path5.default.resolve(__dirname, "../../../..") : import_node_path5.default.resolve(__dirname, "../..");
|
|
796
|
+
var previewServerLocation = isDev ? import_node_path5.default.resolve(__dirname, "../../../..") : import_node_path5.default.resolve(__dirname, "../preview");
|
|
751
797
|
var startDevServer = function() {
|
|
752
798
|
var _ref = _async_to_generator(function(emailsDirRelativePath, staticBaseDirRelativePath, port) {
|
|
753
799
|
var portAlreadyInUse, nextPortToTry, spinner, timeBeforeNextReady, app, isNextReady, nextReadyPromise, nextHandleRequest, secondsToNextReady;
|
|
@@ -764,7 +810,8 @@ var startDevServer = function() {
|
|
|
764
810
|
res.setHeader("Pragma", "no-cache");
|
|
765
811
|
res.setHeader("Expires", "-1");
|
|
766
812
|
try {
|
|
767
|
-
|
|
813
|
+
var _parsedUrl_path;
|
|
814
|
+
if (((_parsedUrl_path = parsedUrl.path) === null || _parsedUrl_path === void 0 ? void 0 : _parsedUrl_path.includes("static/")) && !parsedUrl.path.includes("_next/static/")) {
|
|
768
815
|
void serveStaticFile(res, parsedUrl, staticBaseDirRelativePath);
|
|
769
816
|
} else if (!isNextReady) {
|
|
770
817
|
void nextReadyPromise.then(function() {
|
|
@@ -825,7 +872,7 @@ var startDevServer = function() {
|
|
|
825
872
|
process.env = _object_spread(_object_spread_props(_object_spread({}, process.env), {
|
|
826
873
|
NODE_ENV: "development"
|
|
827
874
|
}), getEnvVariablesForPreviewApp(// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
|
|
828
|
-
|
|
875
|
+
import_node_path5.default.normalize(emailsDirRelativePath), process.cwd()));
|
|
829
876
|
app = (0, import_next.default)({
|
|
830
877
|
// passing in env here does not get the environment variables there
|
|
831
878
|
dev: isDev,
|
|
@@ -894,6 +941,50 @@ process.on("uncaughtException", makeExitHandler({
|
|
|
894
941
|
shouldKillProcess: true,
|
|
895
942
|
killWithErrorCode: true
|
|
896
943
|
}));
|
|
944
|
+
// src/cli/utils/preview/hot-reloading/get-imported-modules.ts
|
|
945
|
+
var import_parser = require("@babel/parser");
|
|
946
|
+
var import_traverse = __toESM(require("@babel/traverse"));
|
|
947
|
+
var getImportedModules = function(contents) {
|
|
948
|
+
var importedPaths = [];
|
|
949
|
+
var parsedContents = (0, import_parser.parse)(contents, {
|
|
950
|
+
sourceType: "unambiguous",
|
|
951
|
+
strictMode: false,
|
|
952
|
+
errorRecovery: true,
|
|
953
|
+
plugins: [
|
|
954
|
+
"jsx",
|
|
955
|
+
"typescript",
|
|
956
|
+
"decorators"
|
|
957
|
+
]
|
|
958
|
+
});
|
|
959
|
+
(0, import_traverse.default)(parsedContents, {
|
|
960
|
+
ImportDeclaration: function ImportDeclaration(param) {
|
|
961
|
+
var node = param.node;
|
|
962
|
+
importedPaths.push(node.source.value);
|
|
963
|
+
},
|
|
964
|
+
ExportAllDeclaration: function ExportAllDeclaration(param) {
|
|
965
|
+
var node = param.node;
|
|
966
|
+
importedPaths.push(node.source.value);
|
|
967
|
+
},
|
|
968
|
+
ExportNamedDeclaration: function ExportNamedDeclaration(param) {
|
|
969
|
+
var node = param.node;
|
|
970
|
+
if (node.source) {
|
|
971
|
+
importedPaths.push(node.source.value);
|
|
972
|
+
}
|
|
973
|
+
},
|
|
974
|
+
CallExpression: function CallExpression(param) {
|
|
975
|
+
var node = param.node;
|
|
976
|
+
if ("name" in node.callee && node.callee.name === "require") {
|
|
977
|
+
if (node.arguments.length === 1) {
|
|
978
|
+
var importPathNode = node.arguments[0];
|
|
979
|
+
if (importPathNode.type === "StringLiteral") {
|
|
980
|
+
importedPaths.push(importPathNode.value);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
return importedPaths;
|
|
987
|
+
};
|
|
897
988
|
// src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
898
989
|
var readAllFilesInsideDirectory = function() {
|
|
899
990
|
var _ref = _async_to_generator(function(directory) {
|
|
@@ -904,7 +995,7 @@ var readAllFilesInsideDirectory = function() {
|
|
|
904
995
|
allFilePaths = [];
|
|
905
996
|
return [
|
|
906
997
|
4,
|
|
907
|
-
|
|
998
|
+
import_node_fs4.promises.readdir(directory, {
|
|
908
999
|
withFileTypes: true
|
|
909
1000
|
})
|
|
910
1001
|
];
|
|
@@ -933,7 +1024,7 @@ var readAllFilesInsideDirectory = function() {
|
|
|
933
1024
|
];
|
|
934
1025
|
_value = _step.value;
|
|
935
1026
|
dirent = _value;
|
|
936
|
-
pathToDirent =
|
|
1027
|
+
pathToDirent = import_node_path6.default.join(directory, dirent.name);
|
|
937
1028
|
if (!dirent.isDirectory()) return [
|
|
938
1029
|
3,
|
|
939
1030
|
6
|
|
@@ -1020,7 +1111,7 @@ var readAllFilesInsideDirectory = function() {
|
|
|
1020
1111
|
};
|
|
1021
1112
|
}();
|
|
1022
1113
|
var isJavascriptModule = function(filePath) {
|
|
1023
|
-
var extensionName =
|
|
1114
|
+
var extensionName = import_node_path6.default.extname(filePath);
|
|
1024
1115
|
return [
|
|
1025
1116
|
".js",
|
|
1026
1117
|
".ts",
|
|
@@ -1031,22 +1122,22 @@ var isJavascriptModule = function(filePath) {
|
|
|
1031
1122
|
].includes(extensionName);
|
|
1032
1123
|
};
|
|
1033
1124
|
var checkFileExtensionsUntilItExists = function(pathWithoutExtension) {
|
|
1034
|
-
if ((0,
|
|
1125
|
+
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".ts"))) {
|
|
1035
1126
|
return "".concat(pathWithoutExtension, ".ts");
|
|
1036
1127
|
}
|
|
1037
|
-
if ((0,
|
|
1128
|
+
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".tsx"))) {
|
|
1038
1129
|
return "".concat(pathWithoutExtension, ".tsx");
|
|
1039
1130
|
}
|
|
1040
|
-
if ((0,
|
|
1131
|
+
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".js"))) {
|
|
1041
1132
|
return "".concat(pathWithoutExtension, ".js");
|
|
1042
1133
|
}
|
|
1043
|
-
if ((0,
|
|
1134
|
+
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".jsx"))) {
|
|
1044
1135
|
return "".concat(pathWithoutExtension, ".jsx");
|
|
1045
1136
|
}
|
|
1046
|
-
if ((0,
|
|
1137
|
+
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".mjs"))) {
|
|
1047
1138
|
return "".concat(pathWithoutExtension, ".mjs");
|
|
1048
1139
|
}
|
|
1049
|
-
if ((0,
|
|
1140
|
+
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".cjs"))) {
|
|
1050
1141
|
return "".concat(pathWithoutExtension, ".cjs");
|
|
1051
1142
|
}
|
|
1052
1143
|
};
|
|
@@ -1082,52 +1173,51 @@ var createDependencyGraph = function() {
|
|
|
1082
1173
|
case 0:
|
|
1083
1174
|
return [
|
|
1084
1175
|
4,
|
|
1085
|
-
|
|
1176
|
+
import_node_fs4.promises.readFile(filePath, "utf8")
|
|
1086
1177
|
];
|
|
1087
1178
|
case 1:
|
|
1088
1179
|
contents = _state.sent();
|
|
1089
1180
|
importedPaths = getImportedModules(contents);
|
|
1090
1181
|
importedPathsRelativeToDirectory = importedPaths.map(function(dependencyPath) {
|
|
1091
1182
|
var isModulePath = !dependencyPath.startsWith(".");
|
|
1092
|
-
if (
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1183
|
+
if (isModulePath || import_node_path6.default.isAbsolute(dependencyPath)) {
|
|
1184
|
+
return dependencyPath;
|
|
1185
|
+
}
|
|
1186
|
+
var pathToDependencyFromDirectory = import_node_path6.default.resolve(/*
|
|
1187
|
+
path.resolve resolves paths differently from what imports on javascript do.
|
|
1188
|
+
|
|
1189
|
+
So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependecy path of "./other-email"
|
|
1190
|
+
would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
|
|
1191
|
+
one the import is meant to go to
|
|
1192
|
+
*/ import_node_path6.default.dirname(filePath), dependencyPath);
|
|
1193
|
+
var isDirectory = false;
|
|
1194
|
+
try {
|
|
1195
|
+
isDirectory = (0, import_node_fs4.statSync)(pathToDependencyFromDirectory).isDirectory();
|
|
1196
|
+
} catch (_) {}
|
|
1197
|
+
if (isDirectory) {
|
|
1198
|
+
var pathToSubDirectory = pathToDependencyFromDirectory;
|
|
1199
|
+
var pathWithExtension = checkFileExtensionsUntilItExists("".concat(pathToSubDirectory, "/index"));
|
|
1200
|
+
if (pathWithExtension) {
|
|
1201
|
+
pathToDependencyFromDirectory = pathWithExtension;
|
|
1202
|
+
} else if (isDev) {
|
|
1203
|
+
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
1204
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1205
|
+
}
|
|
1206
|
+
if (!isJavascriptModule(pathToDependencyFromDirectory)) {
|
|
1207
|
+
var pathWithExtension1 = checkFileExtensionsUntilItExists(pathToDependencyFromDirectory);
|
|
1208
|
+
if (pathWithExtension1) {
|
|
1209
|
+
pathToDependencyFromDirectory = pathWithExtension1;
|
|
1210
|
+
} else if (isDev) {
|
|
1211
|
+
console.warn("Could not determine the file extension for the file at ".concat(pathToDependencyFromDirectory));
|
|
1120
1212
|
}
|
|
1121
|
-
return pathToDependencyFromDirectory;
|
|
1122
|
-
} else {
|
|
1123
|
-
return dependencyPath;
|
|
1124
1213
|
}
|
|
1214
|
+
return pathToDependencyFromDirectory;
|
|
1125
1215
|
});
|
|
1126
1216
|
moduleDependencies = importedPathsRelativeToDirectory.filter(function(dependencyPath) {
|
|
1127
|
-
return !dependencyPath.startsWith(".") && !
|
|
1217
|
+
return !dependencyPath.startsWith(".") && !import_node_path6.default.isAbsolute(dependencyPath);
|
|
1128
1218
|
});
|
|
1129
1219
|
nonNodeModuleImportPathsRelativeToDirectory = importedPathsRelativeToDirectory.filter(function(dependencyPath) {
|
|
1130
|
-
return dependencyPath.startsWith(".") ||
|
|
1220
|
+
return dependencyPath.startsWith(".") || import_node_path6.default.isAbsolute(dependencyPath);
|
|
1131
1221
|
});
|
|
1132
1222
|
return [
|
|
1133
1223
|
2,
|
|
@@ -1665,7 +1755,7 @@ var setupHotreloading = function() {
|
|
|
1665
1755
|
});
|
|
1666
1756
|
changes = [];
|
|
1667
1757
|
}, 150);
|
|
1668
|
-
absolutePathToEmailsDirectory =
|
|
1758
|
+
absolutePathToEmailsDirectory = import_node_path7.default.resolve(process.cwd(), emailDirRelativePath);
|
|
1669
1759
|
return [
|
|
1670
1760
|
4,
|
|
1671
1761
|
createDependencyGraph(absolutePathToEmailsDirectory)
|
|
@@ -1681,7 +1771,7 @@ var setupHotreloading = function() {
|
|
|
1681
1771
|
});
|
|
1682
1772
|
getFilesOutsideEmailsDirectory = function() {
|
|
1683
1773
|
return Object.keys(dependencyGraph).filter(function(p) {
|
|
1684
|
-
return
|
|
1774
|
+
return import_node_path7.default.relative(absolutePathToEmailsDirectory, p).startsWith("..");
|
|
1685
1775
|
});
|
|
1686
1776
|
};
|
|
1687
1777
|
filesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
@@ -1734,13 +1824,13 @@ var setupHotreloading = function() {
|
|
|
1734
1824
|
return _ts_generator(this, function(_state) {
|
|
1735
1825
|
switch(_state.label){
|
|
1736
1826
|
case 0:
|
|
1737
|
-
file = relativePathToChangeTarget.split(
|
|
1827
|
+
file = relativePathToChangeTarget.split(import_node_path7.default.sep);
|
|
1738
1828
|
if (file.length === 0) {
|
|
1739
1829
|
return [
|
|
1740
1830
|
2
|
|
1741
1831
|
];
|
|
1742
1832
|
}
|
|
1743
|
-
pathToChangeTarget =
|
|
1833
|
+
pathToChangeTarget = import_node_path7.default.resolve(absolutePathToEmailsDirectory, relativePathToChangeTarget);
|
|
1744
1834
|
return [
|
|
1745
1835
|
4,
|
|
1746
1836
|
updateDependencyGraph(event, pathToChangeTarget)
|
|
@@ -1803,7 +1893,7 @@ var setupHotreloading = function() {
|
|
|
1803
1893
|
dependentPath = _step2.value;
|
|
1804
1894
|
changes.push({
|
|
1805
1895
|
event: "change",
|
|
1806
|
-
filename:
|
|
1896
|
+
filename: import_node_path7.default.relative(absolutePathToEmailsDirectory, dependentPath)
|
|
1807
1897
|
});
|
|
1808
1898
|
}
|
|
1809
1899
|
} catch (err) {
|
|
@@ -1842,193 +1932,444 @@ var setupHotreloading = function() {
|
|
|
1842
1932
|
return _ref.apply(this, arguments);
|
|
1843
1933
|
};
|
|
1844
1934
|
}();
|
|
1845
|
-
// src/cli/commands/
|
|
1846
|
-
var
|
|
1847
|
-
|
|
1848
|
-
var
|
|
1849
|
-
|
|
1850
|
-
|
|
1935
|
+
// src/cli/commands/build.ts
|
|
1936
|
+
var buildPreviewApp = function(absoluteDirectory) {
|
|
1937
|
+
return new Promise(function(resolve, reject) {
|
|
1938
|
+
var nextBuild = (0, import_node_child_process.spawn)("npm", [
|
|
1939
|
+
"run",
|
|
1940
|
+
"build"
|
|
1941
|
+
], {
|
|
1942
|
+
cwd: absoluteDirectory,
|
|
1943
|
+
shell: true
|
|
1944
|
+
});
|
|
1945
|
+
nextBuild.stdout.pipe(process.stdout);
|
|
1946
|
+
nextBuild.stderr.pipe(process.stderr);
|
|
1947
|
+
nextBuild.on("close", function(code) {
|
|
1948
|
+
if (code === 0) {
|
|
1949
|
+
resolve();
|
|
1950
|
+
} else {
|
|
1951
|
+
reject(new Error("Unable to build the Next app and it exited with code: ".concat(code)));
|
|
1952
|
+
}
|
|
1953
|
+
});
|
|
1954
|
+
});
|
|
1955
|
+
};
|
|
1956
|
+
var setNextEnvironmentVariablesForBuild = function() {
|
|
1957
|
+
var _ref = _async_to_generator(function(emailsDirRelativePath, builtPreviewAppPath) {
|
|
1958
|
+
var nextConfigContents;
|
|
1959
|
+
return _ts_generator(this, function(_state) {
|
|
1960
|
+
switch(_state.label){
|
|
1851
1961
|
case 0:
|
|
1852
|
-
emailsDirRelativePath =
|
|
1853
|
-
|
|
1962
|
+
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}");
|
|
1963
|
+
return [
|
|
1964
|
+
4,
|
|
1965
|
+
import_node_fs5.default.promises.writeFile(import_node_path8.default.resolve(builtPreviewAppPath, "./next.config.js"), nextConfigContents, "utf8")
|
|
1966
|
+
];
|
|
1854
1967
|
case 1:
|
|
1855
|
-
_state.
|
|
1856
|
-
|
|
1968
|
+
_state.sent();
|
|
1969
|
+
return [
|
|
1970
|
+
2
|
|
1971
|
+
];
|
|
1972
|
+
}
|
|
1973
|
+
});
|
|
1974
|
+
});
|
|
1975
|
+
return function setNextEnvironmentVariablesForBuild(emailsDirRelativePath, builtPreviewAppPath) {
|
|
1976
|
+
return _ref.apply(this, arguments);
|
|
1977
|
+
};
|
|
1978
|
+
}();
|
|
1979
|
+
var getEmailSlugsFromEmailDirectory = function(emailDirectory, emailsDirectoryAbsolutePath) {
|
|
1980
|
+
var directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
|
|
1981
|
+
var slugs = [];
|
|
1982
|
+
emailDirectory.emailFilenames.forEach(function(filename) {
|
|
1983
|
+
return slugs.push(import_node_path8.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path8.default.sep).filter(function(segment) {
|
|
1984
|
+
return segment.length > 0;
|
|
1985
|
+
}));
|
|
1986
|
+
});
|
|
1987
|
+
emailDirectory.subDirectories.forEach(function(directory) {
|
|
1988
|
+
var _slugs;
|
|
1989
|
+
(_slugs = slugs).push.apply(_slugs, _to_consumable_array(getEmailSlugsFromEmailDirectory(directory, emailsDirectoryAbsolutePath)));
|
|
1990
|
+
});
|
|
1991
|
+
return slugs;
|
|
1992
|
+
};
|
|
1993
|
+
var forceSSGForEmailPreviews = function() {
|
|
1994
|
+
var _ref = _async_to_generator(function(emailsDirPath, builtPreviewAppPath) {
|
|
1995
|
+
var emailDirectoryMetadata, parameters, removeForceDynamic;
|
|
1996
|
+
return _ts_generator(this, function(_state) {
|
|
1997
|
+
switch(_state.label){
|
|
1998
|
+
case 0:
|
|
1999
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2000
|
+
return [
|
|
1857
2001
|
4,
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
2002
|
+
getEmailsDirectoryMetadata(emailsDirPath)
|
|
2003
|
+
];
|
|
2004
|
+
case 1:
|
|
2005
|
+
emailDirectoryMetadata = _state.sent();
|
|
2006
|
+
parameters = getEmailSlugsFromEmailDirectory(emailDirectoryMetadata, emailsDirPath).map(function(slug) {
|
|
2007
|
+
return {
|
|
2008
|
+
slug: slug
|
|
2009
|
+
};
|
|
2010
|
+
});
|
|
2011
|
+
removeForceDynamic = function() {
|
|
2012
|
+
var _ref = _async_to_generator(function(filePath) {
|
|
2013
|
+
var contents;
|
|
2014
|
+
return _ts_generator(this, function(_state) {
|
|
2015
|
+
switch(_state.label){
|
|
2016
|
+
case 0:
|
|
2017
|
+
return [
|
|
2018
|
+
4,
|
|
2019
|
+
import_node_fs5.default.promises.readFile(filePath, "utf8")
|
|
2020
|
+
];
|
|
2021
|
+
case 1:
|
|
2022
|
+
contents = _state.sent();
|
|
2023
|
+
return [
|
|
2024
|
+
4,
|
|
2025
|
+
import_node_fs5.default.promises.writeFile(filePath, contents.replace("export const dynamic = 'force-dynamic';", ""), "utf8")
|
|
2026
|
+
];
|
|
2027
|
+
case 2:
|
|
2028
|
+
_state.sent();
|
|
2029
|
+
return [
|
|
2030
|
+
2
|
|
2031
|
+
];
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
});
|
|
2035
|
+
return function removeForceDynamic(filePath) {
|
|
2036
|
+
return _ref.apply(this, arguments);
|
|
2037
|
+
};
|
|
2038
|
+
}();
|
|
1865
2039
|
return [
|
|
1866
2040
|
4,
|
|
1867
|
-
|
|
1868
|
-
Number.parseInt(port))
|
|
2041
|
+
removeForceDynamic(import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/layout.tsx"))
|
|
1869
2042
|
];
|
|
1870
2043
|
case 2:
|
|
1871
|
-
|
|
2044
|
+
_state.sent();
|
|
1872
2045
|
return [
|
|
1873
2046
|
4,
|
|
1874
|
-
|
|
2047
|
+
removeForceDynamic(import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"))
|
|
1875
2048
|
];
|
|
1876
2049
|
case 3:
|
|
1877
2050
|
_state.sent();
|
|
1878
2051
|
return [
|
|
1879
|
-
|
|
1880
|
-
|
|
2052
|
+
4,
|
|
2053
|
+
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
2054
|
];
|
|
1882
2055
|
case 4:
|
|
1883
|
-
|
|
1884
|
-
console.log(error);
|
|
1885
|
-
process.exit(1);
|
|
1886
|
-
return [
|
|
1887
|
-
3,
|
|
1888
|
-
5
|
|
1889
|
-
];
|
|
1890
|
-
case 5:
|
|
2056
|
+
_state.sent();
|
|
1891
2057
|
return [
|
|
1892
2058
|
2
|
|
1893
2059
|
];
|
|
1894
2060
|
}
|
|
1895
2061
|
});
|
|
1896
2062
|
});
|
|
1897
|
-
return function
|
|
2063
|
+
return function forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath) {
|
|
1898
2064
|
return _ref.apply(this, arguments);
|
|
1899
2065
|
};
|
|
1900
2066
|
}();
|
|
1901
|
-
|
|
1902
|
-
var
|
|
1903
|
-
var
|
|
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;
|
|
2067
|
+
var updatePackageJson = function() {
|
|
2068
|
+
var _ref = _async_to_generator(function(builtPreviewAppPath) {
|
|
2069
|
+
var packageJsonPath, packageJson, _;
|
|
1941
2070
|
return _ts_generator(this, function(_state) {
|
|
1942
2071
|
switch(_state.label){
|
|
1943
2072
|
case 0:
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
2
|
|
1947
|
-
];
|
|
2073
|
+
packageJsonPath = import_node_path8.default.resolve(builtPreviewAppPath, "./package.json");
|
|
2074
|
+
_ = JSON.parse;
|
|
1948
2075
|
return [
|
|
1949
2076
|
4,
|
|
1950
|
-
import_node_fs5.default.promises.
|
|
1951
|
-
withFileTypes: true
|
|
1952
|
-
})
|
|
2077
|
+
import_node_fs5.default.promises.readFile(packageJsonPath, "utf8")
|
|
1953
2078
|
];
|
|
1954
2079
|
case 1:
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2080
|
+
packageJson = _.apply(JSON, [
|
|
2081
|
+
_state.sent()
|
|
2082
|
+
]);
|
|
2083
|
+
packageJson.scripts.build = "next build";
|
|
2084
|
+
packageJson.scripts.start = "next start";
|
|
2085
|
+
packageJson.name = "preview-server";
|
|
2086
|
+
delete packageJson.devDependencies["@react-email/render"];
|
|
2087
|
+
delete packageJson.devDependencies["@react-email/components"];
|
|
1961
2088
|
return [
|
|
1962
2089
|
4,
|
|
1963
|
-
|
|
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
|
-
}))
|
|
2090
|
+
import_node_fs5.default.promises.writeFile(packageJsonPath, JSON.stringify(packageJson), "utf8")
|
|
1969
2091
|
];
|
|
1970
2092
|
case 2:
|
|
1971
|
-
|
|
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
|
-
};
|
|
2093
|
+
_state.sent();
|
|
1979
2094
|
return [
|
|
1980
|
-
2
|
|
1981
|
-
isSubDirectory ? mergeDirectoriesWithSubDirectories(emailsMetadata) : emailsMetadata
|
|
2095
|
+
2
|
|
1982
2096
|
];
|
|
1983
2097
|
}
|
|
1984
2098
|
});
|
|
1985
2099
|
});
|
|
1986
|
-
return function
|
|
2100
|
+
return function updatePackageJson(builtPreviewAppPath) {
|
|
1987
2101
|
return _ref.apply(this, arguments);
|
|
1988
2102
|
};
|
|
1989
2103
|
}();
|
|
1990
|
-
|
|
1991
|
-
var
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
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
|
-
];
|
|
2104
|
+
var npmInstall = function() {
|
|
2105
|
+
var _ref = _async_to_generator(function(builtPreviewAppPath, packageManager) {
|
|
2106
|
+
return _ts_generator(this, function(_state) {
|
|
2107
|
+
return [
|
|
2108
|
+
2,
|
|
2109
|
+
new Promise(function(resolve, reject) {
|
|
2110
|
+
var childProc = (0, import_node_child_process.spawn)(packageManager, [
|
|
2111
|
+
"install",
|
|
2112
|
+
"--silent",
|
|
2113
|
+
"--include=dev"
|
|
2114
|
+
], {
|
|
2115
|
+
cwd: builtPreviewAppPath,
|
|
2116
|
+
shell: true
|
|
2117
|
+
});
|
|
2118
|
+
childProc.stdout.pipe(process.stdout);
|
|
2119
|
+
childProc.stderr.pipe(process.stderr);
|
|
2120
|
+
childProc.on("close", function(code) {
|
|
2121
|
+
if (code === 0) {
|
|
2122
|
+
resolve();
|
|
2123
|
+
} else {
|
|
2124
|
+
reject(new Error("Unable to install the dependencies and it exited with code: ".concat(code)));
|
|
2027
2125
|
}
|
|
2028
2126
|
});
|
|
2029
|
-
})
|
|
2030
|
-
|
|
2031
|
-
|
|
2127
|
+
})
|
|
2128
|
+
];
|
|
2129
|
+
});
|
|
2130
|
+
});
|
|
2131
|
+
return function npmInstall(builtPreviewAppPath, packageManager) {
|
|
2132
|
+
return _ref.apply(this, arguments);
|
|
2133
|
+
};
|
|
2134
|
+
}();
|
|
2135
|
+
var build = function() {
|
|
2136
|
+
var _ref = _async_to_generator(function(param) {
|
|
2137
|
+
var emailsDirRelativePath, packageManager, spinner, emailsDirPath, staticPath, builtPreviewAppPath, builtStaticDirectory, error;
|
|
2138
|
+
return _ts_generator(this, function(_state) {
|
|
2139
|
+
switch(_state.label){
|
|
2140
|
+
case 0:
|
|
2141
|
+
emailsDirRelativePath = param.dir, packageManager = param.packageManager;
|
|
2142
|
+
_state.label = 1;
|
|
2143
|
+
case 1:
|
|
2144
|
+
_state.trys.push([
|
|
2145
|
+
1,
|
|
2146
|
+
12,
|
|
2147
|
+
,
|
|
2148
|
+
13
|
|
2149
|
+
]);
|
|
2150
|
+
spinner = (0, import_ora2.default)({
|
|
2151
|
+
text: "Starting build process...",
|
|
2152
|
+
prefixText: " "
|
|
2153
|
+
}).start();
|
|
2154
|
+
registerSpinnerAutostopping(spinner);
|
|
2155
|
+
spinner.text = "Checking if ".concat(emailsDirRelativePath, " folder exists");
|
|
2156
|
+
if (!import_node_fs5.default.existsSync(emailsDirRelativePath)) {
|
|
2157
|
+
process.exit(1);
|
|
2158
|
+
}
|
|
2159
|
+
emailsDirPath = import_node_path8.default.join(process.cwd(), emailsDirRelativePath);
|
|
2160
|
+
staticPath = import_node_path8.default.join(emailsDirPath, "static");
|
|
2161
|
+
builtPreviewAppPath = import_node_path8.default.join(process.cwd(), ".react-email");
|
|
2162
|
+
if (!import_node_fs5.default.existsSync(builtPreviewAppPath)) return [
|
|
2163
|
+
3,
|
|
2164
|
+
3
|
|
2165
|
+
];
|
|
2166
|
+
spinner.text = "Deleting pre-existing `.react-email` folder";
|
|
2167
|
+
return [
|
|
2168
|
+
4,
|
|
2169
|
+
import_node_fs5.default.promises.rm(builtPreviewAppPath, {
|
|
2170
|
+
recursive: true
|
|
2171
|
+
})
|
|
2172
|
+
];
|
|
2173
|
+
case 2:
|
|
2174
|
+
_state.sent();
|
|
2175
|
+
_state.label = 3;
|
|
2176
|
+
case 3:
|
|
2177
|
+
spinner.text = "Copying preview app from CLI to `.react-email`";
|
|
2178
|
+
return [
|
|
2179
|
+
4,
|
|
2180
|
+
import_node_fs5.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
|
|
2181
|
+
recursive: true,
|
|
2182
|
+
filter: function(source) {
|
|
2183
|
+
return !/(\/|\\)cli(\/|\\)?/.test(source) && !/(\/|\\)\.next(\/|\\)?/.test(source) && !/(\/|\\)\.turbo(\/|\\)?/.test(source) && !/(\/|\\)node_modules(\/|\\)?$/.test(source);
|
|
2184
|
+
}
|
|
2185
|
+
})
|
|
2186
|
+
];
|
|
2187
|
+
case 4:
|
|
2188
|
+
_state.sent();
|
|
2189
|
+
if (!import_node_fs5.default.existsSync(staticPath)) return [
|
|
2190
|
+
3,
|
|
2191
|
+
6
|
|
2192
|
+
];
|
|
2193
|
+
spinner.text = "Copying `static` folder into `.react-email/public/static`";
|
|
2194
|
+
builtStaticDirectory = import_node_path8.default.resolve(builtPreviewAppPath, "./public/static");
|
|
2195
|
+
return [
|
|
2196
|
+
4,
|
|
2197
|
+
import_node_fs5.default.promises.cp(staticPath, builtStaticDirectory, {
|
|
2198
|
+
recursive: true
|
|
2199
|
+
})
|
|
2200
|
+
];
|
|
2201
|
+
case 5:
|
|
2202
|
+
_state.sent();
|
|
2203
|
+
_state.label = 6;
|
|
2204
|
+
case 6:
|
|
2205
|
+
spinner.text = "Setting Next environment variables for preview app to work properly";
|
|
2206
|
+
return [
|
|
2207
|
+
4,
|
|
2208
|
+
setNextEnvironmentVariablesForBuild(emailsDirRelativePath, builtPreviewAppPath)
|
|
2209
|
+
];
|
|
2210
|
+
case 7:
|
|
2211
|
+
_state.sent();
|
|
2212
|
+
spinner.text = "Setting server side generation for the email preview pages";
|
|
2213
|
+
return [
|
|
2214
|
+
4,
|
|
2215
|
+
forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath)
|
|
2216
|
+
];
|
|
2217
|
+
case 8:
|
|
2218
|
+
_state.sent();
|
|
2219
|
+
spinner.text = "Updating package.json's build and start scripts";
|
|
2220
|
+
return [
|
|
2221
|
+
4,
|
|
2222
|
+
updatePackageJson(builtPreviewAppPath)
|
|
2223
|
+
];
|
|
2224
|
+
case 9:
|
|
2225
|
+
_state.sent();
|
|
2226
|
+
spinner.text = "Installing dependencies on `.react-email`";
|
|
2227
|
+
return [
|
|
2228
|
+
4,
|
|
2229
|
+
npmInstall(builtPreviewAppPath, packageManager)
|
|
2230
|
+
];
|
|
2231
|
+
case 10:
|
|
2232
|
+
_state.sent();
|
|
2233
|
+
spinner.stopAndPersist({
|
|
2234
|
+
text: "Successfully prepared `.react-email` for `next build`",
|
|
2235
|
+
symbol: import_log_symbols3.default.success
|
|
2236
|
+
});
|
|
2237
|
+
return [
|
|
2238
|
+
4,
|
|
2239
|
+
buildPreviewApp(builtPreviewAppPath)
|
|
2240
|
+
];
|
|
2241
|
+
case 11:
|
|
2242
|
+
_state.sent();
|
|
2243
|
+
return [
|
|
2244
|
+
3,
|
|
2245
|
+
13
|
|
2246
|
+
];
|
|
2247
|
+
case 12:
|
|
2248
|
+
error = _state.sent();
|
|
2249
|
+
console.log(error);
|
|
2250
|
+
process.exit(1);
|
|
2251
|
+
return [
|
|
2252
|
+
3,
|
|
2253
|
+
13
|
|
2254
|
+
];
|
|
2255
|
+
case 13:
|
|
2256
|
+
return [
|
|
2257
|
+
2
|
|
2258
|
+
];
|
|
2259
|
+
}
|
|
2260
|
+
});
|
|
2261
|
+
});
|
|
2262
|
+
return function build(_) {
|
|
2263
|
+
return _ref.apply(this, arguments);
|
|
2264
|
+
};
|
|
2265
|
+
}();
|
|
2266
|
+
// src/cli/commands/dev.ts
|
|
2267
|
+
var import_node_fs6 = __toESM(require("fs"));
|
|
2268
|
+
var dev = function() {
|
|
2269
|
+
var _ref = _async_to_generator(function(param) {
|
|
2270
|
+
var emailsDirRelativePath, port, devServer2, error;
|
|
2271
|
+
return _ts_generator(this, function(_state) {
|
|
2272
|
+
switch(_state.label){
|
|
2273
|
+
case 0:
|
|
2274
|
+
emailsDirRelativePath = param.dir, port = param.port;
|
|
2275
|
+
_state.label = 1;
|
|
2276
|
+
case 1:
|
|
2277
|
+
_state.trys.push([
|
|
2278
|
+
1,
|
|
2279
|
+
4,
|
|
2280
|
+
,
|
|
2281
|
+
5
|
|
2282
|
+
]);
|
|
2283
|
+
if (!import_node_fs6.default.existsSync(emailsDirRelativePath)) {
|
|
2284
|
+
console.error("Missing ".concat(emailsDirRelativePath, " folder"));
|
|
2285
|
+
process.exit(1);
|
|
2286
|
+
}
|
|
2287
|
+
return [
|
|
2288
|
+
4,
|
|
2289
|
+
startDevServer(emailsDirRelativePath, emailsDirRelativePath, // defaults to ./emails/static for the static files that are served to the preview
|
|
2290
|
+
Number.parseInt(port))
|
|
2291
|
+
];
|
|
2292
|
+
case 2:
|
|
2293
|
+
devServer2 = _state.sent();
|
|
2294
|
+
return [
|
|
2295
|
+
4,
|
|
2296
|
+
setupHotreloading(devServer2, emailsDirRelativePath)
|
|
2297
|
+
];
|
|
2298
|
+
case 3:
|
|
2299
|
+
_state.sent();
|
|
2300
|
+
return [
|
|
2301
|
+
3,
|
|
2302
|
+
5
|
|
2303
|
+
];
|
|
2304
|
+
case 4:
|
|
2305
|
+
error = _state.sent();
|
|
2306
|
+
console.log(error);
|
|
2307
|
+
process.exit(1);
|
|
2308
|
+
return [
|
|
2309
|
+
3,
|
|
2310
|
+
5
|
|
2311
|
+
];
|
|
2312
|
+
case 5:
|
|
2313
|
+
return [
|
|
2314
|
+
2
|
|
2315
|
+
];
|
|
2316
|
+
}
|
|
2317
|
+
});
|
|
2318
|
+
});
|
|
2319
|
+
return function dev(_) {
|
|
2320
|
+
return _ref.apply(this, arguments);
|
|
2321
|
+
};
|
|
2322
|
+
}();
|
|
2323
|
+
// src/cli/commands/export.ts
|
|
2324
|
+
var import_node_fs8 = __toESM(require("fs"));
|
|
2325
|
+
var import_node_path10 = __toESM(require("path"));
|
|
2326
|
+
var import_esbuild = require("esbuild");
|
|
2327
|
+
var import_glob = require("glob");
|
|
2328
|
+
var import_log_symbols4 = __toESM(require("log-symbols"));
|
|
2329
|
+
var import_normalize_path = __toESM(require("normalize-path"));
|
|
2330
|
+
var import_ora3 = __toESM(require("ora"));
|
|
2331
|
+
// src/utils/esbuild/renderring-utilities-exporter.ts
|
|
2332
|
+
var import_node_fs7 = require("fs");
|
|
2333
|
+
var import_node_path9 = __toESM(require("path"));
|
|
2334
|
+
// src/utils/esbuild/escape-string-for-regex.ts
|
|
2335
|
+
function escapeStringForRegex(string) {
|
|
2336
|
+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
2337
|
+
}
|
|
2338
|
+
// src/utils/esbuild/renderring-utilities-exporter.ts
|
|
2339
|
+
var renderingUtilitiesExporter = function(emailTemplates) {
|
|
2340
|
+
return {
|
|
2341
|
+
name: "rendering-utilities-exporter",
|
|
2342
|
+
setup: function(b) {
|
|
2343
|
+
b.onLoad({
|
|
2344
|
+
filter: new RegExp(emailTemplates.map(function(emailPath) {
|
|
2345
|
+
return escapeStringForRegex(emailPath);
|
|
2346
|
+
}).join("|"))
|
|
2347
|
+
}, function() {
|
|
2348
|
+
var _ref = _async_to_generator(function(param) {
|
|
2349
|
+
var pathToFile, _tmp, _, _1;
|
|
2350
|
+
return _ts_generator(this, function(_state) {
|
|
2351
|
+
switch(_state.label){
|
|
2352
|
+
case 0:
|
|
2353
|
+
pathToFile = param.path;
|
|
2354
|
+
_tmp = {};
|
|
2355
|
+
_1 = (_ = "").concat;
|
|
2356
|
+
return [
|
|
2357
|
+
4,
|
|
2358
|
+
import_node_fs7.promises.readFile(pathToFile, "utf8")
|
|
2359
|
+
];
|
|
2360
|
+
case 1:
|
|
2361
|
+
return [
|
|
2362
|
+
2,
|
|
2363
|
+
(_tmp.contents = _1.apply(_, [
|
|
2364
|
+
_state.sent(),
|
|
2365
|
+
";\n export { render } from 'react-email-module-that-will-export-render'\n export { createElement as reactEmailCreateReactElement } from 'react';\n "
|
|
2366
|
+
]), _tmp.loader = import_node_path9.default.extname(pathToFile).slice(1), _tmp)
|
|
2367
|
+
];
|
|
2368
|
+
}
|
|
2369
|
+
});
|
|
2370
|
+
});
|
|
2371
|
+
return function(_) {
|
|
2372
|
+
return _ref.apply(this, arguments);
|
|
2032
2373
|
};
|
|
2033
2374
|
}());
|
|
2034
2375
|
b.onResolve({
|
|
@@ -2084,7 +2425,7 @@ var renderingUtilitiesExporter = function(emailTemplates) {
|
|
|
2084
2425
|
var getEmailTemplatesFromDirectory = function(emailDirectory) {
|
|
2085
2426
|
var templatePaths = [];
|
|
2086
2427
|
emailDirectory.emailFilenames.forEach(function(filename) {
|
|
2087
|
-
return templatePaths.push(
|
|
2428
|
+
return templatePaths.push(import_node_path10.default.join(emailDirectory.absolutePath, filename));
|
|
2088
2429
|
});
|
|
2089
2430
|
emailDirectory.subDirectories.forEach(function(directory) {
|
|
2090
2431
|
var _templatePaths;
|
|
@@ -2098,25 +2439,25 @@ var exportTemplates = function() {
|
|
|
2098
2439
|
return _ts_generator(this, function(_state) {
|
|
2099
2440
|
switch(_state.label){
|
|
2100
2441
|
case 0:
|
|
2101
|
-
if (
|
|
2102
|
-
|
|
2442
|
+
if (import_node_fs8.default.existsSync(pathToWhereEmailMarkupShouldBeDumped)) {
|
|
2443
|
+
import_node_fs8.default.rmSync(pathToWhereEmailMarkupShouldBeDumped, {
|
|
2103
2444
|
recursive: true
|
|
2104
2445
|
});
|
|
2105
2446
|
}
|
|
2106
2447
|
if (!options.silent) {
|
|
2107
|
-
spinner = (0,
|
|
2448
|
+
spinner = (0, import_ora3.default)("Preparing files...\n").start();
|
|
2108
2449
|
registerSpinnerAutostopping(spinner);
|
|
2109
2450
|
}
|
|
2110
2451
|
return [
|
|
2111
2452
|
4,
|
|
2112
|
-
getEmailsDirectoryMetadata(
|
|
2453
|
+
getEmailsDirectoryMetadata(import_node_path10.default.resolve(process.cwd(), emailsDirectoryPath), true)
|
|
2113
2454
|
];
|
|
2114
2455
|
case 1:
|
|
2115
2456
|
emailsDirectoryMetadata = _state.sent();
|
|
2116
2457
|
if (typeof emailsDirectoryMetadata === "undefined") {
|
|
2117
2458
|
if (spinner) {
|
|
2118
2459
|
spinner.stopAndPersist({
|
|
2119
|
-
symbol:
|
|
2460
|
+
symbol: import_log_symbols4.default.error,
|
|
2120
2461
|
text: "Could not find the directory at ".concat(emailsDirectoryPath)
|
|
2121
2462
|
});
|
|
2122
2463
|
}
|
|
@@ -2165,7 +2506,7 @@ var exportTemplates = function() {
|
|
|
2165
2506
|
buildFailure = exception;
|
|
2166
2507
|
if (spinner) {
|
|
2167
2508
|
spinner.stopAndPersist({
|
|
2168
|
-
symbol:
|
|
2509
|
+
symbol: import_log_symbols4.default.error,
|
|
2169
2510
|
text: "Failed to build emails"
|
|
2170
2511
|
});
|
|
2171
2512
|
}
|
|
@@ -2213,519 +2554,183 @@ var exportTemplates = function() {
|
|
|
2213
2554
|
12
|
|
2214
2555
|
]);
|
|
2215
2556
|
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();
|
|
2557
|
+
spinner.text = "rendering ".concat(template.split("/").pop());
|
|
2558
|
+
spinner.render();
|
|
2559
|
+
}
|
|
2560
|
+
delete require.cache[template];
|
|
2561
|
+
emailModule = require(template);
|
|
2504
2562
|
return [
|
|
2505
2563
|
4,
|
|
2506
|
-
|
|
2564
|
+
emailModule.render(emailModule.reactEmailCreateReactElement(emailModule.default, {}), options)
|
|
2507
2565
|
];
|
|
2508
|
-
case
|
|
2509
|
-
_state.sent();
|
|
2566
|
+
case 10:
|
|
2567
|
+
rendered = _state.sent();
|
|
2568
|
+
htmlPath = template.replace(".cjs", options.plainText ? ".txt" : ".html");
|
|
2569
|
+
(0, import_node_fs8.writeFileSync)(htmlPath, rendered);
|
|
2570
|
+
(0, import_node_fs8.unlinkSync)(template);
|
|
2510
2571
|
return [
|
|
2511
|
-
|
|
2512
|
-
|
|
2572
|
+
3,
|
|
2573
|
+
12
|
|
2513
2574
|
];
|
|
2514
|
-
case
|
|
2515
|
-
_state.sent();
|
|
2575
|
+
case 11:
|
|
2576
|
+
exception1 = _state.sent();
|
|
2577
|
+
if (spinner) {
|
|
2578
|
+
spinner.stopAndPersist({
|
|
2579
|
+
symbol: import_log_symbols4.default.error,
|
|
2580
|
+
text: "failed when rendering ".concat(template.split("/").pop())
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
console.error(exception1);
|
|
2584
|
+
process.exit(1);
|
|
2516
2585
|
return [
|
|
2517
|
-
|
|
2586
|
+
3,
|
|
2587
|
+
12
|
|
2518
2588
|
];
|
|
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;
|
|
2589
|
+
case 12:
|
|
2590
|
+
_iteratorAbruptCompletion = false;
|
|
2534
2591
|
return [
|
|
2535
|
-
|
|
2536
|
-
|
|
2592
|
+
3,
|
|
2593
|
+
7
|
|
2537
2594
|
];
|
|
2538
|
-
case
|
|
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"];
|
|
2595
|
+
case 13:
|
|
2547
2596
|
return [
|
|
2548
|
-
|
|
2549
|
-
|
|
2597
|
+
3,
|
|
2598
|
+
20
|
|
2550
2599
|
];
|
|
2551
|
-
case
|
|
2552
|
-
_state.sent();
|
|
2600
|
+
case 14:
|
|
2601
|
+
err = _state.sent();
|
|
2602
|
+
_didIteratorError = true;
|
|
2603
|
+
_iteratorError = err;
|
|
2553
2604
|
return [
|
|
2554
|
-
|
|
2605
|
+
3,
|
|
2606
|
+
20
|
|
2555
2607
|
];
|
|
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:
|
|
2608
|
+
case 15:
|
|
2603
2609
|
_state.trys.push([
|
|
2604
|
-
|
|
2605
|
-
12,
|
|
2610
|
+
15,
|
|
2606
2611
|
,
|
|
2607
|
-
|
|
2612
|
+
18,
|
|
2613
|
+
19
|
|
2608
2614
|
]);
|
|
2609
|
-
|
|
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 [
|
|
2615
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
2622
2616
|
3,
|
|
2623
|
-
|
|
2617
|
+
17
|
|
2624
2618
|
];
|
|
2625
|
-
spinner.text = "Deleting pre-existing `.react-email` folder";
|
|
2626
2619
|
return [
|
|
2627
2620
|
4,
|
|
2628
|
-
|
|
2629
|
-
recursive: true
|
|
2630
|
-
})
|
|
2621
|
+
_iterator.return()
|
|
2631
2622
|
];
|
|
2632
|
-
case
|
|
2623
|
+
case 16:
|
|
2633
2624
|
_state.sent();
|
|
2634
|
-
_state.label =
|
|
2635
|
-
case
|
|
2636
|
-
spinner.text = "Copying preview app from CLI to `.react-email`";
|
|
2625
|
+
_state.label = 17;
|
|
2626
|
+
case 17:
|
|
2637
2627
|
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
2628
|
3,
|
|
2650
|
-
|
|
2629
|
+
19
|
|
2651
2630
|
];
|
|
2652
|
-
|
|
2653
|
-
|
|
2631
|
+
case 18:
|
|
2632
|
+
if (_didIteratorError) {
|
|
2633
|
+
throw _iteratorError;
|
|
2634
|
+
}
|
|
2654
2635
|
return [
|
|
2655
|
-
|
|
2656
|
-
import_node_fs8.default.promises.cp(staticPath, builtStaticDirectory, {
|
|
2657
|
-
recursive: true
|
|
2658
|
-
})
|
|
2636
|
+
7
|
|
2659
2637
|
];
|
|
2660
|
-
case
|
|
2661
|
-
_state.sent();
|
|
2662
|
-
_state.label = 6;
|
|
2663
|
-
case 6:
|
|
2664
|
-
spinner.text = "Setting Next environment variables for preview app to work properly";
|
|
2638
|
+
case 19:
|
|
2665
2639
|
return [
|
|
2666
|
-
|
|
2667
|
-
setNextEnvironmentVariablesForBuild(emailsDirRelativePath, builtPreviewAppPath)
|
|
2640
|
+
7
|
|
2668
2641
|
];
|
|
2669
|
-
case
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2642
|
+
case 20:
|
|
2643
|
+
if (spinner) {
|
|
2644
|
+
spinner.succeed("Rendered all files");
|
|
2645
|
+
spinner.text = "Copying static files";
|
|
2646
|
+
spinner.render();
|
|
2647
|
+
}
|
|
2648
|
+
staticDirectoryPath = import_node_path10.default.join(emailsDirectoryPath, "static");
|
|
2649
|
+
if (!import_node_fs8.default.existsSync(staticDirectoryPath)) return [
|
|
2650
|
+
3,
|
|
2651
|
+
25
|
|
2675
2652
|
];
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
4,
|
|
2681
|
-
updatePackageJson(builtPreviewAppPath)
|
|
2653
|
+
pathToDumpStaticFilesInto = import_node_path10.default.join(pathToWhereEmailMarkupShouldBeDumped, "static");
|
|
2654
|
+
if (!import_node_fs8.default.existsSync(pathToDumpStaticFilesInto)) return [
|
|
2655
|
+
3,
|
|
2656
|
+
22
|
|
2682
2657
|
];
|
|
2683
|
-
case 9:
|
|
2684
|
-
_state.sent();
|
|
2685
|
-
spinner.text = "Installing dependencies on `.react-email`";
|
|
2686
2658
|
return [
|
|
2687
2659
|
4,
|
|
2688
|
-
|
|
2660
|
+
import_node_fs8.default.promises.rm(pathToDumpStaticFilesInto, {
|
|
2661
|
+
recursive: true
|
|
2662
|
+
})
|
|
2689
2663
|
];
|
|
2690
|
-
case
|
|
2664
|
+
case 21:
|
|
2691
2665
|
_state.sent();
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2666
|
+
_state.label = 22;
|
|
2667
|
+
case 22:
|
|
2668
|
+
_state.trys.push([
|
|
2669
|
+
22,
|
|
2670
|
+
24,
|
|
2671
|
+
,
|
|
2672
|
+
25
|
|
2673
|
+
]);
|
|
2696
2674
|
return [
|
|
2697
2675
|
4,
|
|
2698
|
-
|
|
2676
|
+
import_node_fs8.default.promises.cp(staticDirectoryPath, pathToDumpStaticFilesInto, {
|
|
2677
|
+
recursive: true
|
|
2678
|
+
})
|
|
2699
2679
|
];
|
|
2700
|
-
case
|
|
2680
|
+
case 23:
|
|
2701
2681
|
_state.sent();
|
|
2702
2682
|
return [
|
|
2703
2683
|
3,
|
|
2704
|
-
|
|
2684
|
+
25
|
|
2705
2685
|
];
|
|
2706
|
-
case
|
|
2707
|
-
|
|
2708
|
-
console.
|
|
2686
|
+
case 24:
|
|
2687
|
+
exception2 = _state.sent();
|
|
2688
|
+
console.error(exception2);
|
|
2689
|
+
if (spinner) {
|
|
2690
|
+
spinner.stopAndPersist({
|
|
2691
|
+
symbol: import_log_symbols4.default.error,
|
|
2692
|
+
text: "Failed to copy static files"
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
console.error("Something went wrong while copying the file to ".concat(pathToWhereEmailMarkupShouldBeDumped, "/static, ").concat(exception2));
|
|
2709
2696
|
process.exit(1);
|
|
2710
2697
|
return [
|
|
2711
2698
|
3,
|
|
2712
|
-
|
|
2699
|
+
25
|
|
2713
2700
|
];
|
|
2714
|
-
case
|
|
2701
|
+
case 25:
|
|
2702
|
+
if (!(spinner && !options.silent)) return [
|
|
2703
|
+
3,
|
|
2704
|
+
27
|
|
2705
|
+
];
|
|
2706
|
+
spinner.succeed();
|
|
2707
|
+
return [
|
|
2708
|
+
4,
|
|
2709
|
+
tree(pathToWhereEmailMarkupShouldBeDumped, 4)
|
|
2710
|
+
];
|
|
2711
|
+
case 26:
|
|
2712
|
+
fileTree = _state.sent();
|
|
2713
|
+
console.log(fileTree);
|
|
2714
|
+
spinner.stopAndPersist({
|
|
2715
|
+
symbol: import_log_symbols4.default.success,
|
|
2716
|
+
text: "Successfully exported emails"
|
|
2717
|
+
});
|
|
2718
|
+
_state.label = 27;
|
|
2719
|
+
case 27:
|
|
2715
2720
|
return [
|
|
2716
2721
|
2
|
|
2717
2722
|
];
|
|
2718
2723
|
}
|
|
2719
2724
|
});
|
|
2720
2725
|
});
|
|
2721
|
-
return function
|
|
2726
|
+
return function exportTemplates(pathToWhereEmailMarkupShouldBeDumped, emailsDirectoryPath, options) {
|
|
2722
2727
|
return _ref.apply(this, arguments);
|
|
2723
2728
|
};
|
|
2724
2729
|
}();
|
|
2725
2730
|
// src/cli/commands/start.ts
|
|
2731
|
+
var import_node_child_process2 = require("child_process");
|
|
2726
2732
|
var import_node_fs9 = __toESM(require("fs"));
|
|
2727
2733
|
var import_node_path11 = __toESM(require("path"));
|
|
2728
|
-
var import_node_child_process2 = require("child_process");
|
|
2729
2734
|
var start = function() {
|
|
2730
2735
|
var _ref = _async_to_generator(function() {
|
|
2731
2736
|
var usersProjectLocation, builtPreviewPath, nextStart;
|
|
@@ -2766,7 +2771,7 @@ var start = function() {
|
|
|
2766
2771
|
var PACKAGE_NAME = "react-email";
|
|
2767
2772
|
import_commander.program.name(PACKAGE_NAME).description("A live preview of your emails right in your browser").version(package_default.version);
|
|
2768
2773
|
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(
|
|
2774
|
+
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
2775
|
import_commander.program.command("start").description('Runs the built preview app that is inside of ".react-email"').action(start);
|
|
2771
2776
|
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
2777
|
var outDir = param.outDir, pretty = param.pretty, plainText = param.plainText, silent = param.silent, srcDir = param.dir;
|