react-email 4.0.0-alpha.5 → 4.0.0-alpha.7
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 +12 -0
- package/dist/cli/index.js +1179 -2659
- package/dist/cli/index.mjs +17 -11
- package/dist/preview/.next/BUILD_ID +1 -1
- package/dist/preview/.next/app-build-manifest.json +32 -31
- package/dist/preview/.next/app-path-routes-manifest.json +6 -1
- package/dist/preview/.next/build-manifest.json +14 -14
- 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/diagnostics/framework.json +1 -1
- package/dist/preview/.next/export-marker.json +6 -1
- package/dist/preview/.next/images-manifest.json +57 -1
- 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 +41 -1
- package/dist/preview/.next/required-server-files.json +310 -1
- package/dist/preview/.next/routes-manifest.json +64 -1
- package/dist/preview/.next/server/app/_not-found/page.js +1 -1
- package/dist/preview/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/app/favicon.ico/route.js +1 -1
- package/dist/preview/.next/server/app/favicon.ico/route.js.nft.json +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 +51 -11
- 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/app-paths-manifest.json +1 -1
- package/dist/preview/.next/server/chunks/446.js +6 -0
- package/dist/preview/.next/server/chunks/600.js +8 -0
- package/dist/preview/.next/server/chunks/811.js +13 -0
- package/dist/preview/.next/server/chunks/816.js +14 -0
- package/dist/preview/.next/server/chunks/943.js +1 -0
- package/dist/preview/.next/server/functions-config-manifest.json +4 -1
- package/dist/preview/.next/server/middleware-build-manifest.js +1 -1
- package/dist/preview/.next/server/next-font-manifest.js +1 -1
- package/dist/preview/.next/server/next-font-manifest.json +1 -1
- package/dist/preview/.next/server/pages/500.html +1 -1
- package/dist/preview/.next/server/pages/_app.js +1 -1
- package/dist/preview/.next/server/pages/_app.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/_document.js +1 -1
- package/dist/preview/.next/server/pages/_document.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/_error.js +1 -1
- package/dist/preview/.next/server/pages/_error.js.nft.json +1 -1
- package/dist/preview/.next/server/pages-manifest.json +5 -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/Pms2orsQgT5xpttCfZfH5/_buildManifest.js +1 -0
- package/dist/preview/.next/static/chunks/287-7864b805e6bdc854.js +1 -0
- package/dist/preview/.next/static/chunks/412-31817e53b50a3e73.js +1 -0
- package/dist/preview/.next/static/chunks/683-1fb40795502f6e63.js +1 -0
- package/dist/preview/.next/static/chunks/744-79730358b37b2212.js +1 -0
- package/dist/preview/.next/static/chunks/781-5f16c6bc9d9d4cc1.js +1 -0
- package/dist/preview/.next/static/chunks/832ad4be-cb988facfb8f955f.js +1 -0
- package/dist/preview/.next/static/chunks/880-9c0b721328117b8b.js +1 -0
- package/dist/preview/.next/static/chunks/{afa401a5-a600c227dacf3ab4.js → afa401a5-3e949a1cfd317dd3.js} +3 -3
- package/dist/preview/.next/static/chunks/app/_not-found/page-09d694081cc9d4dc.js +1 -0
- package/dist/preview/.next/static/chunks/app/layout-ffdee5cc1be30e7b.js +1 -0
- package/dist/preview/.next/static/chunks/app/page-9ea0bd45cd6294b0.js +1 -0
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-9e22979a25c836c0.js +1 -0
- package/dist/preview/.next/static/chunks/framework-c2bd6d936e3077bc.js +1 -0
- package/dist/preview/.next/static/chunks/main-44463a8301435b64.js +1 -0
- package/dist/preview/.next/static/chunks/main-app-256b213b179a95cc.js +1 -0
- package/dist/preview/.next/static/chunks/pages/_app-f3011d3f00bb8dba.js +1 -0
- package/dist/preview/.next/static/chunks/pages/_error-39a87dee2e97a2a3.js +1 -0
- package/dist/preview/.next/static/chunks/{webpack-2eb145a20ee6cb77.js → webpack-41e2667c9f086a4f.js} +1 -1
- package/dist/preview/.next/static/css/eaae8ce545b295f9.css +3 -0
- package/dist/preview/.next/trace +26 -22
- package/dist/preview/.next/types/app/layout.ts +1 -1
- package/dist/preview/.next/types/app/page.ts +84 -0
- package/dist/preview/.next/types/app/preview/[...slug]/page.ts +1 -1
- package/dist/preview/.next/types/cache-life.d.ts +3 -3
- package/package.json +14 -9
- package/scripts/build-preview-server.mjs +32 -0
- package/scripts/fill-caniemail-data.mjs +36 -0
- package/src/actions/email-validation/caniemail-data.ts +85993 -0
- package/src/actions/email-validation/check-compatibility.ts +321 -0
- package/src/actions/email-validation/check-images.spec.tsx +15 -13
- package/src/actions/email-validation/check-images.ts +8 -2
- package/src/actions/email-validation/check-links.spec.tsx +27 -15
- package/src/actions/email-validation/check-links.ts +8 -2
- package/src/actions/email-validation/get-code-location-from-ast-element.ts +18 -0
- package/src/actions/get-email-path-from-slug.ts +1 -1
- package/src/actions/render-email-by-path.tsx +2 -1
- package/src/{utils/emails-directory-absolute-path.ts → app/env.ts} +5 -0
- package/src/app/layout.tsx +1 -1
- package/src/app/page.tsx +1 -1
- package/src/app/preview/[...slug]/page.tsx +89 -19
- package/src/app/preview/[...slug]/preview.tsx +25 -68
- package/src/components/code-container.tsx +90 -71
- package/src/components/code.tsx +106 -43
- package/src/components/icons/icon-info.tsx +18 -0
- package/src/components/icons/icon-reload.tsx +13 -14
- package/src/components/logo.tsx +3 -2
- package/src/components/resizable-wrapper.tsx +1 -4
- package/src/components/sidebar/file-tree-directory-children.tsx +1 -0
- package/src/components/sidebar/sidebar.tsx +2 -3
- package/src/components/toolbar/code-preview-line-link.tsx +40 -0
- package/src/components/toolbar/compatibility.tsx +113 -0
- package/src/components/toolbar/linter.tsx +226 -125
- package/src/components/toolbar/results.tsx +5 -2
- package/src/components/toolbar/spam-assassin.tsx +40 -43
- package/src/components/toolbar/toolbar-button.tsx +52 -0
- package/src/components/toolbar/use-cached-state.ts +33 -0
- package/src/components/toolbar.tsx +196 -110
- package/src/components/tooltip-content.tsx +1 -1
- package/src/components/topbar/view-size-controls.tsx +1 -1
- package/src/components/topbar.tsx +4 -29
- package/src/contexts/emails.tsx +2 -1
- package/src/contexts/fragment-identifier.tsx +46 -0
- package/src/contexts/preview.tsx +81 -0
- package/src/hooks/use-email-rendering-result.ts +2 -1
- package/src/hooks/use-fragment-identifier.ts +14 -0
- package/src/utils/__snapshots__/get-email-component.spec.ts.snap +1 -1
- package/src/utils/caniemail/all-css-properties.ts +358 -0
- package/src/utils/caniemail/ast/get-object-variables.ts +61 -0
- package/src/utils/caniemail/ast/get-used-style-properties.ts +91 -0
- package/src/utils/caniemail/get-compatibility-stats-for-entry.ts +118 -0
- package/src/utils/caniemail/get-css-functions.ts +25 -0
- package/src/utils/caniemail/get-css-property-names.ts +32 -0
- package/src/utils/caniemail/get-css-property-with-value.ts +14 -0
- package/src/utils/caniemail/get-css-unit.ts +3 -0
- package/src/utils/caniemail/get-element-attributes.ts +7 -0
- package/src/utils/caniemail/get-element-names.ts +20 -0
- package/src/utils/caniemail/tailwind/generate-tailwind-rules.ts +30 -0
- package/src/utils/caniemail/tailwind/get-tailwind-config.ts +203 -0
- package/src/utils/caniemail/tailwind/get-tailwind-metadata.spec.ts +25 -0
- package/src/utils/caniemail/tailwind/get-tailwind-metadata.ts +45 -0
- package/src/utils/caniemail/tailwind/setup-tailwind-context.ts +15 -0
- package/src/utils/get-email-component.ts +34 -67
- package/src/utils/get-line-and-column-from-offset.spec.ts +11 -0
- package/src/utils/get-line-and-column-from-offset.ts +11 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/linting.ts +60 -0
- package/src/utils/load-stream.ts +15 -0
- package/src/utils/result.ts +49 -0
- package/src/utils/run-bundled-code.ts +64 -0
- package/src/utils/sanitize.ts +6 -0
- package/tailwind-internals.d.ts +133 -0
- package/tsconfig.json +9 -3
- package/build-preview-server.mjs +0 -25
- package/dist/preview/.next/cache/images/TcyzHbFXGFjrOu3wEMvDoSmqCh3qP3iiNqJf0QbED9Y/60.1741728556140.cQ5qicbpvoXZ7leVmWqG2ElLwXB1ynYeSv8MBSA-QeM.Vy8iMWM3MGUtMTk1ODcxYmIyNzMi.webp +0 -0
- package/dist/preview/.next/cache/webpack/client-development/0.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/1.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/10.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/11.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/12.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/13.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/2.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/3.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/4.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/5.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/6.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/7.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/8.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/9.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/index.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/client-development/index.pack.gz.old +0 -0
- package/dist/preview/.next/cache/webpack/server-development/0.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/1.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/2.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/3.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/4.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/5.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/6.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/7.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/8.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/9.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/index.pack.gz +0 -0
- package/dist/preview/.next/cache/webpack/server-development/index.pack.gz.old +0 -0
- package/dist/preview/.next/server/chunks/143.js +0 -6
- package/dist/preview/.next/server/chunks/409.js +0 -5
- package/dist/preview/.next/server/chunks/46.js +0 -1
- package/dist/preview/.next/server/chunks/478.js +0 -14
- package/dist/preview/.next/server/chunks/707.js +0 -13
- package/dist/preview/.next/static/B4EYZiVzdylEG9lAIl-aO/_buildManifest.js +0 -1
- package/dist/preview/.next/static/chunks/575-bc52750855c25df4.js +0 -2
- package/dist/preview/.next/static/chunks/684-0f1ef7361c499798.js +0 -1
- package/dist/preview/.next/static/chunks/684c6b30-0c65da32762fc4ee.js +0 -1
- package/dist/preview/.next/static/chunks/81-e7539b08d9d3fb4d.js +0 -1
- package/dist/preview/.next/static/chunks/883-70c8267c50bc4133.js +0 -1
- package/dist/preview/.next/static/chunks/921-d1dc8c63f49e85d6.js +0 -1
- package/dist/preview/.next/static/chunks/app/_not-found/page-03ce767859c36d4e.js +0 -1
- package/dist/preview/.next/static/chunks/app/layout-7cf14e28880544f1.js +0 -1
- package/dist/preview/.next/static/chunks/app/page-065cb49b0a078541.js +0 -1
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-656510fd180c803c.js +0 -1
- package/dist/preview/.next/static/chunks/framework-2a724981073c3a29.js +0 -1
- package/dist/preview/.next/static/chunks/main-552b9719bbc3a274.js +0 -1
- package/dist/preview/.next/static/chunks/main-app-914a73336fd45af5.js +0 -1
- package/dist/preview/.next/static/chunks/pages/_app-77ca34bce25ac75c.js +0 -1
- package/dist/preview/.next/static/chunks/pages/_error-73f611c46abbb495.js +0 -1
- package/dist/preview/.next/static/css/2df96d9ee014e8de.css +0 -3
- package/src/actions/email-validation/get-line-and-column-from-index.spec.ts +0 -22
- package/src/actions/email-validation/get-line-and-column-from-index.ts +0 -43
- package/src/components/icons/icon-scanner.tsx +0 -19
- package/src/components/icons/icon-scissors.tsx +0 -19
- /package/dist/preview/.next/static/{B4EYZiVzdylEG9lAIl-aO → Pms2orsQgT5xpttCfZfH5}/_ssgManifest.js +0 -0
package/dist/cli/index.js
CHANGED
|
@@ -1,698 +1,298 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
function _array_like_to_array(arr, len) {
|
|
3
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
-
return arr2;
|
|
6
|
-
}
|
|
7
|
-
function _array_with_holes(arr) {
|
|
8
|
-
if (Array.isArray(arr)) return arr;
|
|
9
|
-
}
|
|
10
|
-
function _array_without_holes(arr) {
|
|
11
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
|
-
}
|
|
13
|
-
function _async_iterator(iterable) {
|
|
14
|
-
var method, async, sync, retry = 2;
|
|
15
|
-
for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
|
|
16
|
-
if (async && null != (method = iterable[async])) return method.call(iterable);
|
|
17
|
-
if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
|
|
18
|
-
async = "@@asyncIterator", sync = "@@iterator";
|
|
19
|
-
}
|
|
20
|
-
throw new TypeError("Object is not async iterable");
|
|
21
|
-
}
|
|
22
|
-
function AsyncFromSyncIterator(s) {
|
|
23
|
-
function AsyncFromSyncIteratorContinuation(r) {
|
|
24
|
-
if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
|
|
25
|
-
var done = r.done;
|
|
26
|
-
return Promise.resolve(r.value).then(function(value) {
|
|
27
|
-
return {
|
|
28
|
-
value: value,
|
|
29
|
-
done: done
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return AsyncFromSyncIterator = function(s) {
|
|
34
|
-
this.s = s, this.n = s.next;
|
|
35
|
-
}, AsyncFromSyncIterator.prototype = {
|
|
36
|
-
s: null,
|
|
37
|
-
n: null,
|
|
38
|
-
next: function() {
|
|
39
|
-
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
40
|
-
},
|
|
41
|
-
return: function(value) {
|
|
42
|
-
var ret = this.s.return;
|
|
43
|
-
return void 0 === ret ? Promise.resolve({
|
|
44
|
-
value: value,
|
|
45
|
-
done: !0
|
|
46
|
-
}) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
|
|
47
|
-
},
|
|
48
|
-
throw: function(value) {
|
|
49
|
-
var thr = this.s.return;
|
|
50
|
-
return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
|
|
51
|
-
}
|
|
52
|
-
}, new AsyncFromSyncIterator(s);
|
|
53
|
-
}
|
|
54
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
55
|
-
try {
|
|
56
|
-
var info = gen[key](arg);
|
|
57
|
-
var value = info.value;
|
|
58
|
-
} catch (error) {
|
|
59
|
-
reject(error);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (info.done) {
|
|
63
|
-
resolve(value);
|
|
64
|
-
} else {
|
|
65
|
-
Promise.resolve(value).then(_next, _throw);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function _async_to_generator(fn) {
|
|
69
|
-
return function() {
|
|
70
|
-
var self = this, args = arguments;
|
|
71
|
-
return new Promise(function(resolve, reject) {
|
|
72
|
-
var gen = fn.apply(self, args);
|
|
73
|
-
function _next(value) {
|
|
74
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
75
|
-
}
|
|
76
|
-
function _throw(err) {
|
|
77
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
78
|
-
}
|
|
79
|
-
_next(undefined);
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function _define_property(obj, key, value) {
|
|
84
|
-
if (key in obj) {
|
|
85
|
-
Object.defineProperty(obj, key, {
|
|
86
|
-
value: value,
|
|
87
|
-
enumerable: true,
|
|
88
|
-
configurable: true,
|
|
89
|
-
writable: true
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
obj[key] = value;
|
|
93
|
-
}
|
|
94
|
-
return obj;
|
|
95
|
-
}
|
|
96
|
-
function _iterable_to_array(iter) {
|
|
97
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
98
|
-
}
|
|
99
|
-
function _iterable_to_array_limit(arr, i) {
|
|
100
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
101
|
-
if (_i == null) return;
|
|
102
|
-
var _arr = [];
|
|
103
|
-
var _n = true;
|
|
104
|
-
var _d = false;
|
|
105
|
-
var _s, _e;
|
|
106
|
-
try {
|
|
107
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
108
|
-
_arr.push(_s.value);
|
|
109
|
-
if (i && _arr.length === i) break;
|
|
110
|
-
}
|
|
111
|
-
} catch (err) {
|
|
112
|
-
_d = true;
|
|
113
|
-
_e = err;
|
|
114
|
-
} finally{
|
|
115
|
-
try {
|
|
116
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
117
|
-
} finally{
|
|
118
|
-
if (_d) throw _e;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return _arr;
|
|
122
|
-
}
|
|
123
|
-
function _non_iterable_rest() {
|
|
124
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
125
|
-
}
|
|
126
|
-
function _non_iterable_spread() {
|
|
127
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
128
|
-
}
|
|
129
|
-
function _object_spread(target) {
|
|
130
|
-
for(var i = 1; i < arguments.length; i++){
|
|
131
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
132
|
-
var ownKeys = Object.keys(source);
|
|
133
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
134
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
135
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
ownKeys.forEach(function(key) {
|
|
139
|
-
_define_property(target, key, source[key]);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return target;
|
|
143
|
-
}
|
|
144
|
-
function ownKeys(object, enumerableOnly) {
|
|
145
|
-
var keys = Object.keys(object);
|
|
146
|
-
if (Object.getOwnPropertySymbols) {
|
|
147
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
148
|
-
if (enumerableOnly) {
|
|
149
|
-
symbols = symbols.filter(function(sym) {
|
|
150
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
keys.push.apply(keys, symbols);
|
|
154
|
-
}
|
|
155
|
-
return keys;
|
|
156
|
-
}
|
|
157
|
-
function _object_spread_props(target, source) {
|
|
158
|
-
source = source != null ? source : {};
|
|
159
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
160
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
161
|
-
} else {
|
|
162
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
163
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return target;
|
|
167
|
-
}
|
|
168
|
-
function _sliced_to_array(arr, i) {
|
|
169
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
170
|
-
}
|
|
171
|
-
function _to_consumable_array(arr) {
|
|
172
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
173
|
-
}
|
|
174
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
175
|
-
if (!o) return;
|
|
176
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
177
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
178
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
179
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
180
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
181
|
-
}
|
|
182
|
-
function _ts_generator(thisArg, body) {
|
|
183
|
-
var f, y, t, g, _ = {
|
|
184
|
-
label: 0,
|
|
185
|
-
sent: function() {
|
|
186
|
-
if (t[0] & 1) throw t[1];
|
|
187
|
-
return t[1];
|
|
188
|
-
},
|
|
189
|
-
trys: [],
|
|
190
|
-
ops: []
|
|
191
|
-
};
|
|
192
|
-
return g = {
|
|
193
|
-
next: verb(0),
|
|
194
|
-
"throw": verb(1),
|
|
195
|
-
"return": verb(2)
|
|
196
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
197
|
-
return this;
|
|
198
|
-
}), g;
|
|
199
|
-
function verb(n) {
|
|
200
|
-
return function(v) {
|
|
201
|
-
return step([
|
|
202
|
-
n,
|
|
203
|
-
v
|
|
204
|
-
]);
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function step(op) {
|
|
208
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
209
|
-
while(_)try {
|
|
210
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
211
|
-
if (y = 0, t) op = [
|
|
212
|
-
op[0] & 2,
|
|
213
|
-
t.value
|
|
214
|
-
];
|
|
215
|
-
switch(op[0]){
|
|
216
|
-
case 0:
|
|
217
|
-
case 1:
|
|
218
|
-
t = op;
|
|
219
|
-
break;
|
|
220
|
-
case 4:
|
|
221
|
-
_.label++;
|
|
222
|
-
return {
|
|
223
|
-
value: op[1],
|
|
224
|
-
done: false
|
|
225
|
-
};
|
|
226
|
-
case 5:
|
|
227
|
-
_.label++;
|
|
228
|
-
y = op[1];
|
|
229
|
-
op = [
|
|
230
|
-
0
|
|
231
|
-
];
|
|
232
|
-
continue;
|
|
233
|
-
case 7:
|
|
234
|
-
op = _.ops.pop();
|
|
235
|
-
_.trys.pop();
|
|
236
|
-
continue;
|
|
237
|
-
default:
|
|
238
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
239
|
-
_ = 0;
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
243
|
-
_.label = op[1];
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
247
|
-
_.label = t[1];
|
|
248
|
-
t = op;
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
if (t && _.label < t[2]) {
|
|
252
|
-
_.label = t[2];
|
|
253
|
-
_.ops.push(op);
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
if (t[2]) _.ops.pop();
|
|
257
|
-
_.trys.pop();
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
op = body.call(thisArg, _);
|
|
261
|
-
} catch (e) {
|
|
262
|
-
op = [
|
|
263
|
-
6,
|
|
264
|
-
e
|
|
265
|
-
];
|
|
266
|
-
y = 0;
|
|
267
|
-
} finally{
|
|
268
|
-
f = t = 0;
|
|
269
|
-
}
|
|
270
|
-
if (op[0] & 5) throw op[1];
|
|
271
|
-
return {
|
|
272
|
-
value: op[0] ? op[1] : void 0,
|
|
273
|
-
done: true
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function _ts_values(o) {
|
|
278
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
279
|
-
if (m) return m.call(o);
|
|
280
|
-
if (o && typeof o.length === "number") return {
|
|
281
|
-
next: function() {
|
|
282
|
-
if (o && i >= o.length) o = void 0;
|
|
283
|
-
return {
|
|
284
|
-
value: o && o[i++],
|
|
285
|
-
done: !o
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
290
|
-
}
|
|
291
2
|
var __create = Object.create;
|
|
292
3
|
var __defProp = Object.defineProperty;
|
|
293
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
294
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
295
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
296
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
297
|
-
var __copyProps =
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
get: function() {
|
|
305
|
-
return from[key];
|
|
306
|
-
},
|
|
307
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
308
|
-
});
|
|
309
|
-
};
|
|
310
|
-
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
311
|
-
} catch (err) {
|
|
312
|
-
_didIteratorError = true;
|
|
313
|
-
_iteratorError = err;
|
|
314
|
-
} finally{
|
|
315
|
-
try {
|
|
316
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
317
|
-
_iterator.return();
|
|
318
|
-
}
|
|
319
|
-
} finally{
|
|
320
|
-
if (_didIteratorError) {
|
|
321
|
-
throw _iteratorError;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return to;
|
|
327
|
-
};
|
|
328
|
-
var __toESM = function(mod, isNodeMode, target) {
|
|
329
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
330
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
331
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
332
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
333
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
334
|
-
value: mod,
|
|
335
|
-
enumerable: true
|
|
336
|
-
}) : target, mod);
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
337
15
|
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
338
25
|
// src/cli/index.ts
|
|
339
26
|
var import_commander = require("commander");
|
|
27
|
+
|
|
340
28
|
// package.json
|
|
341
29
|
var package_default = {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
30
|
+
name: "react-email",
|
|
31
|
+
version: "4.0.0-alpha.7",
|
|
32
|
+
description: "A live preview of your emails right in your browser.",
|
|
33
|
+
bin: {
|
|
34
|
+
email: "./dist/cli/index.js"
|
|
35
|
+
},
|
|
36
|
+
scripts: {
|
|
37
|
+
build: "tsup-node && node ./scripts/build-preview-server.mjs",
|
|
38
|
+
"caniemail:fetch": "node ./scripts/fill-caniemail-data.mjs",
|
|
39
|
+
clean: "rm -rf dist",
|
|
40
|
+
dev: "tsup-node --watch",
|
|
41
|
+
"dev:preview": "cd ../../apps/demo && tsx ../../packages/react-email/src/cli/index.ts dev",
|
|
42
|
+
test: "vitest run",
|
|
43
|
+
"test:watch": "vitest"
|
|
44
|
+
},
|
|
45
|
+
license: "MIT",
|
|
46
|
+
repository: {
|
|
47
|
+
type: "git",
|
|
48
|
+
url: "https://github.com/resend/react-email.git",
|
|
49
|
+
directory: "packages/react-email"
|
|
50
|
+
},
|
|
51
|
+
keywords: [
|
|
52
|
+
"react",
|
|
53
|
+
"email"
|
|
54
|
+
],
|
|
55
|
+
engines: {
|
|
56
|
+
node: ">=18.0.0"
|
|
57
|
+
},
|
|
58
|
+
dependencies: {
|
|
59
|
+
"@babel/parser": "7.24.5",
|
|
60
|
+
"@babel/traverse": "7.25.6",
|
|
61
|
+
chalk: "4.1.2",
|
|
62
|
+
chokidar: "4.0.3",
|
|
63
|
+
commander: "11.1.0",
|
|
64
|
+
debounce: "2.0.0",
|
|
65
|
+
esbuild: "0.23.0",
|
|
66
|
+
glob: "10.3.4",
|
|
67
|
+
"log-symbols": "4.1.0",
|
|
68
|
+
"mime-types": "2.1.35",
|
|
69
|
+
next: "15.2.2",
|
|
70
|
+
"normalize-path": "3.0.0",
|
|
71
|
+
ora: "5.4.1",
|
|
72
|
+
"socket.io": "4.8.1"
|
|
73
|
+
},
|
|
74
|
+
devDependencies: {
|
|
75
|
+
"@babel/core": "7.26.10",
|
|
76
|
+
"@lottiefiles/dotlottie-react": "0.12.3",
|
|
77
|
+
"@radix-ui/colors": "1.0.1",
|
|
78
|
+
"@radix-ui/react-collapsible": "1.1.0",
|
|
79
|
+
"@radix-ui/react-dropdown-menu": "2.1.4",
|
|
80
|
+
"@radix-ui/react-popover": "1.1.1",
|
|
81
|
+
"@radix-ui/react-slot": "1.1.0",
|
|
82
|
+
"@radix-ui/react-tabs": "1.1.1",
|
|
83
|
+
"@radix-ui/react-toggle-group": "1.1.0",
|
|
84
|
+
"@radix-ui/react-tooltip": "1.1.2",
|
|
85
|
+
"@react-email/render": "workspace:*",
|
|
86
|
+
"@swc/core": "1.4.15",
|
|
87
|
+
"@types/babel__core": "7.20.5",
|
|
88
|
+
"@types/babel__traverse": "*",
|
|
89
|
+
"@types/fs-extra": "11.0.1",
|
|
90
|
+
"@types/mime-types": "2.1.4",
|
|
91
|
+
"@types/node": "22.10.2",
|
|
92
|
+
"@types/normalize-path": "3.0.2",
|
|
93
|
+
"@types/react": "19.0.10",
|
|
94
|
+
"@types/react-dom": "19.0.4",
|
|
95
|
+
"@types/webpack": "5.28.5",
|
|
96
|
+
"@vercel/style-guide": "5.1.0",
|
|
97
|
+
autoprefixer: "10.4.20",
|
|
98
|
+
clsx: "2.1.0",
|
|
99
|
+
"framer-motion": "12.0.0-alpha.2",
|
|
100
|
+
jiti: "2.4.2",
|
|
101
|
+
json5: "2.2.3",
|
|
102
|
+
"module-punycode": "npm:punycode@2.3.1",
|
|
103
|
+
"node-html-parser": "6.1.13",
|
|
104
|
+
postcss: "8.4.40",
|
|
105
|
+
"prettier-plugin-tailwindcss": "0.6.6",
|
|
106
|
+
"pretty-bytes": "6.1.1",
|
|
107
|
+
"prism-react-renderer": "2.1.0",
|
|
108
|
+
react: "19.0.0",
|
|
109
|
+
"react-dom": "19.0.0",
|
|
110
|
+
sharp: "0.33.3",
|
|
111
|
+
"socket.io-client": "4.8.0",
|
|
112
|
+
sonner: "1.7.1",
|
|
113
|
+
"source-map-js": "1.0.2",
|
|
114
|
+
spamc: "0.0.5",
|
|
115
|
+
"stacktrace-parser": "0.1.10",
|
|
116
|
+
"tailwind-merge": "2.2.0",
|
|
117
|
+
tailwindcss: "3.4.0",
|
|
118
|
+
tsup: "7.2.0",
|
|
119
|
+
tsx: "4.9.0",
|
|
120
|
+
typescript: "5.8.2",
|
|
121
|
+
"use-debounce": "10.0.4",
|
|
122
|
+
vitest: "1.1.3",
|
|
123
|
+
zod: "3.24.2"
|
|
124
|
+
}
|
|
432
125
|
};
|
|
126
|
+
|
|
433
127
|
// src/cli/commands/build.ts
|
|
434
128
|
var import_node_child_process = require("child_process");
|
|
435
129
|
var import_node_fs5 = __toESM(require("fs"));
|
|
436
130
|
var import_node_path8 = __toESM(require("path"));
|
|
437
131
|
var import_log_symbols3 = __toESM(require("log-symbols"));
|
|
438
132
|
var import_ora2 = __toESM(require("ora"));
|
|
133
|
+
|
|
439
134
|
// src/utils/get-emails-directory-metadata.ts
|
|
440
135
|
var import_node_fs = __toESM(require("fs"));
|
|
441
136
|
var import_node_path = __toESM(require("path"));
|
|
442
|
-
var isFileAnEmail =
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
var fileContents = import_node_fs.default.readFileSync(fullPath, "utf8");
|
|
455
|
-
return /\bexport\s+default\b/gm.test(fileContents);
|
|
137
|
+
var isFileAnEmail = (fullPath) => {
|
|
138
|
+
const stat = import_node_fs.default.statSync(fullPath);
|
|
139
|
+
if (stat.isDirectory())
|
|
140
|
+
return false;
|
|
141
|
+
const { ext } = import_node_path.default.parse(fullPath);
|
|
142
|
+
if (![".js", ".tsx", ".jsx"].includes(ext))
|
|
143
|
+
return false;
|
|
144
|
+
if (!import_node_fs.default.existsSync(fullPath)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const fileContents = import_node_fs.default.readFileSync(fullPath, "utf8");
|
|
148
|
+
return /\bexport\s+default\b/gm.test(fileContents);
|
|
456
149
|
};
|
|
457
|
-
var mergeDirectoriesWithSubDirectories =
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
var getEmailsDirectoryMetadata = function() {
|
|
468
|
-
var _ref = _async_to_generator(function(absolutePathToEmailsDirectory) {
|
|
469
|
-
var keepFileExtensions, isSubDirectory, baseDirectoryPath, dirents, emailFilenames, subDirectories, emailsMetadata;
|
|
470
|
-
var _arguments = arguments;
|
|
471
|
-
return _ts_generator(this, function(_state) {
|
|
472
|
-
switch(_state.label){
|
|
473
|
-
case 0:
|
|
474
|
-
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;
|
|
475
|
-
if (!import_node_fs.default.existsSync(absolutePathToEmailsDirectory)) return [
|
|
476
|
-
2
|
|
477
|
-
];
|
|
478
|
-
return [
|
|
479
|
-
4,
|
|
480
|
-
import_node_fs.default.promises.readdir(absolutePathToEmailsDirectory, {
|
|
481
|
-
withFileTypes: true
|
|
482
|
-
})
|
|
483
|
-
];
|
|
484
|
-
case 1:
|
|
485
|
-
dirents = _state.sent();
|
|
486
|
-
emailFilenames = dirents.filter(function(dirent) {
|
|
487
|
-
return isFileAnEmail(import_node_path.default.join(absolutePathToEmailsDirectory, dirent.name));
|
|
488
|
-
}).map(function(dirent) {
|
|
489
|
-
return keepFileExtensions ? dirent.name : dirent.name.replace(import_node_path.default.extname(dirent.name), "");
|
|
490
|
-
});
|
|
491
|
-
return [
|
|
492
|
-
4,
|
|
493
|
-
Promise.all(dirents.filter(function(dirent) {
|
|
494
|
-
return dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static";
|
|
495
|
-
}).map(function(dirent) {
|
|
496
|
-
var direntAbsolutePath = import_node_path.default.join(absolutePathToEmailsDirectory, dirent.name);
|
|
497
|
-
return getEmailsDirectoryMetadata(direntAbsolutePath, keepFileExtensions, true, baseDirectoryPath);
|
|
498
|
-
}))
|
|
499
|
-
];
|
|
500
|
-
case 2:
|
|
501
|
-
subDirectories = _state.sent();
|
|
502
|
-
emailsMetadata = {
|
|
503
|
-
absolutePath: absolutePathToEmailsDirectory,
|
|
504
|
-
relativePath: import_node_path.default.relative(baseDirectoryPath, absolutePathToEmailsDirectory),
|
|
505
|
-
directoryName: absolutePathToEmailsDirectory.split(import_node_path.default.sep).pop(),
|
|
506
|
-
emailFilenames: emailFilenames,
|
|
507
|
-
subDirectories: subDirectories
|
|
508
|
-
};
|
|
509
|
-
return [
|
|
510
|
-
2,
|
|
511
|
-
isSubDirectory ? mergeDirectoriesWithSubDirectories(emailsMetadata) : emailsMetadata
|
|
512
|
-
];
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
});
|
|
516
|
-
return function getEmailsDirectoryMetadata(absolutePathToEmailsDirectory) {
|
|
517
|
-
return _ref.apply(this, arguments);
|
|
150
|
+
var mergeDirectoriesWithSubDirectories = (emailsDirectoryMetadata) => {
|
|
151
|
+
let currentResultingMergedDirectory = emailsDirectoryMetadata;
|
|
152
|
+
while (currentResultingMergedDirectory.emailFilenames.length === 0 && currentResultingMergedDirectory.subDirectories.length === 1) {
|
|
153
|
+
const onlySubDirectory = currentResultingMergedDirectory.subDirectories[0];
|
|
154
|
+
currentResultingMergedDirectory = {
|
|
155
|
+
...onlySubDirectory,
|
|
156
|
+
directoryName: import_node_path.default.join(
|
|
157
|
+
currentResultingMergedDirectory.directoryName,
|
|
158
|
+
onlySubDirectory.directoryName
|
|
159
|
+
)
|
|
518
160
|
};
|
|
519
|
-
}
|
|
161
|
+
}
|
|
162
|
+
return currentResultingMergedDirectory;
|
|
163
|
+
};
|
|
164
|
+
var getEmailsDirectoryMetadata = async (absolutePathToEmailsDirectory, keepFileExtensions = false, isSubDirectory = false, baseDirectoryPath = absolutePathToEmailsDirectory) => {
|
|
165
|
+
if (!import_node_fs.default.existsSync(absolutePathToEmailsDirectory))
|
|
166
|
+
return;
|
|
167
|
+
const dirents = await import_node_fs.default.promises.readdir(absolutePathToEmailsDirectory, {
|
|
168
|
+
withFileTypes: true
|
|
169
|
+
});
|
|
170
|
+
const emailFilenames = dirents.filter(
|
|
171
|
+
(dirent) => isFileAnEmail(import_node_path.default.join(absolutePathToEmailsDirectory, dirent.name))
|
|
172
|
+
).map(
|
|
173
|
+
(dirent) => keepFileExtensions ? dirent.name : dirent.name.replace(import_node_path.default.extname(dirent.name), "")
|
|
174
|
+
);
|
|
175
|
+
const subDirectories = await Promise.all(
|
|
176
|
+
dirents.filter(
|
|
177
|
+
(dirent) => dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static"
|
|
178
|
+
).map((dirent) => {
|
|
179
|
+
const direntAbsolutePath = import_node_path.default.join(
|
|
180
|
+
absolutePathToEmailsDirectory,
|
|
181
|
+
dirent.name
|
|
182
|
+
);
|
|
183
|
+
return getEmailsDirectoryMetadata(
|
|
184
|
+
direntAbsolutePath,
|
|
185
|
+
keepFileExtensions,
|
|
186
|
+
true,
|
|
187
|
+
baseDirectoryPath
|
|
188
|
+
);
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
const emailsMetadata = {
|
|
192
|
+
absolutePath: absolutePathToEmailsDirectory,
|
|
193
|
+
relativePath: import_node_path.default.relative(
|
|
194
|
+
baseDirectoryPath,
|
|
195
|
+
absolutePathToEmailsDirectory
|
|
196
|
+
),
|
|
197
|
+
directoryName: absolutePathToEmailsDirectory.split(import_node_path.default.sep).pop(),
|
|
198
|
+
emailFilenames,
|
|
199
|
+
subDirectories
|
|
200
|
+
};
|
|
201
|
+
return isSubDirectory ? mergeDirectoriesWithSubDirectories(emailsMetadata) : emailsMetadata;
|
|
202
|
+
};
|
|
203
|
+
|
|
520
204
|
// src/utils/register-spinner-autostopping.ts
|
|
521
205
|
var import_log_symbols = __toESM(require("log-symbols"));
|
|
522
206
|
var spinners = /* @__PURE__ */ new Set();
|
|
523
|
-
process.on("SIGINT",
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
207
|
+
process.on("SIGINT", () => {
|
|
208
|
+
spinners.forEach((spinner) => {
|
|
209
|
+
if (spinner.isSpinning) {
|
|
210
|
+
spinner.stop();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
529
213
|
});
|
|
530
|
-
process.on("exit",
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
});
|
|
537
|
-
}
|
|
214
|
+
process.on("exit", (code) => {
|
|
215
|
+
if (code !== 0) {
|
|
216
|
+
spinners.forEach((spinner) => {
|
|
217
|
+
if (spinner.isSpinning) {
|
|
218
|
+
spinner.stopAndPersist({
|
|
219
|
+
symbol: import_log_symbols.default.error
|
|
538
220
|
});
|
|
539
|
-
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
540
224
|
});
|
|
541
|
-
var registerSpinnerAutostopping =
|
|
542
|
-
|
|
225
|
+
var registerSpinnerAutostopping = (spinner) => {
|
|
226
|
+
spinners.add(spinner);
|
|
543
227
|
};
|
|
228
|
+
|
|
544
229
|
// src/cli/utils/tree.ts
|
|
545
230
|
var import_node_fs2 = require("fs");
|
|
546
231
|
var import_node_os = __toESM(require("os"));
|
|
547
232
|
var import_node_path2 = __toESM(require("path"));
|
|
548
233
|
var SYMBOLS = {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
234
|
+
BRANCH: "\u251C\u2500\u2500 ",
|
|
235
|
+
EMPTY: "",
|
|
236
|
+
INDENT: " ",
|
|
237
|
+
LAST_BRANCH: "\u2514\u2500\u2500 ",
|
|
238
|
+
VERTICAL: "\u2502 "
|
|
554
239
|
};
|
|
555
|
-
var getTreeLines =
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
import_node_fs2.promises.stat(dirFullpath)
|
|
572
|
-
];
|
|
573
|
-
case 1:
|
|
574
|
-
dirStat = _state.sent();
|
|
575
|
-
if (!(dirStat.isDirectory() && currentDepth < depth)) return [
|
|
576
|
-
3,
|
|
577
|
-
6
|
|
578
|
-
];
|
|
579
|
-
_loop = function(i) {
|
|
580
|
-
var dirent, isLast, branchingSymbol, verticalSymbol, pathToDirectory, treeLinesForSubDirectory;
|
|
581
|
-
return _ts_generator(this, function(_state) {
|
|
582
|
-
switch(_state.label){
|
|
583
|
-
case 0:
|
|
584
|
-
dirent = childDirents[i];
|
|
585
|
-
isLast = i === childDirents.length - 1;
|
|
586
|
-
branchingSymbol = isLast ? SYMBOLS.LAST_BRANCH : SYMBOLS.BRANCH;
|
|
587
|
-
verticalSymbol = isLast ? SYMBOLS.INDENT : SYMBOLS.VERTICAL;
|
|
588
|
-
if (!dirent.isFile()) return [
|
|
589
|
-
3,
|
|
590
|
-
1
|
|
591
|
-
];
|
|
592
|
-
lines.push("".concat(branchingSymbol).concat(dirent.name));
|
|
593
|
-
return [
|
|
594
|
-
3,
|
|
595
|
-
3
|
|
596
|
-
];
|
|
597
|
-
case 1:
|
|
598
|
-
pathToDirectory = import_node_path2.default.join(dirFullpath, dirent.name);
|
|
599
|
-
return [
|
|
600
|
-
4,
|
|
601
|
-
getTreeLines(pathToDirectory, depth, currentDepth + 1)
|
|
602
|
-
];
|
|
603
|
-
case 2:
|
|
604
|
-
treeLinesForSubDirectory = _state.sent();
|
|
605
|
-
lines = lines.concat(treeLinesForSubDirectory.map(function(line, index) {
|
|
606
|
-
return index === 0 ? "".concat(branchingSymbol).concat(line) : "".concat(verticalSymbol).concat(line);
|
|
607
|
-
}));
|
|
608
|
-
_state.label = 3;
|
|
609
|
-
case 3:
|
|
610
|
-
return [
|
|
611
|
-
2
|
|
612
|
-
];
|
|
613
|
-
}
|
|
614
|
-
});
|
|
615
|
-
};
|
|
616
|
-
return [
|
|
617
|
-
4,
|
|
618
|
-
import_node_fs2.promises.readdir(dirFullpath, {
|
|
619
|
-
withFileTypes: true
|
|
620
|
-
})
|
|
621
|
-
];
|
|
622
|
-
case 2:
|
|
623
|
-
childDirents = _state.sent();
|
|
624
|
-
childDirents.sort(function(a, b) {
|
|
625
|
-
if (a.isDirectory() && b.isFile()) {
|
|
626
|
-
return -1;
|
|
627
|
-
}
|
|
628
|
-
if (a.isFile() && b.isDirectory()) {
|
|
629
|
-
return 1;
|
|
630
|
-
}
|
|
631
|
-
return b.name > a.name ? -1 : 1;
|
|
632
|
-
});
|
|
633
|
-
i = 0;
|
|
634
|
-
_state.label = 3;
|
|
635
|
-
case 3:
|
|
636
|
-
if (!(i < childDirents.length)) return [
|
|
637
|
-
3,
|
|
638
|
-
6
|
|
639
|
-
];
|
|
640
|
-
return [
|
|
641
|
-
5,
|
|
642
|
-
_ts_values(_loop(i))
|
|
643
|
-
];
|
|
644
|
-
case 4:
|
|
645
|
-
_state.sent();
|
|
646
|
-
_state.label = 5;
|
|
647
|
-
case 5:
|
|
648
|
-
i++;
|
|
649
|
-
return [
|
|
650
|
-
3,
|
|
651
|
-
3
|
|
652
|
-
];
|
|
653
|
-
case 6:
|
|
654
|
-
return [
|
|
655
|
-
2,
|
|
656
|
-
lines
|
|
657
|
-
];
|
|
658
|
-
}
|
|
659
|
-
});
|
|
240
|
+
var getTreeLines = async (dirPath, depth, currentDepth = 0) => {
|
|
241
|
+
const base = process.cwd();
|
|
242
|
+
const dirFullpath = import_node_path2.default.resolve(base, dirPath);
|
|
243
|
+
const dirname = import_node_path2.default.basename(dirFullpath);
|
|
244
|
+
let lines = [dirname];
|
|
245
|
+
const dirStat = await import_node_fs2.promises.stat(dirFullpath);
|
|
246
|
+
if (dirStat.isDirectory() && currentDepth < depth) {
|
|
247
|
+
const childDirents = await import_node_fs2.promises.readdir(dirFullpath, { withFileTypes: true });
|
|
248
|
+
childDirents.sort((a, b) => {
|
|
249
|
+
if (a.isDirectory() && b.isFile()) {
|
|
250
|
+
return -1;
|
|
251
|
+
}
|
|
252
|
+
if (a.isFile() && b.isDirectory()) {
|
|
253
|
+
return 1;
|
|
254
|
+
}
|
|
255
|
+
return b.name > a.name ? -1 : 1;
|
|
660
256
|
});
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
257
|
+
for (let i = 0; i < childDirents.length; i++) {
|
|
258
|
+
const dirent = childDirents[i];
|
|
259
|
+
const isLast = i === childDirents.length - 1;
|
|
260
|
+
const branchingSymbol = isLast ? SYMBOLS.LAST_BRANCH : SYMBOLS.BRANCH;
|
|
261
|
+
const verticalSymbol = isLast ? SYMBOLS.INDENT : SYMBOLS.VERTICAL;
|
|
262
|
+
if (dirent.isFile()) {
|
|
263
|
+
lines.push(`${branchingSymbol}${dirent.name}`);
|
|
264
|
+
} else {
|
|
265
|
+
const pathToDirectory = import_node_path2.default.join(dirFullpath, dirent.name);
|
|
266
|
+
const treeLinesForSubDirectory = await getTreeLines(
|
|
267
|
+
pathToDirectory,
|
|
268
|
+
depth,
|
|
269
|
+
currentDepth + 1
|
|
270
|
+
);
|
|
271
|
+
lines = lines.concat(
|
|
272
|
+
treeLinesForSubDirectory.map(
|
|
273
|
+
(line, index) => index === 0 ? `${branchingSymbol}${line}` : `${verticalSymbol}${line}`
|
|
274
|
+
)
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return lines;
|
|
280
|
+
};
|
|
281
|
+
var tree = async (dirPath, depth) => {
|
|
282
|
+
const lines = await getTreeLines(dirPath, depth);
|
|
283
|
+
return lines.join(import_node_os.default.EOL);
|
|
284
|
+
};
|
|
285
|
+
|
|
688
286
|
// src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
689
287
|
var import_node_path7 = __toESM(require("path"));
|
|
690
288
|
var import_chokidar = require("chokidar");
|
|
691
289
|
var import_debounce = __toESM(require("debounce"));
|
|
692
290
|
var import_socket = require("socket.io");
|
|
291
|
+
|
|
693
292
|
// src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
694
293
|
var import_node_fs4 = require("fs");
|
|
695
294
|
var import_node_path6 = __toESM(require("path"));
|
|
295
|
+
|
|
696
296
|
// src/cli/utils/preview/start-dev-server.ts
|
|
697
297
|
var import_node_http = __toESM(require("http"));
|
|
698
298
|
var import_node_path5 = __toESM(require("path"));
|
|
@@ -701,1627 +301,760 @@ var import_chalk = __toESM(require("chalk"));
|
|
|
701
301
|
var import_log_symbols2 = __toESM(require("log-symbols"));
|
|
702
302
|
var import_next = __toESM(require("next"));
|
|
703
303
|
var import_ora = __toESM(require("ora"));
|
|
304
|
+
|
|
704
305
|
// src/cli/utils/preview/get-env-variables-for-preview-app.ts
|
|
705
306
|
var import_node_path3 = __toESM(require("path"));
|
|
706
|
-
var getEnvVariablesForPreviewApp =
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
307
|
+
var getEnvVariablesForPreviewApp = (relativePathToEmailsDirectory, cwd) => {
|
|
308
|
+
return {
|
|
309
|
+
EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
|
|
310
|
+
EMAILS_DIR_ABSOLUTE_PATH: import_node_path3.default.resolve(cwd, relativePathToEmailsDirectory),
|
|
311
|
+
USER_PROJECT_LOCATION: cwd,
|
|
312
|
+
NEXT_PUBLIC_IS_PREVIEW_DEVELOPMENT: isDev ? "true" : "false"
|
|
313
|
+
};
|
|
712
314
|
};
|
|
315
|
+
|
|
713
316
|
// src/cli/utils/preview/serve-static-file.ts
|
|
714
317
|
var import_node_fs3 = require("fs");
|
|
715
318
|
var import_node_path4 = __toESM(require("path"));
|
|
716
319
|
var import_mime_types = require("mime-types");
|
|
717
|
-
var serveStaticFile =
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
return [
|
|
742
|
-
4,
|
|
743
|
-
import_node_fs3.promises.readFile(fileHandle)
|
|
744
|
-
];
|
|
745
|
-
case 3:
|
|
746
|
-
fileData = _state.sent();
|
|
747
|
-
res.setHeader("Content-type", (0, import_mime_types.lookup)(ext) || "text/plain");
|
|
748
|
-
res.end(fileData);
|
|
749
|
-
return [
|
|
750
|
-
3,
|
|
751
|
-
6
|
|
752
|
-
];
|
|
753
|
-
case 4:
|
|
754
|
-
exception = _state.sent();
|
|
755
|
-
console.error("Could not read file at ".concat(fileAbsolutePath, " to be served, here's the exception:"), exception);
|
|
756
|
-
res.statusCode = 500;
|
|
757
|
-
res.end("Could not read file to be served! Check your terminal for more information.");
|
|
758
|
-
return [
|
|
759
|
-
3,
|
|
760
|
-
6
|
|
761
|
-
];
|
|
762
|
-
case 5:
|
|
763
|
-
fileHandle.close();
|
|
764
|
-
return [
|
|
765
|
-
7
|
|
766
|
-
];
|
|
767
|
-
case 6:
|
|
768
|
-
return [
|
|
769
|
-
2
|
|
770
|
-
];
|
|
771
|
-
}
|
|
772
|
-
});
|
|
773
|
-
});
|
|
774
|
-
return function serveStaticFile(res, parsedUrl, staticDirRelativePath) {
|
|
775
|
-
return _ref.apply(this, arguments);
|
|
776
|
-
};
|
|
777
|
-
}();
|
|
320
|
+
var serveStaticFile = async (res, parsedUrl, staticDirRelativePath) => {
|
|
321
|
+
const staticBaseDir = import_node_path4.default.join(process.cwd(), staticDirRelativePath);
|
|
322
|
+
const pathname = parsedUrl.pathname;
|
|
323
|
+
const ext = import_node_path4.default.parse(pathname).ext;
|
|
324
|
+
const fileAbsolutePath = import_node_path4.default.join(staticBaseDir, pathname);
|
|
325
|
+
const fileHandle = await import_node_fs3.promises.open(fileAbsolutePath, "r");
|
|
326
|
+
try {
|
|
327
|
+
const fileData = await import_node_fs3.promises.readFile(fileHandle);
|
|
328
|
+
res.setHeader("Content-type", (0, import_mime_types.lookup)(ext) || "text/plain");
|
|
329
|
+
res.end(fileData);
|
|
330
|
+
} catch (exception) {
|
|
331
|
+
console.error(
|
|
332
|
+
`Could not read file at ${fileAbsolutePath} to be served, here's the exception:`,
|
|
333
|
+
exception
|
|
334
|
+
);
|
|
335
|
+
res.statusCode = 500;
|
|
336
|
+
res.end(
|
|
337
|
+
"Could not read file to be served! Check your terminal for more information."
|
|
338
|
+
);
|
|
339
|
+
} finally {
|
|
340
|
+
fileHandle.close();
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
778
344
|
// src/cli/utils/preview/start-dev-server.ts
|
|
779
345
|
var devServer;
|
|
780
|
-
var safeAsyncServerListen =
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
resolve({
|
|
790
|
-
portAlreadyInUse: true
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
});
|
|
346
|
+
var safeAsyncServerListen = (server, port) => {
|
|
347
|
+
return new Promise((resolve) => {
|
|
348
|
+
server.listen(port, () => {
|
|
349
|
+
resolve({ portAlreadyInUse: false });
|
|
350
|
+
});
|
|
351
|
+
server.on("error", (e) => {
|
|
352
|
+
if (e.code === "EADDRINUSE") {
|
|
353
|
+
resolve({ portAlreadyInUse: true });
|
|
354
|
+
}
|
|
794
355
|
});
|
|
356
|
+
});
|
|
795
357
|
};
|
|
796
358
|
var isDev = !__filename.endsWith(import_node_path5.default.join("cli", "index.js"));
|
|
797
359
|
var cliPacakgeLocation = isDev ? import_node_path5.default.resolve(__dirname, "../../../..") : import_node_path5.default.resolve(__dirname, "../..");
|
|
798
360
|
var previewServerLocation = isDev ? import_node_path5.default.resolve(__dirname, "../../../..") : import_node_path5.default.resolve(__dirname, "../preview");
|
|
799
|
-
var startDevServer =
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
symbol: import_log_symbols2.default.success
|
|
905
|
-
});
|
|
906
|
-
return [
|
|
907
|
-
2,
|
|
908
|
-
devServer
|
|
909
|
-
];
|
|
910
|
-
}
|
|
911
|
-
});
|
|
912
|
-
});
|
|
913
|
-
return function startDevServer(emailsDirRelativePath, staticBaseDirRelativePath, port) {
|
|
914
|
-
return _ref.apply(this, arguments);
|
|
915
|
-
};
|
|
916
|
-
}();
|
|
917
|
-
var makeExitHandler = function(options) {
|
|
918
|
-
return function(_codeOrSignal) {
|
|
919
|
-
if (typeof devServer !== "undefined") {
|
|
920
|
-
console.log("\nshutting down dev server");
|
|
921
|
-
devServer.close();
|
|
922
|
-
devServer = void 0;
|
|
923
|
-
}
|
|
924
|
-
if (options === null || options === void 0 ? void 0 : options.shouldKillProcess) {
|
|
925
|
-
process.exit(options.killWithErrorCode ? 1 : 0);
|
|
926
|
-
}
|
|
927
|
-
};
|
|
361
|
+
var startDevServer = async (emailsDirRelativePath, staticBaseDirRelativePath, port) => {
|
|
362
|
+
devServer = import_node_http.default.createServer((req, res) => {
|
|
363
|
+
if (!req.url) {
|
|
364
|
+
res.end(404);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const parsedUrl = import_node_url.default.parse(req.url, true);
|
|
368
|
+
res.setHeader(
|
|
369
|
+
"Cache-Control",
|
|
370
|
+
"no-cache, max-age=0, must-revalidate, no-store"
|
|
371
|
+
);
|
|
372
|
+
res.setHeader("Pragma", "no-cache");
|
|
373
|
+
res.setHeader("Expires", "-1");
|
|
374
|
+
try {
|
|
375
|
+
if (parsedUrl.path?.includes("static/") && !parsedUrl.path.includes("_next/static/")) {
|
|
376
|
+
void serveStaticFile(res, parsedUrl, staticBaseDirRelativePath);
|
|
377
|
+
} else if (!isNextReady) {
|
|
378
|
+
void nextReadyPromise.then(
|
|
379
|
+
() => nextHandleRequest?.(req, res, parsedUrl)
|
|
380
|
+
);
|
|
381
|
+
} else {
|
|
382
|
+
void nextHandleRequest?.(req, res, parsedUrl);
|
|
383
|
+
}
|
|
384
|
+
} catch (e) {
|
|
385
|
+
console.error("caught error", e);
|
|
386
|
+
res.writeHead(500);
|
|
387
|
+
res.end();
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
const { portAlreadyInUse } = await safeAsyncServerListen(devServer, port);
|
|
391
|
+
if (!portAlreadyInUse) {
|
|
392
|
+
console.log(import_chalk.default.greenBright(` React Email ${package_default.version}`));
|
|
393
|
+
console.log(` Running preview at: http://localhost:${port}
|
|
394
|
+
`);
|
|
395
|
+
} else {
|
|
396
|
+
const nextPortToTry = port + 1;
|
|
397
|
+
console.warn(
|
|
398
|
+
` ${import_log_symbols2.default.warning} Port ${port} is already in use, trying ${nextPortToTry}`
|
|
399
|
+
);
|
|
400
|
+
return startDevServer(
|
|
401
|
+
emailsDirRelativePath,
|
|
402
|
+
staticBaseDirRelativePath,
|
|
403
|
+
nextPortToTry
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
devServer.on("close", async () => {
|
|
407
|
+
await app.close();
|
|
408
|
+
});
|
|
409
|
+
devServer.on("error", (e) => {
|
|
410
|
+
console.error(
|
|
411
|
+
` ${import_log_symbols2.default.error} preview server error: `,
|
|
412
|
+
JSON.stringify(e)
|
|
413
|
+
);
|
|
414
|
+
process.exit(1);
|
|
415
|
+
});
|
|
416
|
+
const spinner = (0, import_ora.default)({
|
|
417
|
+
text: "Getting react-email preview server ready...\n",
|
|
418
|
+
prefixText: " "
|
|
419
|
+
}).start();
|
|
420
|
+
registerSpinnerAutostopping(spinner);
|
|
421
|
+
const timeBeforeNextReady = performance.now();
|
|
422
|
+
process.env = {
|
|
423
|
+
NODE_ENV: "development",
|
|
424
|
+
...process.env,
|
|
425
|
+
...getEnvVariablesForPreviewApp(
|
|
426
|
+
// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
|
|
427
|
+
import_node_path5.default.normalize(emailsDirRelativePath),
|
|
428
|
+
process.cwd()
|
|
429
|
+
)
|
|
430
|
+
};
|
|
431
|
+
const app = (0, import_next.default)({
|
|
432
|
+
// passing in env here does not get the environment variables there
|
|
433
|
+
dev: isDev,
|
|
434
|
+
conf: {
|
|
435
|
+
images: {
|
|
436
|
+
// This is to avoid the warning with sharp
|
|
437
|
+
unoptimized: true
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
hostname: "localhost",
|
|
441
|
+
port,
|
|
442
|
+
dir: previewServerLocation
|
|
443
|
+
});
|
|
444
|
+
let isNextReady = false;
|
|
445
|
+
const nextReadyPromise = app.prepare();
|
|
446
|
+
await nextReadyPromise;
|
|
447
|
+
isNextReady = true;
|
|
448
|
+
const nextHandleRequest = app.getRequestHandler();
|
|
449
|
+
const secondsToNextReady = ((performance.now() - timeBeforeNextReady) / 1e3).toFixed(1);
|
|
450
|
+
spinner.stopAndPersist({
|
|
451
|
+
text: `Ready in ${secondsToNextReady}s
|
|
452
|
+
`,
|
|
453
|
+
symbol: import_log_symbols2.default.success
|
|
454
|
+
});
|
|
455
|
+
return devServer;
|
|
456
|
+
};
|
|
457
|
+
var makeExitHandler = (options) => (_codeOrSignal) => {
|
|
458
|
+
if (typeof devServer !== "undefined") {
|
|
459
|
+
console.log("\nshutting down dev server");
|
|
460
|
+
devServer.close();
|
|
461
|
+
devServer = void 0;
|
|
462
|
+
}
|
|
463
|
+
if (options?.shouldKillProcess) {
|
|
464
|
+
process.exit(options.killWithErrorCode ? 1 : 0);
|
|
465
|
+
}
|
|
928
466
|
};
|
|
929
467
|
process.on("exit", makeExitHandler());
|
|
930
|
-
process.on(
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
process.on(
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
process.on(
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
process.on(
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
468
|
+
process.on(
|
|
469
|
+
"SIGINT",
|
|
470
|
+
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
471
|
+
);
|
|
472
|
+
process.on(
|
|
473
|
+
"SIGUSR1",
|
|
474
|
+
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
475
|
+
);
|
|
476
|
+
process.on(
|
|
477
|
+
"SIGUSR2",
|
|
478
|
+
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
479
|
+
);
|
|
480
|
+
process.on(
|
|
481
|
+
"uncaughtException",
|
|
482
|
+
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: true })
|
|
483
|
+
);
|
|
484
|
+
|
|
946
485
|
// src/cli/utils/preview/hot-reloading/get-imported-modules.ts
|
|
947
486
|
var import_parser = require("@babel/parser");
|
|
948
487
|
var import_traverse = __toESM(require("@babel/traverse"));
|
|
949
|
-
var getImportedModules =
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
}
|
|
961
|
-
(
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
CallExpression: function CallExpression(param) {
|
|
977
|
-
var node = param.node;
|
|
978
|
-
if ("name" in node.callee && node.callee.name === "require") {
|
|
979
|
-
if (node.arguments.length === 1) {
|
|
980
|
-
var importPathNode = node.arguments[0];
|
|
981
|
-
if (importPathNode.type === "StringLiteral") {
|
|
982
|
-
importedPaths.push(importPathNode.value);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
488
|
+
var getImportedModules = (contents) => {
|
|
489
|
+
const importedPaths = [];
|
|
490
|
+
const parsedContents = (0, import_parser.parse)(contents, {
|
|
491
|
+
sourceType: "unambiguous",
|
|
492
|
+
strictMode: false,
|
|
493
|
+
errorRecovery: true,
|
|
494
|
+
plugins: ["jsx", "typescript", "decorators"]
|
|
495
|
+
});
|
|
496
|
+
(0, import_traverse.default)(parsedContents, {
|
|
497
|
+
ImportDeclaration({ node }) {
|
|
498
|
+
importedPaths.push(node.source.value);
|
|
499
|
+
},
|
|
500
|
+
ExportAllDeclaration({ node }) {
|
|
501
|
+
importedPaths.push(node.source.value);
|
|
502
|
+
},
|
|
503
|
+
ExportNamedDeclaration({ node }) {
|
|
504
|
+
if (node.source) {
|
|
505
|
+
importedPaths.push(node.source.value);
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
CallExpression({ node }) {
|
|
509
|
+
if ("name" in node.callee && node.callee.name === "require") {
|
|
510
|
+
if (node.arguments.length === 1) {
|
|
511
|
+
const importPathNode = node.arguments[0];
|
|
512
|
+
if (importPathNode.type === "StringLiteral") {
|
|
513
|
+
importedPaths.push(importPathNode.value);
|
|
514
|
+
}
|
|
986
515
|
}
|
|
987
|
-
|
|
988
|
-
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
return importedPaths;
|
|
989
520
|
};
|
|
521
|
+
|
|
990
522
|
// src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
991
|
-
var readAllFilesInsideDirectory =
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
})
|
|
1003
|
-
];
|
|
1004
|
-
case 1:
|
|
1005
|
-
topLevelDirents = _state.sent();
|
|
1006
|
-
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
1007
|
-
_state.label = 2;
|
|
1008
|
-
case 2:
|
|
1009
|
-
_state.trys.push([
|
|
1010
|
-
2,
|
|
1011
|
-
9,
|
|
1012
|
-
10,
|
|
1013
|
-
15
|
|
1014
|
-
]);
|
|
1015
|
-
_iterator = _async_iterator(topLevelDirents);
|
|
1016
|
-
_state.label = 3;
|
|
1017
|
-
case 3:
|
|
1018
|
-
return [
|
|
1019
|
-
4,
|
|
1020
|
-
_iterator.next()
|
|
1021
|
-
];
|
|
1022
|
-
case 4:
|
|
1023
|
-
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
1024
|
-
3,
|
|
1025
|
-
8
|
|
1026
|
-
];
|
|
1027
|
-
_value = _step.value;
|
|
1028
|
-
dirent = _value;
|
|
1029
|
-
pathToDirent = import_node_path6.default.join(directory, dirent.name);
|
|
1030
|
-
if (!dirent.isDirectory()) return [
|
|
1031
|
-
3,
|
|
1032
|
-
6
|
|
1033
|
-
];
|
|
1034
|
-
_ = allFilePaths.concat;
|
|
1035
|
-
return [
|
|
1036
|
-
4,
|
|
1037
|
-
readAllFilesInsideDirectory(pathToDirent)
|
|
1038
|
-
];
|
|
1039
|
-
case 5:
|
|
1040
|
-
allFilePaths = _.apply(allFilePaths, [
|
|
1041
|
-
_state.sent()
|
|
1042
|
-
]);
|
|
1043
|
-
return [
|
|
1044
|
-
3,
|
|
1045
|
-
7
|
|
1046
|
-
];
|
|
1047
|
-
case 6:
|
|
1048
|
-
allFilePaths.push(pathToDirent);
|
|
1049
|
-
_state.label = 7;
|
|
1050
|
-
case 7:
|
|
1051
|
-
_iteratorAbruptCompletion = false;
|
|
1052
|
-
return [
|
|
1053
|
-
3,
|
|
1054
|
-
3
|
|
1055
|
-
];
|
|
1056
|
-
case 8:
|
|
1057
|
-
return [
|
|
1058
|
-
3,
|
|
1059
|
-
15
|
|
1060
|
-
];
|
|
1061
|
-
case 9:
|
|
1062
|
-
err = _state.sent();
|
|
1063
|
-
_didIteratorError = true;
|
|
1064
|
-
_iteratorError = err;
|
|
1065
|
-
return [
|
|
1066
|
-
3,
|
|
1067
|
-
15
|
|
1068
|
-
];
|
|
1069
|
-
case 10:
|
|
1070
|
-
_state.trys.push([
|
|
1071
|
-
10,
|
|
1072
|
-
,
|
|
1073
|
-
13,
|
|
1074
|
-
14
|
|
1075
|
-
]);
|
|
1076
|
-
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
1077
|
-
3,
|
|
1078
|
-
12
|
|
1079
|
-
];
|
|
1080
|
-
return [
|
|
1081
|
-
4,
|
|
1082
|
-
_iterator.return()
|
|
1083
|
-
];
|
|
1084
|
-
case 11:
|
|
1085
|
-
_state.sent();
|
|
1086
|
-
_state.label = 12;
|
|
1087
|
-
case 12:
|
|
1088
|
-
return [
|
|
1089
|
-
3,
|
|
1090
|
-
14
|
|
1091
|
-
];
|
|
1092
|
-
case 13:
|
|
1093
|
-
if (_didIteratorError) {
|
|
1094
|
-
throw _iteratorError;
|
|
1095
|
-
}
|
|
1096
|
-
return [
|
|
1097
|
-
7
|
|
1098
|
-
];
|
|
1099
|
-
case 14:
|
|
1100
|
-
return [
|
|
1101
|
-
7
|
|
1102
|
-
];
|
|
1103
|
-
case 15:
|
|
1104
|
-
return [
|
|
1105
|
-
2,
|
|
1106
|
-
allFilePaths
|
|
1107
|
-
];
|
|
1108
|
-
}
|
|
1109
|
-
});
|
|
1110
|
-
});
|
|
1111
|
-
return function readAllFilesInsideDirectory(directory) {
|
|
1112
|
-
return _ref.apply(this, arguments);
|
|
1113
|
-
};
|
|
1114
|
-
}();
|
|
1115
|
-
var isJavascriptModule = function(filePath) {
|
|
1116
|
-
var extensionName = import_node_path6.default.extname(filePath);
|
|
1117
|
-
return [
|
|
1118
|
-
".js",
|
|
1119
|
-
".ts",
|
|
1120
|
-
".jsx",
|
|
1121
|
-
".tsx",
|
|
1122
|
-
".mjs",
|
|
1123
|
-
".cjs"
|
|
1124
|
-
].includes(extensionName);
|
|
1125
|
-
};
|
|
1126
|
-
var checkFileExtensionsUntilItExists = function(pathWithoutExtension) {
|
|
1127
|
-
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".ts"))) {
|
|
1128
|
-
return "".concat(pathWithoutExtension, ".ts");
|
|
1129
|
-
}
|
|
1130
|
-
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".tsx"))) {
|
|
1131
|
-
return "".concat(pathWithoutExtension, ".tsx");
|
|
1132
|
-
}
|
|
1133
|
-
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".js"))) {
|
|
1134
|
-
return "".concat(pathWithoutExtension, ".js");
|
|
1135
|
-
}
|
|
1136
|
-
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".jsx"))) {
|
|
1137
|
-
return "".concat(pathWithoutExtension, ".jsx");
|
|
1138
|
-
}
|
|
1139
|
-
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".mjs"))) {
|
|
1140
|
-
return "".concat(pathWithoutExtension, ".mjs");
|
|
1141
|
-
}
|
|
1142
|
-
if ((0, import_node_fs4.existsSync)("".concat(pathWithoutExtension, ".cjs"))) {
|
|
1143
|
-
return "".concat(pathWithoutExtension, ".cjs");
|
|
523
|
+
var readAllFilesInsideDirectory = async (directory) => {
|
|
524
|
+
let allFilePaths = [];
|
|
525
|
+
const topLevelDirents = await import_node_fs4.promises.readdir(directory, { withFileTypes: true });
|
|
526
|
+
for await (const dirent of topLevelDirents) {
|
|
527
|
+
const pathToDirent = import_node_path6.default.join(directory, dirent.name);
|
|
528
|
+
if (dirent.isDirectory()) {
|
|
529
|
+
allFilePaths = allFilePaths.concat(
|
|
530
|
+
await readAllFilesInsideDirectory(pathToDirent)
|
|
531
|
+
);
|
|
532
|
+
} else {
|
|
533
|
+
allFilePaths.push(pathToDirent);
|
|
1144
534
|
}
|
|
535
|
+
}
|
|
536
|
+
return allFilePaths;
|
|
537
|
+
};
|
|
538
|
+
var isJavascriptModule = (filePath) => {
|
|
539
|
+
const extensionName = import_node_path6.default.extname(filePath);
|
|
540
|
+
return [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"].includes(extensionName);
|
|
541
|
+
};
|
|
542
|
+
var checkFileExtensionsUntilItExists = (pathWithoutExtension) => {
|
|
543
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.ts`)) {
|
|
544
|
+
return `${pathWithoutExtension}.ts`;
|
|
545
|
+
}
|
|
546
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.tsx`)) {
|
|
547
|
+
return `${pathWithoutExtension}.tsx`;
|
|
548
|
+
}
|
|
549
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.js`)) {
|
|
550
|
+
return `${pathWithoutExtension}.js`;
|
|
551
|
+
}
|
|
552
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.jsx`)) {
|
|
553
|
+
return `${pathWithoutExtension}.jsx`;
|
|
554
|
+
}
|
|
555
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.mjs`)) {
|
|
556
|
+
return `${pathWithoutExtension}.mjs`;
|
|
557
|
+
}
|
|
558
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.cjs`)) {
|
|
559
|
+
return `${pathWithoutExtension}.cjs`;
|
|
560
|
+
}
|
|
1145
561
|
};
|
|
1146
|
-
var createDependencyGraph =
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
var _ref = _async_to_generator(function(filePath) {
|
|
1172
|
-
var contents, importedPaths, importedPathsRelativeToDirectory, moduleDependencies, nonNodeModuleImportPathsRelativeToDirectory;
|
|
1173
|
-
return _ts_generator(this, function(_state) {
|
|
1174
|
-
switch(_state.label){
|
|
1175
|
-
case 0:
|
|
1176
|
-
return [
|
|
1177
|
-
4,
|
|
1178
|
-
import_node_fs4.promises.readFile(filePath, "utf8")
|
|
1179
|
-
];
|
|
1180
|
-
case 1:
|
|
1181
|
-
contents = _state.sent();
|
|
1182
|
-
importedPaths = getImportedModules(contents);
|
|
1183
|
-
importedPathsRelativeToDirectory = importedPaths.map(function(dependencyPath) {
|
|
1184
|
-
var isModulePath = !dependencyPath.startsWith(".");
|
|
1185
|
-
if (isModulePath || import_node_path6.default.isAbsolute(dependencyPath)) {
|
|
1186
|
-
return dependencyPath;
|
|
1187
|
-
}
|
|
1188
|
-
var pathToDependencyFromDirectory = import_node_path6.default.resolve(/*
|
|
562
|
+
var createDependencyGraph = async (directory) => {
|
|
563
|
+
const filePaths = await readAllFilesInsideDirectory(directory);
|
|
564
|
+
const modulePaths = filePaths.filter(isJavascriptModule);
|
|
565
|
+
const graph = Object.fromEntries(
|
|
566
|
+
modulePaths.map((path12) => [
|
|
567
|
+
path12,
|
|
568
|
+
{
|
|
569
|
+
path: path12,
|
|
570
|
+
dependencyPaths: [],
|
|
571
|
+
dependentPaths: [],
|
|
572
|
+
moduleDependencies: []
|
|
573
|
+
}
|
|
574
|
+
])
|
|
575
|
+
);
|
|
576
|
+
const getDependencyPaths = async (filePath) => {
|
|
577
|
+
const contents = await import_node_fs4.promises.readFile(filePath, "utf8");
|
|
578
|
+
const importedPaths = getImportedModules(contents);
|
|
579
|
+
const importedPathsRelativeToDirectory = importedPaths.map(
|
|
580
|
+
(dependencyPath) => {
|
|
581
|
+
const isModulePath = !dependencyPath.startsWith(".");
|
|
582
|
+
if (isModulePath || import_node_path6.default.isAbsolute(dependencyPath)) {
|
|
583
|
+
return dependencyPath;
|
|
584
|
+
}
|
|
585
|
+
let pathToDependencyFromDirectory = import_node_path6.default.resolve(
|
|
586
|
+
/*
|
|
1189
587
|
path.resolve resolves paths differently from what imports on javascript do.
|
|
1190
588
|
|
|
1191
589
|
So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependecy path of "./other-email"
|
|
1192
590
|
would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
|
|
1193
591
|
one the import is meant to go to
|
|
1194
|
-
*/
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
var _graph_moduleFilePath, module2, _ref, moduleDependencies, newDependencyPaths, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, dependencyPath, dependencyModule, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, dependencyPath1, dependencyModule1;
|
|
1241
|
-
return _ts_generator(this, function(_state) {
|
|
1242
|
-
switch(_state.label){
|
|
1243
|
-
case 0:
|
|
1244
|
-
module2 = (_graph_moduleFilePath = graph[moduleFilePath]) !== null && _graph_moduleFilePath !== void 0 ? _graph_moduleFilePath : {
|
|
1245
|
-
path: moduleFilePath,
|
|
1246
|
-
dependencyPaths: [],
|
|
1247
|
-
dependentPaths: [],
|
|
1248
|
-
moduleDependencies: []
|
|
1249
|
-
};
|
|
1250
|
-
return [
|
|
1251
|
-
4,
|
|
1252
|
-
getDependencyPaths(moduleFilePath)
|
|
1253
|
-
];
|
|
1254
|
-
case 1:
|
|
1255
|
-
_ref = _state.sent(), moduleDependencies = _ref.moduleDependencies, newDependencyPaths = _ref.dependencyPaths;
|
|
1256
|
-
module2.moduleDependencies = moduleDependencies;
|
|
1257
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1258
|
-
try {
|
|
1259
|
-
for(_iterator = module2.dependencyPaths[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1260
|
-
dependencyPath = _step.value;
|
|
1261
|
-
if (newDependencyPaths.includes(dependencyPath)) continue;
|
|
1262
|
-
dependencyModule = graph[dependencyPath];
|
|
1263
|
-
if (dependencyModule !== void 0) {
|
|
1264
|
-
dependencyModule.dependentPaths = dependencyModule.dependentPaths.filter(function(dependentPath) {
|
|
1265
|
-
return dependentPath !== moduleFilePath;
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
} catch (err) {
|
|
1270
|
-
_didIteratorError = true;
|
|
1271
|
-
_iteratorError = err;
|
|
1272
|
-
} finally{
|
|
1273
|
-
try {
|
|
1274
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1275
|
-
_iterator.return();
|
|
1276
|
-
}
|
|
1277
|
-
} finally{
|
|
1278
|
-
if (_didIteratorError) {
|
|
1279
|
-
throw _iteratorError;
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
module2.dependencyPaths = newDependencyPaths;
|
|
1284
|
-
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
1285
|
-
try {
|
|
1286
|
-
for(_iterator1 = newDependencyPaths[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
1287
|
-
dependencyPath1 = _step1.value;
|
|
1288
|
-
dependencyModule1 = graph[dependencyPath1];
|
|
1289
|
-
if (dependencyModule1 !== void 0 && !dependencyModule1.dependentPaths.includes(moduleFilePath)) {
|
|
1290
|
-
dependencyModule1.dependentPaths.push(moduleFilePath);
|
|
1291
|
-
} else {
|
|
1292
|
-
graph[dependencyPath1] = {
|
|
1293
|
-
path: dependencyPath1,
|
|
1294
|
-
moduleDependencies: [],
|
|
1295
|
-
dependencyPaths: [],
|
|
1296
|
-
dependentPaths: [
|
|
1297
|
-
moduleFilePath
|
|
1298
|
-
]
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
} catch (err) {
|
|
1303
|
-
_didIteratorError1 = true;
|
|
1304
|
-
_iteratorError1 = err;
|
|
1305
|
-
} finally{
|
|
1306
|
-
try {
|
|
1307
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
1308
|
-
_iterator1.return();
|
|
1309
|
-
}
|
|
1310
|
-
} finally{
|
|
1311
|
-
if (_didIteratorError1) {
|
|
1312
|
-
throw _iteratorError1;
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
graph[moduleFilePath] = module2;
|
|
1317
|
-
return [
|
|
1318
|
-
2
|
|
1319
|
-
];
|
|
1320
|
-
}
|
|
1321
|
-
});
|
|
1322
|
-
});
|
|
1323
|
-
return function updateModuleDependenciesInGraph(moduleFilePath) {
|
|
1324
|
-
return _ref.apply(this, arguments);
|
|
1325
|
-
};
|
|
1326
|
-
}();
|
|
1327
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1328
|
-
_state.label = 2;
|
|
1329
|
-
case 2:
|
|
1330
|
-
_state.trys.push([
|
|
1331
|
-
2,
|
|
1332
|
-
7,
|
|
1333
|
-
8,
|
|
1334
|
-
9
|
|
1335
|
-
]);
|
|
1336
|
-
_iterator = modulePaths[Symbol.iterator]();
|
|
1337
|
-
_state.label = 3;
|
|
1338
|
-
case 3:
|
|
1339
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
1340
|
-
3,
|
|
1341
|
-
6
|
|
1342
|
-
];
|
|
1343
|
-
filePath = _step.value;
|
|
1344
|
-
return [
|
|
1345
|
-
4,
|
|
1346
|
-
updateModuleDependenciesInGraph(filePath)
|
|
1347
|
-
];
|
|
1348
|
-
case 4:
|
|
1349
|
-
_state.sent();
|
|
1350
|
-
_state.label = 5;
|
|
1351
|
-
case 5:
|
|
1352
|
-
_iteratorNormalCompletion = true;
|
|
1353
|
-
return [
|
|
1354
|
-
3,
|
|
1355
|
-
3
|
|
1356
|
-
];
|
|
1357
|
-
case 6:
|
|
1358
|
-
return [
|
|
1359
|
-
3,
|
|
1360
|
-
9
|
|
1361
|
-
];
|
|
1362
|
-
case 7:
|
|
1363
|
-
err = _state.sent();
|
|
1364
|
-
_didIteratorError = true;
|
|
1365
|
-
_iteratorError = err;
|
|
1366
|
-
return [
|
|
1367
|
-
3,
|
|
1368
|
-
9
|
|
1369
|
-
];
|
|
1370
|
-
case 8:
|
|
1371
|
-
try {
|
|
1372
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1373
|
-
_iterator.return();
|
|
1374
|
-
}
|
|
1375
|
-
} finally{
|
|
1376
|
-
if (_didIteratorError) {
|
|
1377
|
-
throw _iteratorError;
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
return [
|
|
1381
|
-
7
|
|
1382
|
-
];
|
|
1383
|
-
case 9:
|
|
1384
|
-
removeModuleFromGraph = function(filePath) {
|
|
1385
|
-
var module2 = graph[filePath];
|
|
1386
|
-
if (module2) {
|
|
1387
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1388
|
-
try {
|
|
1389
|
-
for(var _iterator = module2.dependencyPaths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1390
|
-
var dependencyPath = _step.value;
|
|
1391
|
-
if (graph[dependencyPath]) {
|
|
1392
|
-
graph[dependencyPath].dependentPaths = graph[dependencyPath].dependentPaths.filter(function(dependentPath) {
|
|
1393
|
-
return dependentPath !== filePath;
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
} catch (err) {
|
|
1398
|
-
_didIteratorError = true;
|
|
1399
|
-
_iteratorError = err;
|
|
1400
|
-
} finally{
|
|
1401
|
-
try {
|
|
1402
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1403
|
-
_iterator.return();
|
|
1404
|
-
}
|
|
1405
|
-
} finally{
|
|
1406
|
-
if (_didIteratorError) {
|
|
1407
|
-
throw _iteratorError;
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
delete graph[filePath];
|
|
1412
|
-
}
|
|
1413
|
-
};
|
|
1414
|
-
return [
|
|
1415
|
-
2,
|
|
1416
|
-
[
|
|
1417
|
-
graph,
|
|
1418
|
-
function() {
|
|
1419
|
-
var _ref = _async_to_generator(function(event, pathToModified) {
|
|
1420
|
-
var filesInsideAddedDirectory, modulesInsideAddedDirectory, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, filePath, err, filesInsideDeletedDirectory, modulesInsideDeletedDirectory, _iteratorAbruptCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _value1, filePath1, err1;
|
|
1421
|
-
return _ts_generator(this, function(_state) {
|
|
1422
|
-
switch(_state.label){
|
|
1423
|
-
case 0:
|
|
1424
|
-
switch(event){
|
|
1425
|
-
case "change":
|
|
1426
|
-
return [
|
|
1427
|
-
3,
|
|
1428
|
-
1
|
|
1429
|
-
];
|
|
1430
|
-
case "add":
|
|
1431
|
-
return [
|
|
1432
|
-
3,
|
|
1433
|
-
4
|
|
1434
|
-
];
|
|
1435
|
-
case "addDir":
|
|
1436
|
-
return [
|
|
1437
|
-
3,
|
|
1438
|
-
7
|
|
1439
|
-
];
|
|
1440
|
-
case "unlink":
|
|
1441
|
-
return [
|
|
1442
|
-
3,
|
|
1443
|
-
22
|
|
1444
|
-
];
|
|
1445
|
-
case "unlinkDir":
|
|
1446
|
-
return [
|
|
1447
|
-
3,
|
|
1448
|
-
23
|
|
1449
|
-
];
|
|
1450
|
-
}
|
|
1451
|
-
return [
|
|
1452
|
-
3,
|
|
1453
|
-
37
|
|
1454
|
-
];
|
|
1455
|
-
case 1:
|
|
1456
|
-
if (!isJavascriptModule(pathToModified)) return [
|
|
1457
|
-
3,
|
|
1458
|
-
3
|
|
1459
|
-
];
|
|
1460
|
-
return [
|
|
1461
|
-
4,
|
|
1462
|
-
updateModuleDependenciesInGraph(pathToModified)
|
|
1463
|
-
];
|
|
1464
|
-
case 2:
|
|
1465
|
-
_state.sent();
|
|
1466
|
-
_state.label = 3;
|
|
1467
|
-
case 3:
|
|
1468
|
-
return [
|
|
1469
|
-
3,
|
|
1470
|
-
37
|
|
1471
|
-
];
|
|
1472
|
-
case 4:
|
|
1473
|
-
if (!isJavascriptModule(pathToModified)) return [
|
|
1474
|
-
3,
|
|
1475
|
-
6
|
|
1476
|
-
];
|
|
1477
|
-
return [
|
|
1478
|
-
4,
|
|
1479
|
-
updateModuleDependenciesInGraph(pathToModified)
|
|
1480
|
-
];
|
|
1481
|
-
case 5:
|
|
1482
|
-
_state.sent();
|
|
1483
|
-
_state.label = 6;
|
|
1484
|
-
case 6:
|
|
1485
|
-
return [
|
|
1486
|
-
3,
|
|
1487
|
-
37
|
|
1488
|
-
];
|
|
1489
|
-
case 7:
|
|
1490
|
-
return [
|
|
1491
|
-
4,
|
|
1492
|
-
readAllFilesInsideDirectory(pathToModified)
|
|
1493
|
-
];
|
|
1494
|
-
case 8:
|
|
1495
|
-
filesInsideAddedDirectory = _state.sent();
|
|
1496
|
-
modulesInsideAddedDirectory = filesInsideAddedDirectory.filter(isJavascriptModule);
|
|
1497
|
-
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
1498
|
-
_state.label = 9;
|
|
1499
|
-
case 9:
|
|
1500
|
-
_state.trys.push([
|
|
1501
|
-
9,
|
|
1502
|
-
15,
|
|
1503
|
-
16,
|
|
1504
|
-
21
|
|
1505
|
-
]);
|
|
1506
|
-
_iterator = _async_iterator(modulesInsideAddedDirectory);
|
|
1507
|
-
_state.label = 10;
|
|
1508
|
-
case 10:
|
|
1509
|
-
return [
|
|
1510
|
-
4,
|
|
1511
|
-
_iterator.next()
|
|
1512
|
-
];
|
|
1513
|
-
case 11:
|
|
1514
|
-
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
1515
|
-
3,
|
|
1516
|
-
14
|
|
1517
|
-
];
|
|
1518
|
-
_value = _step.value;
|
|
1519
|
-
filePath = _value;
|
|
1520
|
-
return [
|
|
1521
|
-
4,
|
|
1522
|
-
updateModuleDependenciesInGraph(filePath)
|
|
1523
|
-
];
|
|
1524
|
-
case 12:
|
|
1525
|
-
_state.sent();
|
|
1526
|
-
_state.label = 13;
|
|
1527
|
-
case 13:
|
|
1528
|
-
_iteratorAbruptCompletion = false;
|
|
1529
|
-
return [
|
|
1530
|
-
3,
|
|
1531
|
-
10
|
|
1532
|
-
];
|
|
1533
|
-
case 14:
|
|
1534
|
-
return [
|
|
1535
|
-
3,
|
|
1536
|
-
21
|
|
1537
|
-
];
|
|
1538
|
-
case 15:
|
|
1539
|
-
err = _state.sent();
|
|
1540
|
-
_didIteratorError = true;
|
|
1541
|
-
_iteratorError = err;
|
|
1542
|
-
return [
|
|
1543
|
-
3,
|
|
1544
|
-
21
|
|
1545
|
-
];
|
|
1546
|
-
case 16:
|
|
1547
|
-
_state.trys.push([
|
|
1548
|
-
16,
|
|
1549
|
-
,
|
|
1550
|
-
19,
|
|
1551
|
-
20
|
|
1552
|
-
]);
|
|
1553
|
-
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
1554
|
-
3,
|
|
1555
|
-
18
|
|
1556
|
-
];
|
|
1557
|
-
return [
|
|
1558
|
-
4,
|
|
1559
|
-
_iterator.return()
|
|
1560
|
-
];
|
|
1561
|
-
case 17:
|
|
1562
|
-
_state.sent();
|
|
1563
|
-
_state.label = 18;
|
|
1564
|
-
case 18:
|
|
1565
|
-
return [
|
|
1566
|
-
3,
|
|
1567
|
-
20
|
|
1568
|
-
];
|
|
1569
|
-
case 19:
|
|
1570
|
-
if (_didIteratorError) {
|
|
1571
|
-
throw _iteratorError;
|
|
1572
|
-
}
|
|
1573
|
-
return [
|
|
1574
|
-
7
|
|
1575
|
-
];
|
|
1576
|
-
case 20:
|
|
1577
|
-
return [
|
|
1578
|
-
7
|
|
1579
|
-
];
|
|
1580
|
-
case 21:
|
|
1581
|
-
return [
|
|
1582
|
-
3,
|
|
1583
|
-
37
|
|
1584
|
-
];
|
|
1585
|
-
case 22:
|
|
1586
|
-
if (isJavascriptModule(pathToModified)) {
|
|
1587
|
-
removeModuleFromGraph(pathToModified);
|
|
1588
|
-
}
|
|
1589
|
-
return [
|
|
1590
|
-
3,
|
|
1591
|
-
37
|
|
1592
|
-
];
|
|
1593
|
-
case 23:
|
|
1594
|
-
return [
|
|
1595
|
-
4,
|
|
1596
|
-
readAllFilesInsideDirectory(pathToModified)
|
|
1597
|
-
];
|
|
1598
|
-
case 24:
|
|
1599
|
-
filesInsideDeletedDirectory = _state.sent();
|
|
1600
|
-
modulesInsideDeletedDirectory = filesInsideDeletedDirectory.filter(isJavascriptModule);
|
|
1601
|
-
_iteratorAbruptCompletion1 = false, _didIteratorError1 = false;
|
|
1602
|
-
_state.label = 25;
|
|
1603
|
-
case 25:
|
|
1604
|
-
_state.trys.push([
|
|
1605
|
-
25,
|
|
1606
|
-
30,
|
|
1607
|
-
31,
|
|
1608
|
-
36
|
|
1609
|
-
]);
|
|
1610
|
-
_iterator1 = _async_iterator(modulesInsideDeletedDirectory);
|
|
1611
|
-
_state.label = 26;
|
|
1612
|
-
case 26:
|
|
1613
|
-
return [
|
|
1614
|
-
4,
|
|
1615
|
-
_iterator1.next()
|
|
1616
|
-
];
|
|
1617
|
-
case 27:
|
|
1618
|
-
if (!(_iteratorAbruptCompletion1 = !(_step1 = _state.sent()).done)) return [
|
|
1619
|
-
3,
|
|
1620
|
-
29
|
|
1621
|
-
];
|
|
1622
|
-
_value1 = _step1.value;
|
|
1623
|
-
filePath1 = _value1;
|
|
1624
|
-
removeModuleFromGraph(filePath1);
|
|
1625
|
-
_state.label = 28;
|
|
1626
|
-
case 28:
|
|
1627
|
-
_iteratorAbruptCompletion1 = false;
|
|
1628
|
-
return [
|
|
1629
|
-
3,
|
|
1630
|
-
26
|
|
1631
|
-
];
|
|
1632
|
-
case 29:
|
|
1633
|
-
return [
|
|
1634
|
-
3,
|
|
1635
|
-
36
|
|
1636
|
-
];
|
|
1637
|
-
case 30:
|
|
1638
|
-
err1 = _state.sent();
|
|
1639
|
-
_didIteratorError1 = true;
|
|
1640
|
-
_iteratorError1 = err1;
|
|
1641
|
-
return [
|
|
1642
|
-
3,
|
|
1643
|
-
36
|
|
1644
|
-
];
|
|
1645
|
-
case 31:
|
|
1646
|
-
_state.trys.push([
|
|
1647
|
-
31,
|
|
1648
|
-
,
|
|
1649
|
-
34,
|
|
1650
|
-
35
|
|
1651
|
-
]);
|
|
1652
|
-
if (!(_iteratorAbruptCompletion1 && _iterator1.return != null)) return [
|
|
1653
|
-
3,
|
|
1654
|
-
33
|
|
1655
|
-
];
|
|
1656
|
-
return [
|
|
1657
|
-
4,
|
|
1658
|
-
_iterator1.return()
|
|
1659
|
-
];
|
|
1660
|
-
case 32:
|
|
1661
|
-
_state.sent();
|
|
1662
|
-
_state.label = 33;
|
|
1663
|
-
case 33:
|
|
1664
|
-
return [
|
|
1665
|
-
3,
|
|
1666
|
-
35
|
|
1667
|
-
];
|
|
1668
|
-
case 34:
|
|
1669
|
-
if (_didIteratorError1) {
|
|
1670
|
-
throw _iteratorError1;
|
|
1671
|
-
}
|
|
1672
|
-
return [
|
|
1673
|
-
7
|
|
1674
|
-
];
|
|
1675
|
-
case 35:
|
|
1676
|
-
return [
|
|
1677
|
-
7
|
|
1678
|
-
];
|
|
1679
|
-
case 36:
|
|
1680
|
-
return [
|
|
1681
|
-
3,
|
|
1682
|
-
37
|
|
1683
|
-
];
|
|
1684
|
-
case 37:
|
|
1685
|
-
return [
|
|
1686
|
-
2
|
|
1687
|
-
];
|
|
1688
|
-
}
|
|
1689
|
-
});
|
|
1690
|
-
});
|
|
1691
|
-
return function(event, pathToModified) {
|
|
1692
|
-
return _ref.apply(this, arguments);
|
|
1693
|
-
};
|
|
1694
|
-
}(),
|
|
1695
|
-
{
|
|
1696
|
-
resolveDependentsOf: function resolveDependentsOf(pathToModule) {
|
|
1697
|
-
var moduleEntry = graph[pathToModule];
|
|
1698
|
-
var dependentPaths = [];
|
|
1699
|
-
if (moduleEntry) {
|
|
1700
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1701
|
-
try {
|
|
1702
|
-
for(var _iterator = moduleEntry.dependentPaths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1703
|
-
var dependentPath = _step.value;
|
|
1704
|
-
var _dependentPaths;
|
|
1705
|
-
var dependentsOfDependent = resolveDependentsOf(dependentPath);
|
|
1706
|
-
(_dependentPaths = dependentPaths).push.apply(_dependentPaths, _to_consumable_array(dependentsOfDependent));
|
|
1707
|
-
dependentPaths.push(dependentPath);
|
|
1708
|
-
}
|
|
1709
|
-
} catch (err) {
|
|
1710
|
-
_didIteratorError = true;
|
|
1711
|
-
_iteratorError = err;
|
|
1712
|
-
} finally{
|
|
1713
|
-
try {
|
|
1714
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1715
|
-
_iterator.return();
|
|
1716
|
-
}
|
|
1717
|
-
} finally{
|
|
1718
|
-
if (_didIteratorError) {
|
|
1719
|
-
throw _iteratorError;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
return dependentPaths;
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
]
|
|
1728
|
-
];
|
|
1729
|
-
}
|
|
1730
|
-
});
|
|
1731
|
-
});
|
|
1732
|
-
return function createDependencyGraph(directory) {
|
|
1733
|
-
return _ref.apply(this, arguments);
|
|
592
|
+
*/
|
|
593
|
+
import_node_path6.default.dirname(filePath),
|
|
594
|
+
dependencyPath
|
|
595
|
+
);
|
|
596
|
+
let isDirectory = false;
|
|
597
|
+
try {
|
|
598
|
+
isDirectory = (0, import_node_fs4.statSync)(pathToDependencyFromDirectory).isDirectory();
|
|
599
|
+
} catch (_) {
|
|
600
|
+
}
|
|
601
|
+
if (isDirectory) {
|
|
602
|
+
const pathToSubDirectory = pathToDependencyFromDirectory;
|
|
603
|
+
const pathWithExtension = checkFileExtensionsUntilItExists(
|
|
604
|
+
`${pathToSubDirectory}/index`
|
|
605
|
+
);
|
|
606
|
+
if (pathWithExtension) {
|
|
607
|
+
pathToDependencyFromDirectory = pathWithExtension;
|
|
608
|
+
} else if (isDev) {
|
|
609
|
+
console.warn(
|
|
610
|
+
`Could not find index file for directory at ${pathToDependencyFromDirectory}. This is probably going to cause issues with both hot reloading and your code.`
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (!isJavascriptModule(pathToDependencyFromDirectory)) {
|
|
615
|
+
const pathWithExtension = checkFileExtensionsUntilItExists(
|
|
616
|
+
pathToDependencyFromDirectory
|
|
617
|
+
);
|
|
618
|
+
if (pathWithExtension) {
|
|
619
|
+
pathToDependencyFromDirectory = pathWithExtension;
|
|
620
|
+
} else if (isDev) {
|
|
621
|
+
console.warn(
|
|
622
|
+
`Could not determine the file extension for the file at ${pathToDependencyFromDirectory}`
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return pathToDependencyFromDirectory;
|
|
627
|
+
}
|
|
628
|
+
);
|
|
629
|
+
const moduleDependencies = importedPathsRelativeToDirectory.filter(
|
|
630
|
+
(dependencyPath) => !dependencyPath.startsWith(".") && !import_node_path6.default.isAbsolute(dependencyPath)
|
|
631
|
+
);
|
|
632
|
+
const nonNodeModuleImportPathsRelativeToDirectory = importedPathsRelativeToDirectory.filter(
|
|
633
|
+
(dependencyPath) => dependencyPath.startsWith(".") || import_node_path6.default.isAbsolute(dependencyPath)
|
|
634
|
+
);
|
|
635
|
+
return {
|
|
636
|
+
dependencyPaths: nonNodeModuleImportPathsRelativeToDirectory,
|
|
637
|
+
moduleDependencies
|
|
1734
638
|
};
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
case 0:
|
|
1743
|
-
clients = [];
|
|
1744
|
-
io = new import_socket.Server(devServer2);
|
|
1745
|
-
io.on("connection", function(client) {
|
|
1746
|
-
clients.push(client);
|
|
1747
|
-
client.on("disconnect", function() {
|
|
1748
|
-
clients = clients.filter(function(item) {
|
|
1749
|
-
return item !== client;
|
|
1750
|
-
});
|
|
1751
|
-
});
|
|
1752
|
-
});
|
|
1753
|
-
changes = [];
|
|
1754
|
-
reload = (0, import_debounce.default)(function() {
|
|
1755
|
-
clients.forEach(function(client) {
|
|
1756
|
-
client.emit("reload", changes);
|
|
1757
|
-
});
|
|
1758
|
-
changes = [];
|
|
1759
|
-
}, 150);
|
|
1760
|
-
absolutePathToEmailsDirectory = import_node_path7.default.resolve(process.cwd(), emailDirRelativePath);
|
|
1761
|
-
return [
|
|
1762
|
-
4,
|
|
1763
|
-
createDependencyGraph(absolutePathToEmailsDirectory)
|
|
1764
|
-
];
|
|
1765
|
-
case 1:
|
|
1766
|
-
_ref = _sliced_to_array.apply(void 0, [
|
|
1767
|
-
_state.sent(),
|
|
1768
|
-
3
|
|
1769
|
-
]), dependencyGraph = _ref[0], updateDependencyGraph = _ref[1], resolveDependentsOf = _ref[2].resolveDependentsOf;
|
|
1770
|
-
watcher = (0, import_chokidar.watch)("", {
|
|
1771
|
-
ignoreInitial: true,
|
|
1772
|
-
cwd: absolutePathToEmailsDirectory
|
|
1773
|
-
});
|
|
1774
|
-
getFilesOutsideEmailsDirectory = function() {
|
|
1775
|
-
return Object.keys(dependencyGraph).filter(function(p) {
|
|
1776
|
-
return import_node_path7.default.relative(absolutePathToEmailsDirectory, p).startsWith("..");
|
|
1777
|
-
});
|
|
1778
|
-
};
|
|
1779
|
-
filesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
1780
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1781
|
-
try {
|
|
1782
|
-
for(_iterator = filesOutsideEmailsDirectory[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1783
|
-
p = _step.value;
|
|
1784
|
-
watcher.add(p);
|
|
1785
|
-
}
|
|
1786
|
-
} catch (err) {
|
|
1787
|
-
_didIteratorError = true;
|
|
1788
|
-
_iteratorError = err;
|
|
1789
|
-
} finally{
|
|
1790
|
-
try {
|
|
1791
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1792
|
-
_iterator.return();
|
|
1793
|
-
}
|
|
1794
|
-
} finally{
|
|
1795
|
-
if (_didIteratorError) {
|
|
1796
|
-
throw _iteratorError;
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
exit = function() {
|
|
1801
|
-
var _ref = _async_to_generator(function() {
|
|
1802
|
-
return _ts_generator(this, function(_state) {
|
|
1803
|
-
switch(_state.label){
|
|
1804
|
-
case 0:
|
|
1805
|
-
return [
|
|
1806
|
-
4,
|
|
1807
|
-
watcher.close()
|
|
1808
|
-
];
|
|
1809
|
-
case 1:
|
|
1810
|
-
_state.sent();
|
|
1811
|
-
return [
|
|
1812
|
-
2
|
|
1813
|
-
];
|
|
1814
|
-
}
|
|
1815
|
-
});
|
|
1816
|
-
});
|
|
1817
|
-
return function exit() {
|
|
1818
|
-
return _ref.apply(this, arguments);
|
|
1819
|
-
};
|
|
1820
|
-
}();
|
|
1821
|
-
process.on("SIGINT", exit);
|
|
1822
|
-
process.on("uncaughtException", exit);
|
|
1823
|
-
watcher.on("all", function() {
|
|
1824
|
-
var _ref = _async_to_generator(function(event, relativePathToChangeTarget) {
|
|
1825
|
-
var file, pathToChangeTarget, newFilesOutsideEmailsDirectory, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, p, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, p1, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, dependentPath;
|
|
1826
|
-
return _ts_generator(this, function(_state) {
|
|
1827
|
-
switch(_state.label){
|
|
1828
|
-
case 0:
|
|
1829
|
-
file = relativePathToChangeTarget.split(import_node_path7.default.sep);
|
|
1830
|
-
if (file.length === 0) {
|
|
1831
|
-
return [
|
|
1832
|
-
2
|
|
1833
|
-
];
|
|
1834
|
-
}
|
|
1835
|
-
pathToChangeTarget = import_node_path7.default.resolve(absolutePathToEmailsDirectory, relativePathToChangeTarget);
|
|
1836
|
-
return [
|
|
1837
|
-
4,
|
|
1838
|
-
updateDependencyGraph(event, pathToChangeTarget)
|
|
1839
|
-
];
|
|
1840
|
-
case 1:
|
|
1841
|
-
_state.sent();
|
|
1842
|
-
newFilesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
1843
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1844
|
-
try {
|
|
1845
|
-
for(_iterator = filesOutsideEmailsDirectory[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1846
|
-
p = _step.value;
|
|
1847
|
-
if (!newFilesOutsideEmailsDirectory.includes(p)) {
|
|
1848
|
-
watcher.unwatch(p);
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
} catch (err) {
|
|
1852
|
-
_didIteratorError = true;
|
|
1853
|
-
_iteratorError = err;
|
|
1854
|
-
} finally{
|
|
1855
|
-
try {
|
|
1856
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1857
|
-
_iterator.return();
|
|
1858
|
-
}
|
|
1859
|
-
} finally{
|
|
1860
|
-
if (_didIteratorError) {
|
|
1861
|
-
throw _iteratorError;
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
1866
|
-
try {
|
|
1867
|
-
for(_iterator1 = newFilesOutsideEmailsDirectory[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
1868
|
-
p1 = _step1.value;
|
|
1869
|
-
if (!filesOutsideEmailsDirectory.includes(p1)) {
|
|
1870
|
-
watcher.add(p1);
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
} catch (err) {
|
|
1874
|
-
_didIteratorError1 = true;
|
|
1875
|
-
_iteratorError1 = err;
|
|
1876
|
-
} finally{
|
|
1877
|
-
try {
|
|
1878
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
1879
|
-
_iterator1.return();
|
|
1880
|
-
}
|
|
1881
|
-
} finally{
|
|
1882
|
-
if (_didIteratorError1) {
|
|
1883
|
-
throw _iteratorError1;
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
filesOutsideEmailsDirectory = newFilesOutsideEmailsDirectory;
|
|
1888
|
-
changes.push({
|
|
1889
|
-
event: event,
|
|
1890
|
-
filename: relativePathToChangeTarget
|
|
1891
|
-
});
|
|
1892
|
-
_iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
1893
|
-
try {
|
|
1894
|
-
for(_iterator2 = resolveDependentsOf(pathToChangeTarget)[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
1895
|
-
dependentPath = _step2.value;
|
|
1896
|
-
changes.push({
|
|
1897
|
-
event: "change",
|
|
1898
|
-
filename: import_node_path7.default.relative(absolutePathToEmailsDirectory, dependentPath)
|
|
1899
|
-
});
|
|
1900
|
-
}
|
|
1901
|
-
} catch (err) {
|
|
1902
|
-
_didIteratorError2 = true;
|
|
1903
|
-
_iteratorError2 = err;
|
|
1904
|
-
} finally{
|
|
1905
|
-
try {
|
|
1906
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
1907
|
-
_iterator2.return();
|
|
1908
|
-
}
|
|
1909
|
-
} finally{
|
|
1910
|
-
if (_didIteratorError2) {
|
|
1911
|
-
throw _iteratorError2;
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
reload();
|
|
1916
|
-
return [
|
|
1917
|
-
2
|
|
1918
|
-
];
|
|
1919
|
-
}
|
|
1920
|
-
});
|
|
1921
|
-
});
|
|
1922
|
-
return function(event, relativePathToChangeTarget) {
|
|
1923
|
-
return _ref.apply(this, arguments);
|
|
1924
|
-
};
|
|
1925
|
-
}());
|
|
1926
|
-
return [
|
|
1927
|
-
2,
|
|
1928
|
-
watcher
|
|
1929
|
-
];
|
|
1930
|
-
}
|
|
1931
|
-
});
|
|
1932
|
-
});
|
|
1933
|
-
return function setupHotreloading(devServer2, emailDirRelativePath) {
|
|
1934
|
-
return _ref.apply(this, arguments);
|
|
639
|
+
};
|
|
640
|
+
const updateModuleDependenciesInGraph = async (moduleFilePath) => {
|
|
641
|
+
const module2 = graph[moduleFilePath] ?? {
|
|
642
|
+
path: moduleFilePath,
|
|
643
|
+
dependencyPaths: [],
|
|
644
|
+
dependentPaths: [],
|
|
645
|
+
moduleDependencies: []
|
|
1935
646
|
};
|
|
1936
|
-
}();
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
647
|
+
const { moduleDependencies, dependencyPaths: newDependencyPaths } = await getDependencyPaths(moduleFilePath);
|
|
648
|
+
module2.moduleDependencies = moduleDependencies;
|
|
649
|
+
for (const dependencyPath of module2.dependencyPaths) {
|
|
650
|
+
if (newDependencyPaths.includes(dependencyPath))
|
|
651
|
+
continue;
|
|
652
|
+
const dependencyModule = graph[dependencyPath];
|
|
653
|
+
if (dependencyModule !== void 0) {
|
|
654
|
+
dependencyModule.dependentPaths = dependencyModule.dependentPaths.filter(
|
|
655
|
+
(dependentPath) => dependentPath !== moduleFilePath
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
module2.dependencyPaths = newDependencyPaths;
|
|
660
|
+
for (const dependencyPath of newDependencyPaths) {
|
|
661
|
+
const dependencyModule = graph[dependencyPath];
|
|
662
|
+
if (dependencyModule !== void 0 && !dependencyModule.dependentPaths.includes(moduleFilePath)) {
|
|
663
|
+
dependencyModule.dependentPaths.push(moduleFilePath);
|
|
664
|
+
} else {
|
|
665
|
+
graph[dependencyPath] = {
|
|
666
|
+
path: dependencyPath,
|
|
667
|
+
moduleDependencies: [],
|
|
668
|
+
dependencyPaths: [],
|
|
669
|
+
dependentPaths: [moduleFilePath]
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
graph[moduleFilePath] = module2;
|
|
674
|
+
};
|
|
675
|
+
for (const filePath of modulePaths) {
|
|
676
|
+
await updateModuleDependenciesInGraph(filePath);
|
|
677
|
+
}
|
|
678
|
+
const removeModuleFromGraph = (filePath) => {
|
|
679
|
+
const module2 = graph[filePath];
|
|
680
|
+
if (module2) {
|
|
681
|
+
for (const dependencyPath of module2.dependencyPaths) {
|
|
682
|
+
if (graph[dependencyPath]) {
|
|
683
|
+
graph[dependencyPath].dependentPaths = graph[dependencyPath].dependentPaths.filter(
|
|
684
|
+
(dependentPath) => dependentPath !== filePath
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
delete graph[filePath];
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
return [
|
|
692
|
+
graph,
|
|
693
|
+
async (event, pathToModified) => {
|
|
694
|
+
switch (event) {
|
|
695
|
+
case "change":
|
|
696
|
+
if (isJavascriptModule(pathToModified)) {
|
|
697
|
+
await updateModuleDependenciesInGraph(pathToModified);
|
|
698
|
+
}
|
|
699
|
+
break;
|
|
700
|
+
case "add":
|
|
701
|
+
if (isJavascriptModule(pathToModified)) {
|
|
702
|
+
await updateModuleDependenciesInGraph(pathToModified);
|
|
703
|
+
}
|
|
704
|
+
break;
|
|
705
|
+
case "addDir": {
|
|
706
|
+
const filesInsideAddedDirectory = await readAllFilesInsideDirectory(pathToModified);
|
|
707
|
+
const modulesInsideAddedDirectory = filesInsideAddedDirectory.filter(isJavascriptModule);
|
|
708
|
+
for await (const filePath of modulesInsideAddedDirectory) {
|
|
709
|
+
await updateModuleDependenciesInGraph(filePath);
|
|
710
|
+
}
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
case "unlink":
|
|
714
|
+
if (isJavascriptModule(pathToModified)) {
|
|
715
|
+
removeModuleFromGraph(pathToModified);
|
|
716
|
+
}
|
|
717
|
+
break;
|
|
718
|
+
case "unlinkDir": {
|
|
719
|
+
const filesInsideDeletedDirectory = await readAllFilesInsideDirectory(pathToModified);
|
|
720
|
+
const modulesInsideDeletedDirectory = filesInsideDeletedDirectory.filter(isJavascriptModule);
|
|
721
|
+
for await (const filePath of modulesInsideDeletedDirectory) {
|
|
722
|
+
removeModuleFromGraph(filePath);
|
|
723
|
+
}
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
resolveDependentsOf: function resolveDependentsOf(pathToModule) {
|
|
730
|
+
const moduleEntry = graph[pathToModule];
|
|
731
|
+
const dependentPaths = [];
|
|
732
|
+
if (moduleEntry) {
|
|
733
|
+
for (const dependentPath of moduleEntry.dependentPaths) {
|
|
734
|
+
const dependentsOfDependent = resolveDependentsOf(dependentPath);
|
|
735
|
+
dependentPaths.push(...dependentsOfDependent);
|
|
736
|
+
dependentPaths.push(dependentPath);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return dependentPaths;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
];
|
|
1957
743
|
};
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
import_node_fs5.default.promises.writeFile(import_node_path8.default.resolve(builtPreviewAppPath, "./next.config.js"), nextConfigContents, "utf8")
|
|
1968
|
-
];
|
|
1969
|
-
case 1:
|
|
1970
|
-
_state.sent();
|
|
1971
|
-
return [
|
|
1972
|
-
2
|
|
1973
|
-
];
|
|
1974
|
-
}
|
|
1975
|
-
});
|
|
744
|
+
|
|
745
|
+
// src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
746
|
+
var setupHotreloading = async (devServer2, emailDirRelativePath) => {
|
|
747
|
+
let clients = [];
|
|
748
|
+
const io = new import_socket.Server(devServer2);
|
|
749
|
+
io.on("connection", (client) => {
|
|
750
|
+
clients.push(client);
|
|
751
|
+
client.on("disconnect", () => {
|
|
752
|
+
clients = clients.filter((item) => item !== client);
|
|
1976
753
|
});
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
var directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
|
|
1983
|
-
var slugs = [];
|
|
1984
|
-
emailDirectory.emailFilenames.forEach(function(filename) {
|
|
1985
|
-
return slugs.push(import_node_path8.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path8.default.sep).filter(function(segment) {
|
|
1986
|
-
return segment.length > 0;
|
|
1987
|
-
}));
|
|
754
|
+
});
|
|
755
|
+
let changes = [];
|
|
756
|
+
const reload = (0, import_debounce.default)(() => {
|
|
757
|
+
clients.forEach((client) => {
|
|
758
|
+
client.emit("reload", changes);
|
|
1988
759
|
});
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
760
|
+
changes = [];
|
|
761
|
+
}, 150);
|
|
762
|
+
const absolutePathToEmailsDirectory = import_node_path7.default.resolve(
|
|
763
|
+
process.cwd(),
|
|
764
|
+
emailDirRelativePath
|
|
765
|
+
);
|
|
766
|
+
const [dependencyGraph, updateDependencyGraph, { resolveDependentsOf }] = await createDependencyGraph(absolutePathToEmailsDirectory);
|
|
767
|
+
const watcher = (0, import_chokidar.watch)("", {
|
|
768
|
+
ignoreInitial: true,
|
|
769
|
+
cwd: absolutePathToEmailsDirectory
|
|
770
|
+
});
|
|
771
|
+
const getFilesOutsideEmailsDirectory = () => Object.keys(dependencyGraph).filter(
|
|
772
|
+
(p) => import_node_path7.default.relative(absolutePathToEmailsDirectory, p).startsWith("..")
|
|
773
|
+
);
|
|
774
|
+
let filesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
775
|
+
for (const p of filesOutsideEmailsDirectory) {
|
|
776
|
+
watcher.add(p);
|
|
777
|
+
}
|
|
778
|
+
const exit = async () => {
|
|
779
|
+
await watcher.close();
|
|
780
|
+
};
|
|
781
|
+
process.on("SIGINT", exit);
|
|
782
|
+
process.on("uncaughtException", exit);
|
|
783
|
+
watcher.on("all", async (event, relativePathToChangeTarget) => {
|
|
784
|
+
const file = relativePathToChangeTarget.split(import_node_path7.default.sep);
|
|
785
|
+
if (file.length === 0) {
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
const pathToChangeTarget = import_node_path7.default.resolve(
|
|
789
|
+
absolutePathToEmailsDirectory,
|
|
790
|
+
relativePathToChangeTarget
|
|
791
|
+
);
|
|
792
|
+
await updateDependencyGraph(event, pathToChangeTarget);
|
|
793
|
+
const newFilesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
794
|
+
for (const p of filesOutsideEmailsDirectory) {
|
|
795
|
+
if (!newFilesOutsideEmailsDirectory.includes(p)) {
|
|
796
|
+
watcher.unwatch(p);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
for (const p of newFilesOutsideEmailsDirectory) {
|
|
800
|
+
if (!filesOutsideEmailsDirectory.includes(p)) {
|
|
801
|
+
watcher.add(p);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
filesOutsideEmailsDirectory = newFilesOutsideEmailsDirectory;
|
|
805
|
+
changes.push({
|
|
806
|
+
event,
|
|
807
|
+
filename: relativePathToChangeTarget
|
|
1992
808
|
});
|
|
1993
|
-
|
|
809
|
+
for (const dependentPath of resolveDependentsOf(pathToChangeTarget)) {
|
|
810
|
+
changes.push({
|
|
811
|
+
event: "change",
|
|
812
|
+
filename: import_node_path7.default.relative(absolutePathToEmailsDirectory, dependentPath)
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
reload();
|
|
816
|
+
});
|
|
817
|
+
return watcher;
|
|
1994
818
|
};
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
return [
|
|
2003
|
-
4,
|
|
2004
|
-
getEmailsDirectoryMetadata(emailsDirPath)
|
|
2005
|
-
];
|
|
2006
|
-
case 1:
|
|
2007
|
-
emailDirectoryMetadata = _state.sent();
|
|
2008
|
-
parameters = getEmailSlugsFromEmailDirectory(emailDirectoryMetadata, emailsDirPath).map(function(slug) {
|
|
2009
|
-
return {
|
|
2010
|
-
slug: slug
|
|
2011
|
-
};
|
|
2012
|
-
});
|
|
2013
|
-
removeForceDynamic = function() {
|
|
2014
|
-
var _ref = _async_to_generator(function(filePath) {
|
|
2015
|
-
var contents;
|
|
2016
|
-
return _ts_generator(this, function(_state) {
|
|
2017
|
-
switch(_state.label){
|
|
2018
|
-
case 0:
|
|
2019
|
-
return [
|
|
2020
|
-
4,
|
|
2021
|
-
import_node_fs5.default.promises.readFile(filePath, "utf8")
|
|
2022
|
-
];
|
|
2023
|
-
case 1:
|
|
2024
|
-
contents = _state.sent();
|
|
2025
|
-
return [
|
|
2026
|
-
4,
|
|
2027
|
-
import_node_fs5.default.promises.writeFile(filePath, contents.replace("export const dynamic = 'force-dynamic';", ""), "utf8")
|
|
2028
|
-
];
|
|
2029
|
-
case 2:
|
|
2030
|
-
_state.sent();
|
|
2031
|
-
return [
|
|
2032
|
-
2
|
|
2033
|
-
];
|
|
2034
|
-
}
|
|
2035
|
-
});
|
|
2036
|
-
});
|
|
2037
|
-
return function removeForceDynamic(filePath) {
|
|
2038
|
-
return _ref.apply(this, arguments);
|
|
2039
|
-
};
|
|
2040
|
-
}();
|
|
2041
|
-
return [
|
|
2042
|
-
4,
|
|
2043
|
-
removeForceDynamic(import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/layout.tsx"))
|
|
2044
|
-
];
|
|
2045
|
-
case 2:
|
|
2046
|
-
_state.sent();
|
|
2047
|
-
return [
|
|
2048
|
-
4,
|
|
2049
|
-
removeForceDynamic(import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"))
|
|
2050
|
-
];
|
|
2051
|
-
case 3:
|
|
2052
|
-
_state.sent();
|
|
2053
|
-
return [
|
|
2054
|
-
4,
|
|
2055
|
-
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")
|
|
2056
|
-
];
|
|
2057
|
-
case 4:
|
|
2058
|
-
_state.sent();
|
|
2059
|
-
return [
|
|
2060
|
-
2
|
|
2061
|
-
];
|
|
2062
|
-
}
|
|
2063
|
-
});
|
|
819
|
+
|
|
820
|
+
// src/cli/commands/build.ts
|
|
821
|
+
var buildPreviewApp = (absoluteDirectory) => {
|
|
822
|
+
return new Promise((resolve, reject) => {
|
|
823
|
+
const nextBuild = (0, import_node_child_process.spawn)("npm", ["run", "build"], {
|
|
824
|
+
cwd: absoluteDirectory,
|
|
825
|
+
shell: true
|
|
2064
826
|
});
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
return [
|
|
2078
|
-
4,
|
|
2079
|
-
import_node_fs5.default.promises.readFile(packageJsonPath, "utf8")
|
|
2080
|
-
];
|
|
2081
|
-
case 1:
|
|
2082
|
-
packageJson = _.apply(JSON, [
|
|
2083
|
-
_state.sent()
|
|
2084
|
-
]);
|
|
2085
|
-
packageJson.scripts.build = "next build";
|
|
2086
|
-
packageJson.scripts.start = "next start";
|
|
2087
|
-
packageJson.name = "preview-server";
|
|
2088
|
-
delete packageJson.devDependencies["@react-email/render"];
|
|
2089
|
-
delete packageJson.devDependencies["@react-email/components"];
|
|
2090
|
-
return [
|
|
2091
|
-
4,
|
|
2092
|
-
import_node_fs5.default.promises.writeFile(packageJsonPath, JSON.stringify(packageJson), "utf8")
|
|
2093
|
-
];
|
|
2094
|
-
case 2:
|
|
2095
|
-
_state.sent();
|
|
2096
|
-
return [
|
|
2097
|
-
2
|
|
2098
|
-
];
|
|
2099
|
-
}
|
|
2100
|
-
});
|
|
827
|
+
nextBuild.stdout.pipe(process.stdout);
|
|
828
|
+
nextBuild.stderr.pipe(process.stderr);
|
|
829
|
+
nextBuild.on("close", (code) => {
|
|
830
|
+
if (code === 0) {
|
|
831
|
+
resolve();
|
|
832
|
+
} else {
|
|
833
|
+
reject(
|
|
834
|
+
new Error(
|
|
835
|
+
`Unable to build the Next app and it exited with code: ${code}`
|
|
836
|
+
)
|
|
837
|
+
);
|
|
838
|
+
}
|
|
2101
839
|
});
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
840
|
+
});
|
|
841
|
+
};
|
|
842
|
+
var setNextEnvironmentVariablesForBuild = async (emailsDirRelativePath, builtPreviewAppPath) => {
|
|
843
|
+
const nextConfigContents = `
|
|
844
|
+
const path = require('path');
|
|
845
|
+
const emailsDirRelativePath = path.normalize('${emailsDirRelativePath}');
|
|
846
|
+
const userProjectLocation = path.resolve(process.cwd(), '../');
|
|
847
|
+
/** @type {import('next').NextConfig} */
|
|
848
|
+
module.exports = {
|
|
849
|
+
env: {
|
|
850
|
+
NEXT_PUBLIC_IS_BUILDING: 'true',
|
|
851
|
+
EMAILS_DIR_RELATIVE_PATH: emailsDirRelativePath,
|
|
852
|
+
EMAILS_DIR_ABSOLUTE_PATH: path.resolve(userProjectLocation, emailsDirRelativePath),
|
|
853
|
+
USER_PROJECT_LOCATION: userProjectLocation
|
|
854
|
+
},
|
|
855
|
+
// this is needed so that the code for building emails works properly
|
|
856
|
+
webpack: (
|
|
857
|
+
/** @type {import('webpack').Configuration & { externals: string[] }} */
|
|
858
|
+
config,
|
|
859
|
+
{ isServer }
|
|
860
|
+
) => {
|
|
861
|
+
if (isServer) {
|
|
862
|
+
config.externals.push('esbuild');
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
return config;
|
|
866
|
+
},
|
|
867
|
+
typescript: {
|
|
868
|
+
ignoreBuildErrors: true
|
|
869
|
+
},
|
|
870
|
+
eslint: {
|
|
871
|
+
ignoreDuringBuilds: true
|
|
872
|
+
},
|
|
873
|
+
experimental: {
|
|
874
|
+
webpackBuildWorker: true
|
|
875
|
+
},
|
|
876
|
+
}`;
|
|
877
|
+
await import_node_fs5.default.promises.writeFile(
|
|
878
|
+
import_node_path8.default.resolve(builtPreviewAppPath, "./next.config.js"),
|
|
879
|
+
nextConfigContents,
|
|
880
|
+
"utf8"
|
|
881
|
+
);
|
|
882
|
+
};
|
|
883
|
+
var getEmailSlugsFromEmailDirectory = (emailDirectory, emailsDirectoryAbsolutePath) => {
|
|
884
|
+
const directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
|
|
885
|
+
const slugs = [];
|
|
886
|
+
emailDirectory.emailFilenames.forEach(
|
|
887
|
+
(filename) => slugs.push(
|
|
888
|
+
import_node_path8.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path8.default.sep).filter((segment) => segment.length > 0)
|
|
889
|
+
)
|
|
890
|
+
);
|
|
891
|
+
emailDirectory.subDirectories.forEach((directory) => {
|
|
892
|
+
slugs.push(
|
|
893
|
+
...getEmailSlugsFromEmailDirectory(
|
|
894
|
+
directory,
|
|
895
|
+
emailsDirectoryAbsolutePath
|
|
896
|
+
)
|
|
897
|
+
);
|
|
898
|
+
});
|
|
899
|
+
return slugs;
|
|
900
|
+
};
|
|
901
|
+
var forceSSGForEmailPreviews = async (emailsDirPath, builtPreviewAppPath) => {
|
|
902
|
+
const emailDirectoryMetadata = (
|
|
903
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
904
|
+
await getEmailsDirectoryMetadata(emailsDirPath)
|
|
905
|
+
);
|
|
906
|
+
const parameters = getEmailSlugsFromEmailDirectory(
|
|
907
|
+
emailDirectoryMetadata,
|
|
908
|
+
emailsDirPath
|
|
909
|
+
).map((slug) => ({ slug }));
|
|
910
|
+
const removeForceDynamic = async (filePath) => {
|
|
911
|
+
const contents = await import_node_fs5.default.promises.readFile(filePath, "utf8");
|
|
912
|
+
await import_node_fs5.default.promises.writeFile(
|
|
913
|
+
filePath,
|
|
914
|
+
contents.replace("export const dynamic = 'force-dynamic';", ""),
|
|
915
|
+
"utf8"
|
|
916
|
+
);
|
|
917
|
+
};
|
|
918
|
+
await removeForceDynamic(
|
|
919
|
+
import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/layout.tsx")
|
|
920
|
+
);
|
|
921
|
+
await removeForceDynamic(
|
|
922
|
+
import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx")
|
|
923
|
+
);
|
|
924
|
+
await import_node_fs5.default.promises.appendFile(
|
|
925
|
+
import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"),
|
|
926
|
+
`
|
|
927
|
+
|
|
928
|
+
export function generateStaticParams() {
|
|
929
|
+
return Promise.resolve(
|
|
930
|
+
${JSON.stringify(parameters)}
|
|
931
|
+
);
|
|
932
|
+
}`,
|
|
933
|
+
"utf8"
|
|
934
|
+
);
|
|
935
|
+
};
|
|
936
|
+
var updatePackageJson = async (builtPreviewAppPath) => {
|
|
937
|
+
const packageJsonPath = import_node_path8.default.resolve(builtPreviewAppPath, "./package.json");
|
|
938
|
+
const packageJson = JSON.parse(
|
|
939
|
+
await import_node_fs5.default.promises.readFile(packageJsonPath, "utf8")
|
|
940
|
+
);
|
|
941
|
+
packageJson.scripts.build = "next build";
|
|
942
|
+
packageJson.scripts.start = "next start";
|
|
943
|
+
packageJson.name = "preview-server";
|
|
944
|
+
delete packageJson.devDependencies["@react-email/render"];
|
|
945
|
+
delete packageJson.devDependencies["@react-email/components"];
|
|
946
|
+
await import_node_fs5.default.promises.writeFile(
|
|
947
|
+
packageJsonPath,
|
|
948
|
+
JSON.stringify(packageJson),
|
|
949
|
+
"utf8"
|
|
950
|
+
);
|
|
951
|
+
};
|
|
952
|
+
var npmInstall = async (builtPreviewAppPath, packageManager) => {
|
|
953
|
+
return new Promise((resolve, reject) => {
|
|
954
|
+
const childProc = (0, import_node_child_process.spawn)(
|
|
955
|
+
packageManager,
|
|
956
|
+
["install", "--silent", "--include=dev"],
|
|
957
|
+
{
|
|
958
|
+
cwd: builtPreviewAppPath,
|
|
959
|
+
shell: true
|
|
960
|
+
}
|
|
961
|
+
);
|
|
962
|
+
childProc.stdout.pipe(process.stdout);
|
|
963
|
+
childProc.stderr.pipe(process.stderr);
|
|
964
|
+
childProc.on("close", (code) => {
|
|
965
|
+
if (code === 0) {
|
|
966
|
+
resolve();
|
|
967
|
+
} else {
|
|
968
|
+
reject(
|
|
969
|
+
new Error(
|
|
970
|
+
`Unable to install the dependencies and it exited with code: ${code}`
|
|
971
|
+
)
|
|
972
|
+
);
|
|
973
|
+
}
|
|
2132
974
|
});
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
staticPath = import_node_path8.default.join(emailsDirPath, "static");
|
|
2163
|
-
builtPreviewAppPath = import_node_path8.default.join(process.cwd(), ".react-email");
|
|
2164
|
-
if (!import_node_fs5.default.existsSync(builtPreviewAppPath)) return [
|
|
2165
|
-
3,
|
|
2166
|
-
3
|
|
2167
|
-
];
|
|
2168
|
-
spinner.text = "Deleting pre-existing `.react-email` folder";
|
|
2169
|
-
return [
|
|
2170
|
-
4,
|
|
2171
|
-
import_node_fs5.default.promises.rm(builtPreviewAppPath, {
|
|
2172
|
-
recursive: true
|
|
2173
|
-
})
|
|
2174
|
-
];
|
|
2175
|
-
case 2:
|
|
2176
|
-
_state.sent();
|
|
2177
|
-
_state.label = 3;
|
|
2178
|
-
case 3:
|
|
2179
|
-
spinner.text = "Copying preview app from CLI to `.react-email`";
|
|
2180
|
-
return [
|
|
2181
|
-
4,
|
|
2182
|
-
import_node_fs5.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
|
|
2183
|
-
recursive: true,
|
|
2184
|
-
filter: function(source) {
|
|
2185
|
-
return !/(\/|\\)cli(\/|\\)?/.test(source) && !/(\/|\\)\.next(\/|\\)?/.test(source) && !/(\/|\\)\.turbo(\/|\\)?/.test(source) && !/(\/|\\)node_modules(\/|\\)?$/.test(source);
|
|
2186
|
-
}
|
|
2187
|
-
})
|
|
2188
|
-
];
|
|
2189
|
-
case 4:
|
|
2190
|
-
_state.sent();
|
|
2191
|
-
if (!import_node_fs5.default.existsSync(staticPath)) return [
|
|
2192
|
-
3,
|
|
2193
|
-
6
|
|
2194
|
-
];
|
|
2195
|
-
spinner.text = "Copying `static` folder into `.react-email/public/static`";
|
|
2196
|
-
builtStaticDirectory = import_node_path8.default.resolve(builtPreviewAppPath, "./public/static");
|
|
2197
|
-
return [
|
|
2198
|
-
4,
|
|
2199
|
-
import_node_fs5.default.promises.cp(staticPath, builtStaticDirectory, {
|
|
2200
|
-
recursive: true
|
|
2201
|
-
})
|
|
2202
|
-
];
|
|
2203
|
-
case 5:
|
|
2204
|
-
_state.sent();
|
|
2205
|
-
_state.label = 6;
|
|
2206
|
-
case 6:
|
|
2207
|
-
spinner.text = "Setting Next environment variables for preview app to work properly";
|
|
2208
|
-
return [
|
|
2209
|
-
4,
|
|
2210
|
-
setNextEnvironmentVariablesForBuild(emailsDirRelativePath, builtPreviewAppPath)
|
|
2211
|
-
];
|
|
2212
|
-
case 7:
|
|
2213
|
-
_state.sent();
|
|
2214
|
-
spinner.text = "Setting server side generation for the email preview pages";
|
|
2215
|
-
return [
|
|
2216
|
-
4,
|
|
2217
|
-
forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath)
|
|
2218
|
-
];
|
|
2219
|
-
case 8:
|
|
2220
|
-
_state.sent();
|
|
2221
|
-
spinner.text = "Updating package.json's build and start scripts";
|
|
2222
|
-
return [
|
|
2223
|
-
4,
|
|
2224
|
-
updatePackageJson(builtPreviewAppPath)
|
|
2225
|
-
];
|
|
2226
|
-
case 9:
|
|
2227
|
-
_state.sent();
|
|
2228
|
-
spinner.text = "Installing dependencies on `.react-email`";
|
|
2229
|
-
return [
|
|
2230
|
-
4,
|
|
2231
|
-
npmInstall(builtPreviewAppPath, packageManager)
|
|
2232
|
-
];
|
|
2233
|
-
case 10:
|
|
2234
|
-
_state.sent();
|
|
2235
|
-
spinner.stopAndPersist({
|
|
2236
|
-
text: "Successfully prepared `.react-email` for `next build`",
|
|
2237
|
-
symbol: import_log_symbols3.default.success
|
|
2238
|
-
});
|
|
2239
|
-
return [
|
|
2240
|
-
4,
|
|
2241
|
-
buildPreviewApp(builtPreviewAppPath)
|
|
2242
|
-
];
|
|
2243
|
-
case 11:
|
|
2244
|
-
_state.sent();
|
|
2245
|
-
return [
|
|
2246
|
-
3,
|
|
2247
|
-
13
|
|
2248
|
-
];
|
|
2249
|
-
case 12:
|
|
2250
|
-
error = _state.sent();
|
|
2251
|
-
console.log(error);
|
|
2252
|
-
process.exit(1);
|
|
2253
|
-
return [
|
|
2254
|
-
3,
|
|
2255
|
-
13
|
|
2256
|
-
];
|
|
2257
|
-
case 13:
|
|
2258
|
-
return [
|
|
2259
|
-
2
|
|
2260
|
-
];
|
|
2261
|
-
}
|
|
2262
|
-
});
|
|
975
|
+
});
|
|
976
|
+
};
|
|
977
|
+
var build = async ({
|
|
978
|
+
dir: emailsDirRelativePath,
|
|
979
|
+
packageManager
|
|
980
|
+
}) => {
|
|
981
|
+
try {
|
|
982
|
+
const spinner = (0, import_ora2.default)({
|
|
983
|
+
text: "Starting build process...",
|
|
984
|
+
prefixText: " "
|
|
985
|
+
}).start();
|
|
986
|
+
registerSpinnerAutostopping(spinner);
|
|
987
|
+
spinner.text = `Checking if ${emailsDirRelativePath} folder exists`;
|
|
988
|
+
if (!import_node_fs5.default.existsSync(emailsDirRelativePath)) {
|
|
989
|
+
process.exit(1);
|
|
990
|
+
}
|
|
991
|
+
const emailsDirPath = import_node_path8.default.join(process.cwd(), emailsDirRelativePath);
|
|
992
|
+
const staticPath = import_node_path8.default.join(emailsDirPath, "static");
|
|
993
|
+
const builtPreviewAppPath = import_node_path8.default.join(process.cwd(), ".react-email");
|
|
994
|
+
if (import_node_fs5.default.existsSync(builtPreviewAppPath)) {
|
|
995
|
+
spinner.text = "Deleting pre-existing `.react-email` folder";
|
|
996
|
+
await import_node_fs5.default.promises.rm(builtPreviewAppPath, { recursive: true });
|
|
997
|
+
}
|
|
998
|
+
spinner.text = "Copying preview app from CLI to `.react-email`";
|
|
999
|
+
await import_node_fs5.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
|
|
1000
|
+
recursive: true,
|
|
1001
|
+
filter: (source) => {
|
|
1002
|
+
return !/(\/|\\)cli(\/|\\)?/.test(source) && !/(\/|\\)\.next(\/|\\)?/.test(source) && !/(\/|\\)\.turbo(\/|\\)?/.test(source) && !/(\/|\\)node_modules(\/|\\)?$/.test(source);
|
|
1003
|
+
}
|
|
2263
1004
|
});
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
1005
|
+
if (import_node_fs5.default.existsSync(staticPath)) {
|
|
1006
|
+
spinner.text = "Copying `static` folder into `.react-email/public/static`";
|
|
1007
|
+
const builtStaticDirectory = import_node_path8.default.resolve(
|
|
1008
|
+
builtPreviewAppPath,
|
|
1009
|
+
"./public/static"
|
|
1010
|
+
);
|
|
1011
|
+
await import_node_fs5.default.promises.cp(staticPath, builtStaticDirectory, {
|
|
1012
|
+
recursive: true
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
spinner.text = "Setting Next environment variables for preview app to work properly";
|
|
1016
|
+
await setNextEnvironmentVariablesForBuild(
|
|
1017
|
+
emailsDirRelativePath,
|
|
1018
|
+
builtPreviewAppPath
|
|
1019
|
+
);
|
|
1020
|
+
spinner.text = "Setting server side generation for the email preview pages";
|
|
1021
|
+
await forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath);
|
|
1022
|
+
spinner.text = "Updating package.json's build and start scripts";
|
|
1023
|
+
await updatePackageJson(builtPreviewAppPath);
|
|
1024
|
+
spinner.text = "Installing dependencies on `.react-email`";
|
|
1025
|
+
await npmInstall(builtPreviewAppPath, packageManager);
|
|
1026
|
+
spinner.stopAndPersist({
|
|
1027
|
+
text: "Successfully prepared `.react-email` for `next build`",
|
|
1028
|
+
symbol: import_log_symbols3.default.success
|
|
1029
|
+
});
|
|
1030
|
+
await buildPreviewApp(builtPreviewAppPath);
|
|
1031
|
+
} catch (error) {
|
|
1032
|
+
console.log(error);
|
|
1033
|
+
process.exit(1);
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
|
|
2268
1037
|
// src/cli/commands/dev.ts
|
|
2269
1038
|
var import_node_fs6 = __toESM(require("fs"));
|
|
2270
|
-
var dev =
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
return [
|
|
2290
|
-
4,
|
|
2291
|
-
startDevServer(emailsDirRelativePath, emailsDirRelativePath, // defaults to ./emails/static for the static files that are served to the preview
|
|
2292
|
-
Number.parseInt(port))
|
|
2293
|
-
];
|
|
2294
|
-
case 2:
|
|
2295
|
-
devServer2 = _state.sent();
|
|
2296
|
-
return [
|
|
2297
|
-
4,
|
|
2298
|
-
setupHotreloading(devServer2, emailsDirRelativePath)
|
|
2299
|
-
];
|
|
2300
|
-
case 3:
|
|
2301
|
-
_state.sent();
|
|
2302
|
-
return [
|
|
2303
|
-
3,
|
|
2304
|
-
5
|
|
2305
|
-
];
|
|
2306
|
-
case 4:
|
|
2307
|
-
error = _state.sent();
|
|
2308
|
-
console.log(error);
|
|
2309
|
-
process.exit(1);
|
|
2310
|
-
return [
|
|
2311
|
-
3,
|
|
2312
|
-
5
|
|
2313
|
-
];
|
|
2314
|
-
case 5:
|
|
2315
|
-
return [
|
|
2316
|
-
2
|
|
2317
|
-
];
|
|
2318
|
-
}
|
|
2319
|
-
});
|
|
2320
|
-
});
|
|
2321
|
-
return function dev(_) {
|
|
2322
|
-
return _ref.apply(this, arguments);
|
|
2323
|
-
};
|
|
2324
|
-
}();
|
|
1039
|
+
var dev = async ({ dir: emailsDirRelativePath, port }) => {
|
|
1040
|
+
try {
|
|
1041
|
+
if (!import_node_fs6.default.existsSync(emailsDirRelativePath)) {
|
|
1042
|
+
console.error(`Missing ${emailsDirRelativePath} folder`);
|
|
1043
|
+
process.exit(1);
|
|
1044
|
+
}
|
|
1045
|
+
const devServer2 = await startDevServer(
|
|
1046
|
+
emailsDirRelativePath,
|
|
1047
|
+
emailsDirRelativePath,
|
|
1048
|
+
// defaults to ./emails/static for the static files that are served to the preview
|
|
1049
|
+
Number.parseInt(port)
|
|
1050
|
+
);
|
|
1051
|
+
await setupHotreloading(devServer2, emailsDirRelativePath);
|
|
1052
|
+
} catch (error) {
|
|
1053
|
+
console.log(error);
|
|
1054
|
+
process.exit(1);
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
|
|
2325
1058
|
// src/cli/commands/export.ts
|
|
2326
1059
|
var import_node_fs8 = __toESM(require("fs"));
|
|
2327
1060
|
var import_node_path10 = __toESM(require("path"));
|
|
@@ -2330,457 +1063,244 @@ var import_glob = require("glob");
|
|
|
2330
1063
|
var import_log_symbols4 = __toESM(require("log-symbols"));
|
|
2331
1064
|
var import_normalize_path = __toESM(require("normalize-path"));
|
|
2332
1065
|
var import_ora3 = __toESM(require("ora"));
|
|
1066
|
+
|
|
2333
1067
|
// src/utils/esbuild/renderring-utilities-exporter.ts
|
|
2334
1068
|
var import_node_fs7 = require("fs");
|
|
2335
1069
|
var import_node_path9 = __toESM(require("path"));
|
|
1070
|
+
|
|
2336
1071
|
// src/utils/esbuild/escape-string-for-regex.ts
|
|
2337
1072
|
function escapeStringForRegex(string) {
|
|
2338
|
-
|
|
1073
|
+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
2339
1074
|
}
|
|
1075
|
+
|
|
2340
1076
|
// src/utils/esbuild/renderring-utilities-exporter.ts
|
|
2341
|
-
var renderingUtilitiesExporter =
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
});
|
|
2373
|
-
return function(_) {
|
|
2374
|
-
return _ref.apply(this, arguments);
|
|
2375
|
-
};
|
|
2376
|
-
}());
|
|
2377
|
-
b.onResolve({
|
|
2378
|
-
filter: /^react-email-module-that-will-export-render$/
|
|
2379
|
-
}, function() {
|
|
2380
|
-
var _ref = _async_to_generator(function(args) {
|
|
2381
|
-
var options, result;
|
|
2382
|
-
return _ts_generator(this, function(_state) {
|
|
2383
|
-
switch(_state.label){
|
|
2384
|
-
case 0:
|
|
2385
|
-
options = {
|
|
2386
|
-
kind: "import-statement",
|
|
2387
|
-
importer: args.importer,
|
|
2388
|
-
resolveDir: args.resolveDir,
|
|
2389
|
-
namespace: args.namespace
|
|
2390
|
-
};
|
|
2391
|
-
return [
|
|
2392
|
-
4,
|
|
2393
|
-
b.resolve("@react-email/render", options)
|
|
2394
|
-
];
|
|
2395
|
-
case 1:
|
|
2396
|
-
result = _state.sent();
|
|
2397
|
-
if (result.errors.length === 0) {
|
|
2398
|
-
return [
|
|
2399
|
-
2,
|
|
2400
|
-
result
|
|
2401
|
-
];
|
|
2402
|
-
}
|
|
2403
|
-
return [
|
|
2404
|
-
4,
|
|
2405
|
-
b.resolve("@react-email/components", options)
|
|
2406
|
-
];
|
|
2407
|
-
case 2:
|
|
2408
|
-
result = _state.sent();
|
|
2409
|
-
if (result.errors.length > 0 && result.errors[0]) {
|
|
2410
|
-
result.errors[0].text = "Failed trying to import `render` from either `@react-email/render` or `@react-email/components` to be able to render your email template.\n Maybe you don't have either of them installed?";
|
|
2411
|
-
}
|
|
2412
|
-
return [
|
|
2413
|
-
2,
|
|
2414
|
-
result
|
|
2415
|
-
];
|
|
2416
|
-
}
|
|
2417
|
-
});
|
|
2418
|
-
});
|
|
2419
|
-
return function(args) {
|
|
2420
|
-
return _ref.apply(this, arguments);
|
|
2421
|
-
};
|
|
2422
|
-
}());
|
|
1077
|
+
var renderingUtilitiesExporter = (emailTemplates) => ({
|
|
1078
|
+
name: "rendering-utilities-exporter",
|
|
1079
|
+
setup: (b) => {
|
|
1080
|
+
b.onLoad(
|
|
1081
|
+
{
|
|
1082
|
+
filter: new RegExp(
|
|
1083
|
+
emailTemplates.map((emailPath) => escapeStringForRegex(emailPath)).join("|")
|
|
1084
|
+
)
|
|
1085
|
+
},
|
|
1086
|
+
async ({ path: pathToFile }) => {
|
|
1087
|
+
return {
|
|
1088
|
+
contents: `${await import_node_fs7.promises.readFile(pathToFile, "utf8")};
|
|
1089
|
+
export { render } from 'react-email-module-that-will-export-render'
|
|
1090
|
+
export { createElement as reactEmailCreateReactElement } from 'react';
|
|
1091
|
+
`,
|
|
1092
|
+
loader: import_node_path9.default.extname(pathToFile).slice(1)
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
);
|
|
1096
|
+
b.onResolve(
|
|
1097
|
+
{ filter: /^react-email-module-that-will-export-render$/ },
|
|
1098
|
+
async (args) => {
|
|
1099
|
+
const options = {
|
|
1100
|
+
kind: "import-statement",
|
|
1101
|
+
importer: args.importer,
|
|
1102
|
+
resolveDir: args.resolveDir,
|
|
1103
|
+
namespace: args.namespace
|
|
1104
|
+
};
|
|
1105
|
+
let result = await b.resolve("@react-email/render", options);
|
|
1106
|
+
if (result.errors.length === 0) {
|
|
1107
|
+
return result;
|
|
2423
1108
|
}
|
|
2424
|
-
|
|
2425
|
-
|
|
1109
|
+
result = await b.resolve("@react-email/components", options);
|
|
1110
|
+
if (result.errors.length > 0 && result.errors[0]) {
|
|
1111
|
+
result.errors[0].text = "Failed trying to import `render` from either `@react-email/render` or `@react-email/components` to be able to render your email template.\n Maybe you don't have either of them installed?";
|
|
1112
|
+
}
|
|
1113
|
+
return result;
|
|
1114
|
+
}
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
|
|
2426
1119
|
// src/cli/commands/export.ts
|
|
2427
|
-
var getEmailTemplatesFromDirectory =
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
return templatePaths;
|
|
1120
|
+
var getEmailTemplatesFromDirectory = (emailDirectory) => {
|
|
1121
|
+
const templatePaths = [];
|
|
1122
|
+
emailDirectory.emailFilenames.forEach(
|
|
1123
|
+
(filename) => templatePaths.push(import_node_path10.default.join(emailDirectory.absolutePath, filename))
|
|
1124
|
+
);
|
|
1125
|
+
emailDirectory.subDirectories.forEach((directory) => {
|
|
1126
|
+
templatePaths.push(...getEmailTemplatesFromDirectory(directory));
|
|
1127
|
+
});
|
|
1128
|
+
return templatePaths;
|
|
2437
1129
|
};
|
|
2438
|
-
var exportTemplates =
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
3,
|
|
2546
|
-
13
|
|
2547
|
-
];
|
|
2548
|
-
_value = _step.value;
|
|
2549
|
-
template = _value;
|
|
2550
|
-
_state.label = 9;
|
|
2551
|
-
case 9:
|
|
2552
|
-
_state.trys.push([
|
|
2553
|
-
9,
|
|
2554
|
-
11,
|
|
2555
|
-
,
|
|
2556
|
-
12
|
|
2557
|
-
]);
|
|
2558
|
-
if (spinner) {
|
|
2559
|
-
spinner.text = "rendering ".concat(template.split("/").pop());
|
|
2560
|
-
spinner.render();
|
|
2561
|
-
}
|
|
2562
|
-
delete require.cache[template];
|
|
2563
|
-
emailModule = require(template);
|
|
2564
|
-
return [
|
|
2565
|
-
4,
|
|
2566
|
-
emailModule.render(emailModule.reactEmailCreateReactElement(emailModule.default, {}), options)
|
|
2567
|
-
];
|
|
2568
|
-
case 10:
|
|
2569
|
-
rendered = _state.sent();
|
|
2570
|
-
htmlPath = template.replace(".cjs", options.plainText ? ".txt" : ".html");
|
|
2571
|
-
(0, import_node_fs8.writeFileSync)(htmlPath, rendered);
|
|
2572
|
-
(0, import_node_fs8.unlinkSync)(template);
|
|
2573
|
-
return [
|
|
2574
|
-
3,
|
|
2575
|
-
12
|
|
2576
|
-
];
|
|
2577
|
-
case 11:
|
|
2578
|
-
exception1 = _state.sent();
|
|
2579
|
-
if (spinner) {
|
|
2580
|
-
spinner.stopAndPersist({
|
|
2581
|
-
symbol: import_log_symbols4.default.error,
|
|
2582
|
-
text: "failed when rendering ".concat(template.split("/").pop())
|
|
2583
|
-
});
|
|
2584
|
-
}
|
|
2585
|
-
console.error(exception1);
|
|
2586
|
-
process.exit(1);
|
|
2587
|
-
return [
|
|
2588
|
-
3,
|
|
2589
|
-
12
|
|
2590
|
-
];
|
|
2591
|
-
case 12:
|
|
2592
|
-
_iteratorAbruptCompletion = false;
|
|
2593
|
-
return [
|
|
2594
|
-
3,
|
|
2595
|
-
7
|
|
2596
|
-
];
|
|
2597
|
-
case 13:
|
|
2598
|
-
return [
|
|
2599
|
-
3,
|
|
2600
|
-
20
|
|
2601
|
-
];
|
|
2602
|
-
case 14:
|
|
2603
|
-
err = _state.sent();
|
|
2604
|
-
_didIteratorError = true;
|
|
2605
|
-
_iteratorError = err;
|
|
2606
|
-
return [
|
|
2607
|
-
3,
|
|
2608
|
-
20
|
|
2609
|
-
];
|
|
2610
|
-
case 15:
|
|
2611
|
-
_state.trys.push([
|
|
2612
|
-
15,
|
|
2613
|
-
,
|
|
2614
|
-
18,
|
|
2615
|
-
19
|
|
2616
|
-
]);
|
|
2617
|
-
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
2618
|
-
3,
|
|
2619
|
-
17
|
|
2620
|
-
];
|
|
2621
|
-
return [
|
|
2622
|
-
4,
|
|
2623
|
-
_iterator.return()
|
|
2624
|
-
];
|
|
2625
|
-
case 16:
|
|
2626
|
-
_state.sent();
|
|
2627
|
-
_state.label = 17;
|
|
2628
|
-
case 17:
|
|
2629
|
-
return [
|
|
2630
|
-
3,
|
|
2631
|
-
19
|
|
2632
|
-
];
|
|
2633
|
-
case 18:
|
|
2634
|
-
if (_didIteratorError) {
|
|
2635
|
-
throw _iteratorError;
|
|
2636
|
-
}
|
|
2637
|
-
return [
|
|
2638
|
-
7
|
|
2639
|
-
];
|
|
2640
|
-
case 19:
|
|
2641
|
-
return [
|
|
2642
|
-
7
|
|
2643
|
-
];
|
|
2644
|
-
case 20:
|
|
2645
|
-
if (spinner) {
|
|
2646
|
-
spinner.succeed("Rendered all files");
|
|
2647
|
-
spinner.text = "Copying static files";
|
|
2648
|
-
spinner.render();
|
|
2649
|
-
}
|
|
2650
|
-
staticDirectoryPath = import_node_path10.default.join(emailsDirectoryPath, "static");
|
|
2651
|
-
if (!import_node_fs8.default.existsSync(staticDirectoryPath)) return [
|
|
2652
|
-
3,
|
|
2653
|
-
25
|
|
2654
|
-
];
|
|
2655
|
-
pathToDumpStaticFilesInto = import_node_path10.default.join(pathToWhereEmailMarkupShouldBeDumped, "static");
|
|
2656
|
-
if (!import_node_fs8.default.existsSync(pathToDumpStaticFilesInto)) return [
|
|
2657
|
-
3,
|
|
2658
|
-
22
|
|
2659
|
-
];
|
|
2660
|
-
return [
|
|
2661
|
-
4,
|
|
2662
|
-
import_node_fs8.default.promises.rm(pathToDumpStaticFilesInto, {
|
|
2663
|
-
recursive: true
|
|
2664
|
-
})
|
|
2665
|
-
];
|
|
2666
|
-
case 21:
|
|
2667
|
-
_state.sent();
|
|
2668
|
-
_state.label = 22;
|
|
2669
|
-
case 22:
|
|
2670
|
-
_state.trys.push([
|
|
2671
|
-
22,
|
|
2672
|
-
24,
|
|
2673
|
-
,
|
|
2674
|
-
25
|
|
2675
|
-
]);
|
|
2676
|
-
return [
|
|
2677
|
-
4,
|
|
2678
|
-
import_node_fs8.default.promises.cp(staticDirectoryPath, pathToDumpStaticFilesInto, {
|
|
2679
|
-
recursive: true
|
|
2680
|
-
})
|
|
2681
|
-
];
|
|
2682
|
-
case 23:
|
|
2683
|
-
_state.sent();
|
|
2684
|
-
return [
|
|
2685
|
-
3,
|
|
2686
|
-
25
|
|
2687
|
-
];
|
|
2688
|
-
case 24:
|
|
2689
|
-
exception2 = _state.sent();
|
|
2690
|
-
console.error(exception2);
|
|
2691
|
-
if (spinner) {
|
|
2692
|
-
spinner.stopAndPersist({
|
|
2693
|
-
symbol: import_log_symbols4.default.error,
|
|
2694
|
-
text: "Failed to copy static files"
|
|
2695
|
-
});
|
|
2696
|
-
}
|
|
2697
|
-
console.error("Something went wrong while copying the file to ".concat(pathToWhereEmailMarkupShouldBeDumped, "/static, ").concat(exception2));
|
|
2698
|
-
process.exit(1);
|
|
2699
|
-
return [
|
|
2700
|
-
3,
|
|
2701
|
-
25
|
|
2702
|
-
];
|
|
2703
|
-
case 25:
|
|
2704
|
-
if (!(spinner && !options.silent)) return [
|
|
2705
|
-
3,
|
|
2706
|
-
27
|
|
2707
|
-
];
|
|
2708
|
-
spinner.succeed();
|
|
2709
|
-
return [
|
|
2710
|
-
4,
|
|
2711
|
-
tree(pathToWhereEmailMarkupShouldBeDumped, 4)
|
|
2712
|
-
];
|
|
2713
|
-
case 26:
|
|
2714
|
-
fileTree = _state.sent();
|
|
2715
|
-
console.log(fileTree);
|
|
2716
|
-
spinner.stopAndPersist({
|
|
2717
|
-
symbol: import_log_symbols4.default.success,
|
|
2718
|
-
text: "Successfully exported emails"
|
|
2719
|
-
});
|
|
2720
|
-
_state.label = 27;
|
|
2721
|
-
case 27:
|
|
2722
|
-
return [
|
|
2723
|
-
2
|
|
2724
|
-
];
|
|
2725
|
-
}
|
|
1130
|
+
var exportTemplates = async (pathToWhereEmailMarkupShouldBeDumped, emailsDirectoryPath, options) => {
|
|
1131
|
+
if (import_node_fs8.default.existsSync(pathToWhereEmailMarkupShouldBeDumped)) {
|
|
1132
|
+
import_node_fs8.default.rmSync(pathToWhereEmailMarkupShouldBeDumped, { recursive: true });
|
|
1133
|
+
}
|
|
1134
|
+
let spinner;
|
|
1135
|
+
if (!options.silent) {
|
|
1136
|
+
spinner = (0, import_ora3.default)("Preparing files...\n").start();
|
|
1137
|
+
registerSpinnerAutostopping(spinner);
|
|
1138
|
+
}
|
|
1139
|
+
const emailsDirectoryMetadata = await getEmailsDirectoryMetadata(
|
|
1140
|
+
import_node_path10.default.resolve(process.cwd(), emailsDirectoryPath),
|
|
1141
|
+
true
|
|
1142
|
+
);
|
|
1143
|
+
if (typeof emailsDirectoryMetadata === "undefined") {
|
|
1144
|
+
if (spinner) {
|
|
1145
|
+
spinner.stopAndPersist({
|
|
1146
|
+
symbol: import_log_symbols4.default.error,
|
|
1147
|
+
text: `Could not find the directory at ${emailsDirectoryPath}`
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
const allTemplates = getEmailTemplatesFromDirectory(emailsDirectoryMetadata);
|
|
1153
|
+
try {
|
|
1154
|
+
await (0, import_esbuild.build)({
|
|
1155
|
+
bundle: true,
|
|
1156
|
+
entryPoints: allTemplates,
|
|
1157
|
+
plugins: [renderingUtilitiesExporter(allTemplates)],
|
|
1158
|
+
platform: "node",
|
|
1159
|
+
format: "cjs",
|
|
1160
|
+
loader: { ".js": "jsx" },
|
|
1161
|
+
outExtension: { ".js": ".cjs" },
|
|
1162
|
+
jsx: "transform",
|
|
1163
|
+
write: true,
|
|
1164
|
+
outdir: pathToWhereEmailMarkupShouldBeDumped
|
|
1165
|
+
});
|
|
1166
|
+
} catch (exception) {
|
|
1167
|
+
const buildFailure = exception;
|
|
1168
|
+
if (spinner) {
|
|
1169
|
+
spinner.stopAndPersist({
|
|
1170
|
+
symbol: import_log_symbols4.default.error,
|
|
1171
|
+
text: "Failed to build emails"
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
process.exit(1);
|
|
1175
|
+
}
|
|
1176
|
+
if (spinner) {
|
|
1177
|
+
spinner.succeed();
|
|
1178
|
+
}
|
|
1179
|
+
const allBuiltTemplates = import_glob.glob.sync(
|
|
1180
|
+
(0, import_normalize_path.default)(`${pathToWhereEmailMarkupShouldBeDumped}/**/*.cjs`),
|
|
1181
|
+
{
|
|
1182
|
+
absolute: true
|
|
1183
|
+
}
|
|
1184
|
+
);
|
|
1185
|
+
for await (const template of allBuiltTemplates) {
|
|
1186
|
+
try {
|
|
1187
|
+
if (spinner) {
|
|
1188
|
+
spinner.text = `rendering ${template.split("/").pop()}`;
|
|
1189
|
+
spinner.render();
|
|
1190
|
+
}
|
|
1191
|
+
delete require.cache[template];
|
|
1192
|
+
const emailModule = require(template);
|
|
1193
|
+
const rendered = await emailModule.render(
|
|
1194
|
+
emailModule.reactEmailCreateReactElement(emailModule.default, {}),
|
|
1195
|
+
options
|
|
1196
|
+
);
|
|
1197
|
+
const htmlPath = template.replace(
|
|
1198
|
+
".cjs",
|
|
1199
|
+
options.plainText ? ".txt" : ".html"
|
|
1200
|
+
);
|
|
1201
|
+
(0, import_node_fs8.writeFileSync)(htmlPath, rendered);
|
|
1202
|
+
(0, import_node_fs8.unlinkSync)(template);
|
|
1203
|
+
} catch (exception) {
|
|
1204
|
+
if (spinner) {
|
|
1205
|
+
spinner.stopAndPersist({
|
|
1206
|
+
symbol: import_log_symbols4.default.error,
|
|
1207
|
+
text: `failed when rendering ${template.split("/").pop()}`
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
console.error(exception);
|
|
1211
|
+
process.exit(1);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
if (spinner) {
|
|
1215
|
+
spinner.succeed("Rendered all files");
|
|
1216
|
+
spinner.text = "Copying static files";
|
|
1217
|
+
spinner.render();
|
|
1218
|
+
}
|
|
1219
|
+
const staticDirectoryPath = import_node_path10.default.join(emailsDirectoryPath, "static");
|
|
1220
|
+
if (import_node_fs8.default.existsSync(staticDirectoryPath)) {
|
|
1221
|
+
const pathToDumpStaticFilesInto = import_node_path10.default.join(
|
|
1222
|
+
pathToWhereEmailMarkupShouldBeDumped,
|
|
1223
|
+
"static"
|
|
1224
|
+
);
|
|
1225
|
+
if (import_node_fs8.default.existsSync(pathToDumpStaticFilesInto))
|
|
1226
|
+
await import_node_fs8.default.promises.rm(pathToDumpStaticFilesInto, { recursive: true });
|
|
1227
|
+
try {
|
|
1228
|
+
await import_node_fs8.default.promises.cp(staticDirectoryPath, pathToDumpStaticFilesInto, {
|
|
1229
|
+
recursive: true
|
|
1230
|
+
});
|
|
1231
|
+
} catch (exception) {
|
|
1232
|
+
console.error(exception);
|
|
1233
|
+
if (spinner) {
|
|
1234
|
+
spinner.stopAndPersist({
|
|
1235
|
+
symbol: import_log_symbols4.default.error,
|
|
1236
|
+
text: "Failed to copy static files"
|
|
2726
1237
|
});
|
|
1238
|
+
}
|
|
1239
|
+
console.error(
|
|
1240
|
+
`Something went wrong while copying the file to ${pathToWhereEmailMarkupShouldBeDumped}/static, ${exception}`
|
|
1241
|
+
);
|
|
1242
|
+
process.exit(1);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
if (spinner && !options.silent) {
|
|
1246
|
+
spinner.succeed();
|
|
1247
|
+
const fileTree = await tree(pathToWhereEmailMarkupShouldBeDumped, 4);
|
|
1248
|
+
console.log(fileTree);
|
|
1249
|
+
spinner.stopAndPersist({
|
|
1250
|
+
symbol: import_log_symbols4.default.success,
|
|
1251
|
+
text: "Successfully exported emails"
|
|
2727
1252
|
});
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
}();
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
|
|
2732
1256
|
// src/cli/commands/start.ts
|
|
2733
1257
|
var import_node_child_process2 = require("child_process");
|
|
2734
1258
|
var import_node_fs9 = __toESM(require("fs"));
|
|
2735
1259
|
var import_node_path11 = __toESM(require("path"));
|
|
2736
|
-
var start =
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
});
|
|
2753
|
-
process.on("SIGINT", function() {
|
|
2754
|
-
nextStart.kill("SIGINT");
|
|
2755
|
-
});
|
|
2756
|
-
nextStart.on("exit", function(code) {
|
|
2757
|
-
process.exit(code !== null && code !== void 0 ? code : 0);
|
|
2758
|
-
});
|
|
2759
|
-
} catch (error) {
|
|
2760
|
-
console.log(error);
|
|
2761
|
-
process.exit(1);
|
|
2762
|
-
}
|
|
2763
|
-
return [
|
|
2764
|
-
2
|
|
2765
|
-
];
|
|
2766
|
-
});
|
|
1260
|
+
var start = async () => {
|
|
1261
|
+
try {
|
|
1262
|
+
const usersProjectLocation = process.cwd();
|
|
1263
|
+
const builtPreviewPath = import_node_path11.default.resolve(
|
|
1264
|
+
usersProjectLocation,
|
|
1265
|
+
"./.react-email"
|
|
1266
|
+
);
|
|
1267
|
+
if (!import_node_fs9.default.existsSync(builtPreviewPath)) {
|
|
1268
|
+
console.error(
|
|
1269
|
+
"Could not find .react-email, maybe you haven't ran email build?"
|
|
1270
|
+
);
|
|
1271
|
+
process.exit(1);
|
|
1272
|
+
}
|
|
1273
|
+
const nextStart = (0, import_node_child_process2.spawn)("npm", ["start"], {
|
|
1274
|
+
cwd: builtPreviewPath,
|
|
1275
|
+
stdio: "inherit"
|
|
2767
1276
|
});
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
};
|
|
2771
|
-
|
|
1277
|
+
process.on("SIGINT", () => {
|
|
1278
|
+
nextStart.kill("SIGINT");
|
|
1279
|
+
});
|
|
1280
|
+
nextStart.on("exit", (code) => {
|
|
1281
|
+
process.exit(code ?? 0);
|
|
1282
|
+
});
|
|
1283
|
+
} catch (error) {
|
|
1284
|
+
console.log(error);
|
|
1285
|
+
process.exit(1);
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
|
|
2772
1289
|
// src/cli/index.ts
|
|
2773
1290
|
var PACKAGE_NAME = "react-email";
|
|
2774
1291
|
import_commander.program.name(PACKAGE_NAME).description("A live preview of your emails right in your browser").version(package_default.version);
|
|
2775
1292
|
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);
|
|
2776
|
-
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(
|
|
1293
|
+
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(
|
|
1294
|
+
"-p --packageManager <name>",
|
|
1295
|
+
"Package name to use on installation on `.react-email`",
|
|
1296
|
+
"npm"
|
|
1297
|
+
).action(build);
|
|
2777
1298
|
import_commander.program.command("start").description('Runs the built preview app that is inside of ".react-email"').action(start);
|
|
2778
|
-
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(
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
});
|
|
1299
|
+
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(
|
|
1300
|
+
"-s, --silent",
|
|
1301
|
+
"To, or not to show a spinner with process information",
|
|
1302
|
+
false
|
|
1303
|
+
).action(
|
|
1304
|
+
({ outDir, pretty, plainText, silent, dir: srcDir }) => exportTemplates(outDir, srcDir, { pretty, silent, plainText })
|
|
1305
|
+
);
|
|
2786
1306
|
import_commander.program.parse();
|