react-email 4.0.0-alpha.5 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cli/index.js +1175 -2659
- package/dist/cli/index.mjs +16 -14
- package/dist/preview/.next/BUILD_ID +1 -1
- package/dist/preview/.next/app-build-manifest.json +31 -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 +47 -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/chunks/171.js +14 -0
- 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/833.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/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/chunks/416-56f79fc7e689f06f.js +1 -0
- package/dist/preview/.next/static/chunks/683-8bbfd191e5105f01.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/87-38e35f08507de015.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-a6640e62690d8fd6.js +1 -0
- package/dist/preview/.next/static/chunks/app/page-ba68f50b287e7478.js +1 -0
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-4a5b026ab543e27f.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-c2e686acf8d370d7.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/d7df9cfc3e182163.css +3 -0
- package/dist/preview/.next/static/gFk9UfWL8joM4iD7-wlKF/_buildManifest.js +1 -0
- package/dist/preview/.next/trace +26 -22
- 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 +322 -0
- package/src/actions/email-validation/check-images.spec.tsx +2 -2
- package/src/actions/email-validation/check-images.ts +2 -2
- package/src/actions/email-validation/check-links.spec.tsx +4 -4
- package/src/actions/email-validation/check-links.ts +2 -2
- 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} +2 -0
- package/src/app/layout.tsx +1 -1
- package/src/app/page.tsx +1 -1
- package/src/app/preview/[...slug]/page.tsx +73 -16
- package/src/app/preview/[...slug]/preview.tsx +11 -57
- package/src/components/code.tsx +0 -1
- package/src/components/toolbar/linter.tsx +267 -124
- package/src/components/toolbar/spam-assassin.tsx +20 -31
- package/src/components/toolbar/toolbar-button.tsx +50 -0
- package/src/components/toolbar/use-cached-state.ts +33 -0
- package/src/components/toolbar.tsx +106 -98
- package/src/components/topbar/view-size-controls.tsx +1 -0
- package/src/components/topbar.tsx +3 -9
- package/src/contexts/emails.tsx +2 -1
- package/src/contexts/preview.tsx +81 -0
- package/src/hooks/use-email-rendering-result.ts +2 -1
- 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 +205 -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/linting.ts +85 -0
- package/src/utils/result.ts +49 -0
- package/src/utils/run-bundled-code.ts +64 -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/dist/preview/.next/static/{B4EYZiVzdylEG9lAIl-aO → gFk9UfWL8joM4iD7-wlKF}/_ssgManifest.js +0 -0
package/dist/cli/index.js
CHANGED
|
@@ -1,698 +1,295 @@
|
|
|
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.6",
|
|
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: ["react", "email"],
|
|
52
|
+
engines: {
|
|
53
|
+
node: ">=18.0.0"
|
|
54
|
+
},
|
|
55
|
+
dependencies: {
|
|
56
|
+
"@babel/parser": "7.24.5",
|
|
57
|
+
"@babel/traverse": "7.25.6",
|
|
58
|
+
chalk: "4.1.2",
|
|
59
|
+
chokidar: "4.0.3",
|
|
60
|
+
commander: "11.1.0",
|
|
61
|
+
debounce: "2.0.0",
|
|
62
|
+
esbuild: "0.23.0",
|
|
63
|
+
glob: "10.3.4",
|
|
64
|
+
"log-symbols": "4.1.0",
|
|
65
|
+
"mime-types": "2.1.35",
|
|
66
|
+
next: "15.2.2",
|
|
67
|
+
"normalize-path": "3.0.0",
|
|
68
|
+
ora: "5.4.1",
|
|
69
|
+
"socket.io": "4.8.1"
|
|
70
|
+
},
|
|
71
|
+
devDependencies: {
|
|
72
|
+
"@babel/core": "7.26.10",
|
|
73
|
+
"@lottiefiles/dotlottie-react": "0.12.3",
|
|
74
|
+
"@radix-ui/colors": "1.0.1",
|
|
75
|
+
"@radix-ui/react-collapsible": "1.1.0",
|
|
76
|
+
"@radix-ui/react-dropdown-menu": "2.1.4",
|
|
77
|
+
"@radix-ui/react-popover": "1.1.1",
|
|
78
|
+
"@radix-ui/react-slot": "1.1.0",
|
|
79
|
+
"@radix-ui/react-tabs": "1.1.1",
|
|
80
|
+
"@radix-ui/react-toggle-group": "1.1.0",
|
|
81
|
+
"@radix-ui/react-tooltip": "1.1.2",
|
|
82
|
+
"@react-email/render": "workspace:*",
|
|
83
|
+
"@swc/core": "1.4.15",
|
|
84
|
+
"@types/babel__core": "7.20.5",
|
|
85
|
+
"@types/babel__traverse": "*",
|
|
86
|
+
"@types/fs-extra": "11.0.1",
|
|
87
|
+
"@types/mime-types": "2.1.4",
|
|
88
|
+
"@types/node": "22.10.2",
|
|
89
|
+
"@types/normalize-path": "3.0.2",
|
|
90
|
+
"@types/react": "19.0.10",
|
|
91
|
+
"@types/react-dom": "19.0.4",
|
|
92
|
+
"@types/webpack": "5.28.5",
|
|
93
|
+
"@vercel/style-guide": "5.1.0",
|
|
94
|
+
autoprefixer: "10.4.20",
|
|
95
|
+
clsx: "2.1.0",
|
|
96
|
+
"framer-motion": "12.0.0-alpha.2",
|
|
97
|
+
jiti: "2.4.2",
|
|
98
|
+
json5: "2.2.3",
|
|
99
|
+
"module-punycode": "npm:punycode@2.3.1",
|
|
100
|
+
"node-html-parser": "6.1.13",
|
|
101
|
+
postcss: "8.4.40",
|
|
102
|
+
"prettier-plugin-tailwindcss": "0.6.6",
|
|
103
|
+
"pretty-bytes": "6.1.1",
|
|
104
|
+
"prism-react-renderer": "2.1.0",
|
|
105
|
+
react: "19.0.0",
|
|
106
|
+
"react-dom": "19.0.0",
|
|
107
|
+
sharp: "0.33.3",
|
|
108
|
+
"socket.io-client": "4.8.0",
|
|
109
|
+
sonner: "1.7.1",
|
|
110
|
+
"source-map-js": "1.0.2",
|
|
111
|
+
spamc: "0.0.5",
|
|
112
|
+
"stacktrace-parser": "0.1.10",
|
|
113
|
+
"tailwind-merge": "2.2.0",
|
|
114
|
+
tailwindcss: "3.4.0",
|
|
115
|
+
tsup: "7.2.0",
|
|
116
|
+
tsx: "4.9.0",
|
|
117
|
+
typescript: "5.8.2",
|
|
118
|
+
"use-debounce": "10.0.4",
|
|
119
|
+
vitest: "1.1.3",
|
|
120
|
+
zod: "3.24.2"
|
|
121
|
+
}
|
|
432
122
|
};
|
|
123
|
+
|
|
433
124
|
// src/cli/commands/build.ts
|
|
434
125
|
var import_node_child_process = require("child_process");
|
|
435
126
|
var import_node_fs5 = __toESM(require("fs"));
|
|
436
127
|
var import_node_path8 = __toESM(require("path"));
|
|
437
128
|
var import_log_symbols3 = __toESM(require("log-symbols"));
|
|
438
129
|
var import_ora2 = __toESM(require("ora"));
|
|
130
|
+
|
|
439
131
|
// src/utils/get-emails-directory-metadata.ts
|
|
440
132
|
var import_node_fs = __toESM(require("fs"));
|
|
441
133
|
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);
|
|
134
|
+
var isFileAnEmail = (fullPath) => {
|
|
135
|
+
const stat = import_node_fs.default.statSync(fullPath);
|
|
136
|
+
if (stat.isDirectory())
|
|
137
|
+
return false;
|
|
138
|
+
const { ext } = import_node_path.default.parse(fullPath);
|
|
139
|
+
if (![".js", ".tsx", ".jsx"].includes(ext))
|
|
140
|
+
return false;
|
|
141
|
+
if (!import_node_fs.default.existsSync(fullPath)) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
const fileContents = import_node_fs.default.readFileSync(fullPath, "utf8");
|
|
145
|
+
return /\bexport\s+default\b/gm.test(fileContents);
|
|
456
146
|
};
|
|
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);
|
|
147
|
+
var mergeDirectoriesWithSubDirectories = (emailsDirectoryMetadata) => {
|
|
148
|
+
let currentResultingMergedDirectory = emailsDirectoryMetadata;
|
|
149
|
+
while (currentResultingMergedDirectory.emailFilenames.length === 0 && currentResultingMergedDirectory.subDirectories.length === 1) {
|
|
150
|
+
const onlySubDirectory = currentResultingMergedDirectory.subDirectories[0];
|
|
151
|
+
currentResultingMergedDirectory = {
|
|
152
|
+
...onlySubDirectory,
|
|
153
|
+
directoryName: import_node_path.default.join(
|
|
154
|
+
currentResultingMergedDirectory.directoryName,
|
|
155
|
+
onlySubDirectory.directoryName
|
|
156
|
+
)
|
|
518
157
|
};
|
|
519
|
-
}
|
|
158
|
+
}
|
|
159
|
+
return currentResultingMergedDirectory;
|
|
160
|
+
};
|
|
161
|
+
var getEmailsDirectoryMetadata = async (absolutePathToEmailsDirectory, keepFileExtensions = false, isSubDirectory = false, baseDirectoryPath = absolutePathToEmailsDirectory) => {
|
|
162
|
+
if (!import_node_fs.default.existsSync(absolutePathToEmailsDirectory))
|
|
163
|
+
return;
|
|
164
|
+
const dirents = await import_node_fs.default.promises.readdir(absolutePathToEmailsDirectory, {
|
|
165
|
+
withFileTypes: true
|
|
166
|
+
});
|
|
167
|
+
const emailFilenames = dirents.filter(
|
|
168
|
+
(dirent) => isFileAnEmail(import_node_path.default.join(absolutePathToEmailsDirectory, dirent.name))
|
|
169
|
+
).map(
|
|
170
|
+
(dirent) => keepFileExtensions ? dirent.name : dirent.name.replace(import_node_path.default.extname(dirent.name), "")
|
|
171
|
+
);
|
|
172
|
+
const subDirectories = await Promise.all(
|
|
173
|
+
dirents.filter(
|
|
174
|
+
(dirent) => dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static"
|
|
175
|
+
).map((dirent) => {
|
|
176
|
+
const direntAbsolutePath = import_node_path.default.join(
|
|
177
|
+
absolutePathToEmailsDirectory,
|
|
178
|
+
dirent.name
|
|
179
|
+
);
|
|
180
|
+
return getEmailsDirectoryMetadata(
|
|
181
|
+
direntAbsolutePath,
|
|
182
|
+
keepFileExtensions,
|
|
183
|
+
true,
|
|
184
|
+
baseDirectoryPath
|
|
185
|
+
);
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
const emailsMetadata = {
|
|
189
|
+
absolutePath: absolutePathToEmailsDirectory,
|
|
190
|
+
relativePath: import_node_path.default.relative(
|
|
191
|
+
baseDirectoryPath,
|
|
192
|
+
absolutePathToEmailsDirectory
|
|
193
|
+
),
|
|
194
|
+
directoryName: absolutePathToEmailsDirectory.split(import_node_path.default.sep).pop(),
|
|
195
|
+
emailFilenames,
|
|
196
|
+
subDirectories
|
|
197
|
+
};
|
|
198
|
+
return isSubDirectory ? mergeDirectoriesWithSubDirectories(emailsMetadata) : emailsMetadata;
|
|
199
|
+
};
|
|
200
|
+
|
|
520
201
|
// src/utils/register-spinner-autostopping.ts
|
|
521
202
|
var import_log_symbols = __toESM(require("log-symbols"));
|
|
522
203
|
var spinners = /* @__PURE__ */ new Set();
|
|
523
|
-
process.on("SIGINT",
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
204
|
+
process.on("SIGINT", () => {
|
|
205
|
+
spinners.forEach((spinner) => {
|
|
206
|
+
if (spinner.isSpinning) {
|
|
207
|
+
spinner.stop();
|
|
208
|
+
}
|
|
209
|
+
});
|
|
529
210
|
});
|
|
530
|
-
process.on("exit",
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
});
|
|
537
|
-
}
|
|
211
|
+
process.on("exit", (code) => {
|
|
212
|
+
if (code !== 0) {
|
|
213
|
+
spinners.forEach((spinner) => {
|
|
214
|
+
if (spinner.isSpinning) {
|
|
215
|
+
spinner.stopAndPersist({
|
|
216
|
+
symbol: import_log_symbols.default.error
|
|
538
217
|
});
|
|
539
|
-
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
540
221
|
});
|
|
541
|
-
var registerSpinnerAutostopping =
|
|
542
|
-
|
|
222
|
+
var registerSpinnerAutostopping = (spinner) => {
|
|
223
|
+
spinners.add(spinner);
|
|
543
224
|
};
|
|
225
|
+
|
|
544
226
|
// src/cli/utils/tree.ts
|
|
545
227
|
var import_node_fs2 = require("fs");
|
|
546
228
|
var import_node_os = __toESM(require("os"));
|
|
547
229
|
var import_node_path2 = __toESM(require("path"));
|
|
548
230
|
var SYMBOLS = {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
231
|
+
BRANCH: "\u251C\u2500\u2500 ",
|
|
232
|
+
EMPTY: "",
|
|
233
|
+
INDENT: " ",
|
|
234
|
+
LAST_BRANCH: "\u2514\u2500\u2500 ",
|
|
235
|
+
VERTICAL: "\u2502 "
|
|
554
236
|
};
|
|
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
|
-
});
|
|
237
|
+
var getTreeLines = async (dirPath, depth, currentDepth = 0) => {
|
|
238
|
+
const base = process.cwd();
|
|
239
|
+
const dirFullpath = import_node_path2.default.resolve(base, dirPath);
|
|
240
|
+
const dirname = import_node_path2.default.basename(dirFullpath);
|
|
241
|
+
let lines = [dirname];
|
|
242
|
+
const dirStat = await import_node_fs2.promises.stat(dirFullpath);
|
|
243
|
+
if (dirStat.isDirectory() && currentDepth < depth) {
|
|
244
|
+
const childDirents = await import_node_fs2.promises.readdir(dirFullpath, { withFileTypes: true });
|
|
245
|
+
childDirents.sort((a, b) => {
|
|
246
|
+
if (a.isDirectory() && b.isFile()) {
|
|
247
|
+
return -1;
|
|
248
|
+
}
|
|
249
|
+
if (a.isFile() && b.isDirectory()) {
|
|
250
|
+
return 1;
|
|
251
|
+
}
|
|
252
|
+
return b.name > a.name ? -1 : 1;
|
|
660
253
|
});
|
|
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
|
-
|
|
254
|
+
for (let i = 0; i < childDirents.length; i++) {
|
|
255
|
+
const dirent = childDirents[i];
|
|
256
|
+
const isLast = i === childDirents.length - 1;
|
|
257
|
+
const branchingSymbol = isLast ? SYMBOLS.LAST_BRANCH : SYMBOLS.BRANCH;
|
|
258
|
+
const verticalSymbol = isLast ? SYMBOLS.INDENT : SYMBOLS.VERTICAL;
|
|
259
|
+
if (dirent.isFile()) {
|
|
260
|
+
lines.push(`${branchingSymbol}${dirent.name}`);
|
|
261
|
+
} else {
|
|
262
|
+
const pathToDirectory = import_node_path2.default.join(dirFullpath, dirent.name);
|
|
263
|
+
const treeLinesForSubDirectory = await getTreeLines(
|
|
264
|
+
pathToDirectory,
|
|
265
|
+
depth,
|
|
266
|
+
currentDepth + 1
|
|
267
|
+
);
|
|
268
|
+
lines = lines.concat(
|
|
269
|
+
treeLinesForSubDirectory.map(
|
|
270
|
+
(line, index) => index === 0 ? `${branchingSymbol}${line}` : `${verticalSymbol}${line}`
|
|
271
|
+
)
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return lines;
|
|
277
|
+
};
|
|
278
|
+
var tree = async (dirPath, depth) => {
|
|
279
|
+
const lines = await getTreeLines(dirPath, depth);
|
|
280
|
+
return lines.join(import_node_os.default.EOL);
|
|
281
|
+
};
|
|
282
|
+
|
|
688
283
|
// src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
689
284
|
var import_node_path7 = __toESM(require("path"));
|
|
690
285
|
var import_chokidar = require("chokidar");
|
|
691
286
|
var import_debounce = __toESM(require("debounce"));
|
|
692
287
|
var import_socket = require("socket.io");
|
|
288
|
+
|
|
693
289
|
// src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
694
290
|
var import_node_fs4 = require("fs");
|
|
695
291
|
var import_node_path6 = __toESM(require("path"));
|
|
292
|
+
|
|
696
293
|
// src/cli/utils/preview/start-dev-server.ts
|
|
697
294
|
var import_node_http = __toESM(require("http"));
|
|
698
295
|
var import_node_path5 = __toESM(require("path"));
|
|
@@ -701,1627 +298,759 @@ var import_chalk = __toESM(require("chalk"));
|
|
|
701
298
|
var import_log_symbols2 = __toESM(require("log-symbols"));
|
|
702
299
|
var import_next = __toESM(require("next"));
|
|
703
300
|
var import_ora = __toESM(require("ora"));
|
|
301
|
+
|
|
704
302
|
// src/cli/utils/preview/get-env-variables-for-preview-app.ts
|
|
705
303
|
var import_node_path3 = __toESM(require("path"));
|
|
706
|
-
var getEnvVariablesForPreviewApp =
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
304
|
+
var getEnvVariablesForPreviewApp = (relativePathToEmailsDirectory, cwd) => {
|
|
305
|
+
return {
|
|
306
|
+
EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
|
|
307
|
+
EMAILS_DIR_ABSOLUTE_PATH: import_node_path3.default.resolve(cwd, relativePathToEmailsDirectory),
|
|
308
|
+
USER_PROJECT_LOCATION: cwd
|
|
309
|
+
};
|
|
712
310
|
};
|
|
311
|
+
|
|
713
312
|
// src/cli/utils/preview/serve-static-file.ts
|
|
714
313
|
var import_node_fs3 = require("fs");
|
|
715
314
|
var import_node_path4 = __toESM(require("path"));
|
|
716
315
|
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
|
-
}();
|
|
316
|
+
var serveStaticFile = async (res, parsedUrl, staticDirRelativePath) => {
|
|
317
|
+
const staticBaseDir = import_node_path4.default.join(process.cwd(), staticDirRelativePath);
|
|
318
|
+
const pathname = parsedUrl.pathname;
|
|
319
|
+
const ext = import_node_path4.default.parse(pathname).ext;
|
|
320
|
+
const fileAbsolutePath = import_node_path4.default.join(staticBaseDir, pathname);
|
|
321
|
+
const fileHandle = await import_node_fs3.promises.open(fileAbsolutePath, "r");
|
|
322
|
+
try {
|
|
323
|
+
const fileData = await import_node_fs3.promises.readFile(fileHandle);
|
|
324
|
+
res.setHeader("Content-type", (0, import_mime_types.lookup)(ext) || "text/plain");
|
|
325
|
+
res.end(fileData);
|
|
326
|
+
} catch (exception) {
|
|
327
|
+
console.error(
|
|
328
|
+
`Could not read file at ${fileAbsolutePath} to be served, here's the exception:`,
|
|
329
|
+
exception
|
|
330
|
+
);
|
|
331
|
+
res.statusCode = 500;
|
|
332
|
+
res.end(
|
|
333
|
+
"Could not read file to be served! Check your terminal for more information."
|
|
334
|
+
);
|
|
335
|
+
} finally {
|
|
336
|
+
fileHandle.close();
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
778
340
|
// src/cli/utils/preview/start-dev-server.ts
|
|
779
341
|
var devServer;
|
|
780
|
-
var safeAsyncServerListen =
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
resolve({
|
|
790
|
-
portAlreadyInUse: true
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
});
|
|
342
|
+
var safeAsyncServerListen = (server, port) => {
|
|
343
|
+
return new Promise((resolve) => {
|
|
344
|
+
server.listen(port, () => {
|
|
345
|
+
resolve({ portAlreadyInUse: false });
|
|
346
|
+
});
|
|
347
|
+
server.on("error", (e) => {
|
|
348
|
+
if (e.code === "EADDRINUSE") {
|
|
349
|
+
resolve({ portAlreadyInUse: true });
|
|
350
|
+
}
|
|
794
351
|
});
|
|
352
|
+
});
|
|
795
353
|
};
|
|
796
354
|
var isDev = !__filename.endsWith(import_node_path5.default.join("cli", "index.js"));
|
|
797
355
|
var cliPacakgeLocation = isDev ? import_node_path5.default.resolve(__dirname, "../../../..") : import_node_path5.default.resolve(__dirname, "../..");
|
|
798
356
|
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
|
-
};
|
|
357
|
+
var startDevServer = async (emailsDirRelativePath, staticBaseDirRelativePath, port) => {
|
|
358
|
+
devServer = import_node_http.default.createServer((req, res) => {
|
|
359
|
+
if (!req.url) {
|
|
360
|
+
res.end(404);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const parsedUrl = import_node_url.default.parse(req.url, true);
|
|
364
|
+
res.setHeader(
|
|
365
|
+
"Cache-Control",
|
|
366
|
+
"no-cache, max-age=0, must-revalidate, no-store"
|
|
367
|
+
);
|
|
368
|
+
res.setHeader("Pragma", "no-cache");
|
|
369
|
+
res.setHeader("Expires", "-1");
|
|
370
|
+
try {
|
|
371
|
+
if (parsedUrl.path?.includes("static/") && !parsedUrl.path.includes("_next/static/")) {
|
|
372
|
+
void serveStaticFile(res, parsedUrl, staticBaseDirRelativePath);
|
|
373
|
+
} else if (!isNextReady) {
|
|
374
|
+
void nextReadyPromise.then(
|
|
375
|
+
() => nextHandleRequest?.(req, res, parsedUrl)
|
|
376
|
+
);
|
|
377
|
+
} else {
|
|
378
|
+
void nextHandleRequest?.(req, res, parsedUrl);
|
|
379
|
+
}
|
|
380
|
+
} catch (e) {
|
|
381
|
+
console.error("caught error", e);
|
|
382
|
+
res.writeHead(500);
|
|
383
|
+
res.end();
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
const { portAlreadyInUse } = await safeAsyncServerListen(devServer, port);
|
|
387
|
+
if (!portAlreadyInUse) {
|
|
388
|
+
console.log(import_chalk.default.greenBright(` React Email ${package_default.version}`));
|
|
389
|
+
console.log(` Running preview at: http://localhost:${port}
|
|
390
|
+
`);
|
|
391
|
+
} else {
|
|
392
|
+
const nextPortToTry = port + 1;
|
|
393
|
+
console.warn(
|
|
394
|
+
` ${import_log_symbols2.default.warning} Port ${port} is already in use, trying ${nextPortToTry}`
|
|
395
|
+
);
|
|
396
|
+
return startDevServer(
|
|
397
|
+
emailsDirRelativePath,
|
|
398
|
+
staticBaseDirRelativePath,
|
|
399
|
+
nextPortToTry
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
devServer.on("close", async () => {
|
|
403
|
+
await app.close();
|
|
404
|
+
});
|
|
405
|
+
devServer.on("error", (e) => {
|
|
406
|
+
console.error(
|
|
407
|
+
` ${import_log_symbols2.default.error} preview server error: `,
|
|
408
|
+
JSON.stringify(e)
|
|
409
|
+
);
|
|
410
|
+
process.exit(1);
|
|
411
|
+
});
|
|
412
|
+
const spinner = (0, import_ora.default)({
|
|
413
|
+
text: "Getting react-email preview server ready...\n",
|
|
414
|
+
prefixText: " "
|
|
415
|
+
}).start();
|
|
416
|
+
registerSpinnerAutostopping(spinner);
|
|
417
|
+
const timeBeforeNextReady = performance.now();
|
|
418
|
+
process.env = {
|
|
419
|
+
NODE_ENV: "development",
|
|
420
|
+
...process.env,
|
|
421
|
+
...getEnvVariablesForPreviewApp(
|
|
422
|
+
// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
|
|
423
|
+
import_node_path5.default.normalize(emailsDirRelativePath),
|
|
424
|
+
process.cwd()
|
|
425
|
+
)
|
|
426
|
+
};
|
|
427
|
+
const app = (0, import_next.default)({
|
|
428
|
+
// passing in env here does not get the environment variables there
|
|
429
|
+
dev: isDev,
|
|
430
|
+
conf: {
|
|
431
|
+
images: {
|
|
432
|
+
// This is to avoid the warning with sharp
|
|
433
|
+
unoptimized: true
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
hostname: "localhost",
|
|
437
|
+
port,
|
|
438
|
+
dir: previewServerLocation
|
|
439
|
+
});
|
|
440
|
+
let isNextReady = false;
|
|
441
|
+
const nextReadyPromise = app.prepare();
|
|
442
|
+
await nextReadyPromise;
|
|
443
|
+
isNextReady = true;
|
|
444
|
+
const nextHandleRequest = app.getRequestHandler();
|
|
445
|
+
const secondsToNextReady = ((performance.now() - timeBeforeNextReady) / 1e3).toFixed(1);
|
|
446
|
+
spinner.stopAndPersist({
|
|
447
|
+
text: `Ready in ${secondsToNextReady}s
|
|
448
|
+
`,
|
|
449
|
+
symbol: import_log_symbols2.default.success
|
|
450
|
+
});
|
|
451
|
+
return devServer;
|
|
452
|
+
};
|
|
453
|
+
var makeExitHandler = (options) => (_codeOrSignal) => {
|
|
454
|
+
if (typeof devServer !== "undefined") {
|
|
455
|
+
console.log("\nshutting down dev server");
|
|
456
|
+
devServer.close();
|
|
457
|
+
devServer = void 0;
|
|
458
|
+
}
|
|
459
|
+
if (options?.shouldKillProcess) {
|
|
460
|
+
process.exit(options.killWithErrorCode ? 1 : 0);
|
|
461
|
+
}
|
|
928
462
|
};
|
|
929
463
|
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
|
-
|
|
464
|
+
process.on(
|
|
465
|
+
"SIGINT",
|
|
466
|
+
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
467
|
+
);
|
|
468
|
+
process.on(
|
|
469
|
+
"SIGUSR1",
|
|
470
|
+
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
471
|
+
);
|
|
472
|
+
process.on(
|
|
473
|
+
"SIGUSR2",
|
|
474
|
+
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
475
|
+
);
|
|
476
|
+
process.on(
|
|
477
|
+
"uncaughtException",
|
|
478
|
+
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: true })
|
|
479
|
+
);
|
|
480
|
+
|
|
946
481
|
// src/cli/utils/preview/hot-reloading/get-imported-modules.ts
|
|
947
482
|
var import_parser = require("@babel/parser");
|
|
948
483
|
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
|
-
}
|
|
484
|
+
var getImportedModules = (contents) => {
|
|
485
|
+
const importedPaths = [];
|
|
486
|
+
const parsedContents = (0, import_parser.parse)(contents, {
|
|
487
|
+
sourceType: "unambiguous",
|
|
488
|
+
strictMode: false,
|
|
489
|
+
errorRecovery: true,
|
|
490
|
+
plugins: ["jsx", "typescript", "decorators"]
|
|
491
|
+
});
|
|
492
|
+
(0, import_traverse.default)(parsedContents, {
|
|
493
|
+
ImportDeclaration({ node }) {
|
|
494
|
+
importedPaths.push(node.source.value);
|
|
495
|
+
},
|
|
496
|
+
ExportAllDeclaration({ node }) {
|
|
497
|
+
importedPaths.push(node.source.value);
|
|
498
|
+
},
|
|
499
|
+
ExportNamedDeclaration({ node }) {
|
|
500
|
+
if (node.source) {
|
|
501
|
+
importedPaths.push(node.source.value);
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
CallExpression({ node }) {
|
|
505
|
+
if ("name" in node.callee && node.callee.name === "require") {
|
|
506
|
+
if (node.arguments.length === 1) {
|
|
507
|
+
const importPathNode = node.arguments[0];
|
|
508
|
+
if (importPathNode.type === "StringLiteral") {
|
|
509
|
+
importedPaths.push(importPathNode.value);
|
|
510
|
+
}
|
|
986
511
|
}
|
|
987
|
-
|
|
988
|
-
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
return importedPaths;
|
|
989
516
|
};
|
|
517
|
+
|
|
990
518
|
// 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");
|
|
519
|
+
var readAllFilesInsideDirectory = async (directory) => {
|
|
520
|
+
let allFilePaths = [];
|
|
521
|
+
const topLevelDirents = await import_node_fs4.promises.readdir(directory, { withFileTypes: true });
|
|
522
|
+
for await (const dirent of topLevelDirents) {
|
|
523
|
+
const pathToDirent = import_node_path6.default.join(directory, dirent.name);
|
|
524
|
+
if (dirent.isDirectory()) {
|
|
525
|
+
allFilePaths = allFilePaths.concat(
|
|
526
|
+
await readAllFilesInsideDirectory(pathToDirent)
|
|
527
|
+
);
|
|
528
|
+
} else {
|
|
529
|
+
allFilePaths.push(pathToDirent);
|
|
1144
530
|
}
|
|
531
|
+
}
|
|
532
|
+
return allFilePaths;
|
|
533
|
+
};
|
|
534
|
+
var isJavascriptModule = (filePath) => {
|
|
535
|
+
const extensionName = import_node_path6.default.extname(filePath);
|
|
536
|
+
return [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"].includes(extensionName);
|
|
537
|
+
};
|
|
538
|
+
var checkFileExtensionsUntilItExists = (pathWithoutExtension) => {
|
|
539
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.ts`)) {
|
|
540
|
+
return `${pathWithoutExtension}.ts`;
|
|
541
|
+
}
|
|
542
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.tsx`)) {
|
|
543
|
+
return `${pathWithoutExtension}.tsx`;
|
|
544
|
+
}
|
|
545
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.js`)) {
|
|
546
|
+
return `${pathWithoutExtension}.js`;
|
|
547
|
+
}
|
|
548
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.jsx`)) {
|
|
549
|
+
return `${pathWithoutExtension}.jsx`;
|
|
550
|
+
}
|
|
551
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.mjs`)) {
|
|
552
|
+
return `${pathWithoutExtension}.mjs`;
|
|
553
|
+
}
|
|
554
|
+
if ((0, import_node_fs4.existsSync)(`${pathWithoutExtension}.cjs`)) {
|
|
555
|
+
return `${pathWithoutExtension}.cjs`;
|
|
556
|
+
}
|
|
1145
557
|
};
|
|
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(/*
|
|
558
|
+
var createDependencyGraph = async (directory) => {
|
|
559
|
+
const filePaths = await readAllFilesInsideDirectory(directory);
|
|
560
|
+
const modulePaths = filePaths.filter(isJavascriptModule);
|
|
561
|
+
const graph = Object.fromEntries(
|
|
562
|
+
modulePaths.map((path12) => [
|
|
563
|
+
path12,
|
|
564
|
+
{
|
|
565
|
+
path: path12,
|
|
566
|
+
dependencyPaths: [],
|
|
567
|
+
dependentPaths: [],
|
|
568
|
+
moduleDependencies: []
|
|
569
|
+
}
|
|
570
|
+
])
|
|
571
|
+
);
|
|
572
|
+
const getDependencyPaths = async (filePath) => {
|
|
573
|
+
const contents = await import_node_fs4.promises.readFile(filePath, "utf8");
|
|
574
|
+
const importedPaths = getImportedModules(contents);
|
|
575
|
+
const importedPathsRelativeToDirectory = importedPaths.map(
|
|
576
|
+
(dependencyPath) => {
|
|
577
|
+
const isModulePath = !dependencyPath.startsWith(".");
|
|
578
|
+
if (isModulePath || import_node_path6.default.isAbsolute(dependencyPath)) {
|
|
579
|
+
return dependencyPath;
|
|
580
|
+
}
|
|
581
|
+
let pathToDependencyFromDirectory = import_node_path6.default.resolve(
|
|
582
|
+
/*
|
|
1189
583
|
path.resolve resolves paths differently from what imports on javascript do.
|
|
1190
584
|
|
|
1191
585
|
So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependecy path of "./other-email"
|
|
1192
586
|
would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
|
|
1193
587
|
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);
|
|
588
|
+
*/
|
|
589
|
+
import_node_path6.default.dirname(filePath),
|
|
590
|
+
dependencyPath
|
|
591
|
+
);
|
|
592
|
+
let isDirectory = false;
|
|
593
|
+
try {
|
|
594
|
+
isDirectory = (0, import_node_fs4.statSync)(pathToDependencyFromDirectory).isDirectory();
|
|
595
|
+
} catch (_) {
|
|
596
|
+
}
|
|
597
|
+
if (isDirectory) {
|
|
598
|
+
const pathToSubDirectory = pathToDependencyFromDirectory;
|
|
599
|
+
const pathWithExtension = checkFileExtensionsUntilItExists(
|
|
600
|
+
`${pathToSubDirectory}/index`
|
|
601
|
+
);
|
|
602
|
+
if (pathWithExtension) {
|
|
603
|
+
pathToDependencyFromDirectory = pathWithExtension;
|
|
604
|
+
} else if (isDev) {
|
|
605
|
+
console.warn(
|
|
606
|
+
`Could not find index file for directory at ${pathToDependencyFromDirectory}. This is probably going to cause issues with both hot reloading and your code.`
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (!isJavascriptModule(pathToDependencyFromDirectory)) {
|
|
611
|
+
const pathWithExtension = checkFileExtensionsUntilItExists(
|
|
612
|
+
pathToDependencyFromDirectory
|
|
613
|
+
);
|
|
614
|
+
if (pathWithExtension) {
|
|
615
|
+
pathToDependencyFromDirectory = pathWithExtension;
|
|
616
|
+
} else if (isDev) {
|
|
617
|
+
console.warn(
|
|
618
|
+
`Could not determine the file extension for the file at ${pathToDependencyFromDirectory}`
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return pathToDependencyFromDirectory;
|
|
623
|
+
}
|
|
624
|
+
);
|
|
625
|
+
const moduleDependencies = importedPathsRelativeToDirectory.filter(
|
|
626
|
+
(dependencyPath) => !dependencyPath.startsWith(".") && !import_node_path6.default.isAbsolute(dependencyPath)
|
|
627
|
+
);
|
|
628
|
+
const nonNodeModuleImportPathsRelativeToDirectory = importedPathsRelativeToDirectory.filter(
|
|
629
|
+
(dependencyPath) => dependencyPath.startsWith(".") || import_node_path6.default.isAbsolute(dependencyPath)
|
|
630
|
+
);
|
|
631
|
+
return {
|
|
632
|
+
dependencyPaths: nonNodeModuleImportPathsRelativeToDirectory,
|
|
633
|
+
moduleDependencies
|
|
1734
634
|
};
|
|
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);
|
|
635
|
+
};
|
|
636
|
+
const updateModuleDependenciesInGraph = async (moduleFilePath) => {
|
|
637
|
+
const module2 = graph[moduleFilePath] ?? {
|
|
638
|
+
path: moduleFilePath,
|
|
639
|
+
dependencyPaths: [],
|
|
640
|
+
dependentPaths: [],
|
|
641
|
+
moduleDependencies: []
|
|
1935
642
|
};
|
|
1936
|
-
}();
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
643
|
+
const { moduleDependencies, dependencyPaths: newDependencyPaths } = await getDependencyPaths(moduleFilePath);
|
|
644
|
+
module2.moduleDependencies = moduleDependencies;
|
|
645
|
+
for (const dependencyPath of module2.dependencyPaths) {
|
|
646
|
+
if (newDependencyPaths.includes(dependencyPath))
|
|
647
|
+
continue;
|
|
648
|
+
const dependencyModule = graph[dependencyPath];
|
|
649
|
+
if (dependencyModule !== void 0) {
|
|
650
|
+
dependencyModule.dependentPaths = dependencyModule.dependentPaths.filter(
|
|
651
|
+
(dependentPath) => dependentPath !== moduleFilePath
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
module2.dependencyPaths = newDependencyPaths;
|
|
656
|
+
for (const dependencyPath of newDependencyPaths) {
|
|
657
|
+
const dependencyModule = graph[dependencyPath];
|
|
658
|
+
if (dependencyModule !== void 0 && !dependencyModule.dependentPaths.includes(moduleFilePath)) {
|
|
659
|
+
dependencyModule.dependentPaths.push(moduleFilePath);
|
|
660
|
+
} else {
|
|
661
|
+
graph[dependencyPath] = {
|
|
662
|
+
path: dependencyPath,
|
|
663
|
+
moduleDependencies: [],
|
|
664
|
+
dependencyPaths: [],
|
|
665
|
+
dependentPaths: [moduleFilePath]
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
graph[moduleFilePath] = module2;
|
|
670
|
+
};
|
|
671
|
+
for (const filePath of modulePaths) {
|
|
672
|
+
await updateModuleDependenciesInGraph(filePath);
|
|
673
|
+
}
|
|
674
|
+
const removeModuleFromGraph = (filePath) => {
|
|
675
|
+
const module2 = graph[filePath];
|
|
676
|
+
if (module2) {
|
|
677
|
+
for (const dependencyPath of module2.dependencyPaths) {
|
|
678
|
+
if (graph[dependencyPath]) {
|
|
679
|
+
graph[dependencyPath].dependentPaths = graph[dependencyPath].dependentPaths.filter(
|
|
680
|
+
(dependentPath) => dependentPath !== filePath
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
delete graph[filePath];
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
return [
|
|
688
|
+
graph,
|
|
689
|
+
async (event, pathToModified) => {
|
|
690
|
+
switch (event) {
|
|
691
|
+
case "change":
|
|
692
|
+
if (isJavascriptModule(pathToModified)) {
|
|
693
|
+
await updateModuleDependenciesInGraph(pathToModified);
|
|
694
|
+
}
|
|
695
|
+
break;
|
|
696
|
+
case "add":
|
|
697
|
+
if (isJavascriptModule(pathToModified)) {
|
|
698
|
+
await updateModuleDependenciesInGraph(pathToModified);
|
|
699
|
+
}
|
|
700
|
+
break;
|
|
701
|
+
case "addDir": {
|
|
702
|
+
const filesInsideAddedDirectory = await readAllFilesInsideDirectory(pathToModified);
|
|
703
|
+
const modulesInsideAddedDirectory = filesInsideAddedDirectory.filter(isJavascriptModule);
|
|
704
|
+
for await (const filePath of modulesInsideAddedDirectory) {
|
|
705
|
+
await updateModuleDependenciesInGraph(filePath);
|
|
706
|
+
}
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
case "unlink":
|
|
710
|
+
if (isJavascriptModule(pathToModified)) {
|
|
711
|
+
removeModuleFromGraph(pathToModified);
|
|
712
|
+
}
|
|
713
|
+
break;
|
|
714
|
+
case "unlinkDir": {
|
|
715
|
+
const filesInsideDeletedDirectory = await readAllFilesInsideDirectory(pathToModified);
|
|
716
|
+
const modulesInsideDeletedDirectory = filesInsideDeletedDirectory.filter(isJavascriptModule);
|
|
717
|
+
for await (const filePath of modulesInsideDeletedDirectory) {
|
|
718
|
+
removeModuleFromGraph(filePath);
|
|
719
|
+
}
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
resolveDependentsOf: function resolveDependentsOf(pathToModule) {
|
|
726
|
+
const moduleEntry = graph[pathToModule];
|
|
727
|
+
const dependentPaths = [];
|
|
728
|
+
if (moduleEntry) {
|
|
729
|
+
for (const dependentPath of moduleEntry.dependentPaths) {
|
|
730
|
+
const dependentsOfDependent = resolveDependentsOf(dependentPath);
|
|
731
|
+
dependentPaths.push(...dependentsOfDependent);
|
|
732
|
+
dependentPaths.push(dependentPath);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return dependentPaths;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
];
|
|
1957
739
|
};
|
|
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
|
-
});
|
|
740
|
+
|
|
741
|
+
// src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
742
|
+
var setupHotreloading = async (devServer2, emailDirRelativePath) => {
|
|
743
|
+
let clients = [];
|
|
744
|
+
const io = new import_socket.Server(devServer2);
|
|
745
|
+
io.on("connection", (client) => {
|
|
746
|
+
clients.push(client);
|
|
747
|
+
client.on("disconnect", () => {
|
|
748
|
+
clients = clients.filter((item) => item !== client);
|
|
1976
749
|
});
|
|
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
|
-
}));
|
|
750
|
+
});
|
|
751
|
+
let changes = [];
|
|
752
|
+
const reload = (0, import_debounce.default)(() => {
|
|
753
|
+
clients.forEach((client) => {
|
|
754
|
+
client.emit("reload", changes);
|
|
1988
755
|
});
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
756
|
+
changes = [];
|
|
757
|
+
}, 150);
|
|
758
|
+
const absolutePathToEmailsDirectory = import_node_path7.default.resolve(
|
|
759
|
+
process.cwd(),
|
|
760
|
+
emailDirRelativePath
|
|
761
|
+
);
|
|
762
|
+
const [dependencyGraph, updateDependencyGraph, { resolveDependentsOf }] = await createDependencyGraph(absolutePathToEmailsDirectory);
|
|
763
|
+
const watcher = (0, import_chokidar.watch)("", {
|
|
764
|
+
ignoreInitial: true,
|
|
765
|
+
cwd: absolutePathToEmailsDirectory
|
|
766
|
+
});
|
|
767
|
+
const getFilesOutsideEmailsDirectory = () => Object.keys(dependencyGraph).filter(
|
|
768
|
+
(p) => import_node_path7.default.relative(absolutePathToEmailsDirectory, p).startsWith("..")
|
|
769
|
+
);
|
|
770
|
+
let filesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
771
|
+
for (const p of filesOutsideEmailsDirectory) {
|
|
772
|
+
watcher.add(p);
|
|
773
|
+
}
|
|
774
|
+
const exit = async () => {
|
|
775
|
+
await watcher.close();
|
|
776
|
+
};
|
|
777
|
+
process.on("SIGINT", exit);
|
|
778
|
+
process.on("uncaughtException", exit);
|
|
779
|
+
watcher.on("all", async (event, relativePathToChangeTarget) => {
|
|
780
|
+
const file = relativePathToChangeTarget.split(import_node_path7.default.sep);
|
|
781
|
+
if (file.length === 0) {
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
const pathToChangeTarget = import_node_path7.default.resolve(
|
|
785
|
+
absolutePathToEmailsDirectory,
|
|
786
|
+
relativePathToChangeTarget
|
|
787
|
+
);
|
|
788
|
+
await updateDependencyGraph(event, pathToChangeTarget);
|
|
789
|
+
const newFilesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
790
|
+
for (const p of filesOutsideEmailsDirectory) {
|
|
791
|
+
if (!newFilesOutsideEmailsDirectory.includes(p)) {
|
|
792
|
+
watcher.unwatch(p);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
for (const p of newFilesOutsideEmailsDirectory) {
|
|
796
|
+
if (!filesOutsideEmailsDirectory.includes(p)) {
|
|
797
|
+
watcher.add(p);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
filesOutsideEmailsDirectory = newFilesOutsideEmailsDirectory;
|
|
801
|
+
changes.push({
|
|
802
|
+
event,
|
|
803
|
+
filename: relativePathToChangeTarget
|
|
1992
804
|
});
|
|
1993
|
-
|
|
805
|
+
for (const dependentPath of resolveDependentsOf(pathToChangeTarget)) {
|
|
806
|
+
changes.push({
|
|
807
|
+
event: "change",
|
|
808
|
+
filename: import_node_path7.default.relative(absolutePathToEmailsDirectory, dependentPath)
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
reload();
|
|
812
|
+
});
|
|
813
|
+
return watcher;
|
|
1994
814
|
};
|
|
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
|
-
});
|
|
815
|
+
|
|
816
|
+
// src/cli/commands/build.ts
|
|
817
|
+
var buildPreviewApp = (absoluteDirectory) => {
|
|
818
|
+
return new Promise((resolve, reject) => {
|
|
819
|
+
const nextBuild = (0, import_node_child_process.spawn)("npm", ["run", "build"], {
|
|
820
|
+
cwd: absoluteDirectory,
|
|
821
|
+
shell: true
|
|
2064
822
|
});
|
|
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
|
-
});
|
|
823
|
+
nextBuild.stdout.pipe(process.stdout);
|
|
824
|
+
nextBuild.stderr.pipe(process.stderr);
|
|
825
|
+
nextBuild.on("close", (code) => {
|
|
826
|
+
if (code === 0) {
|
|
827
|
+
resolve();
|
|
828
|
+
} else {
|
|
829
|
+
reject(
|
|
830
|
+
new Error(
|
|
831
|
+
`Unable to build the Next app and it exited with code: ${code}`
|
|
832
|
+
)
|
|
833
|
+
);
|
|
834
|
+
}
|
|
2101
835
|
});
|
|
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
|
-
|
|
836
|
+
});
|
|
837
|
+
};
|
|
838
|
+
var setNextEnvironmentVariablesForBuild = async (emailsDirRelativePath, builtPreviewAppPath) => {
|
|
839
|
+
const nextConfigContents = `
|
|
840
|
+
const path = require('path');
|
|
841
|
+
const emailsDirRelativePath = path.normalize('${emailsDirRelativePath}');
|
|
842
|
+
const userProjectLocation = path.resolve(process.cwd(), '../');
|
|
843
|
+
/** @type {import('next').NextConfig} */
|
|
844
|
+
module.exports = {
|
|
845
|
+
env: {
|
|
846
|
+
NEXT_PUBLIC_IS_BUILDING: 'true',
|
|
847
|
+
EMAILS_DIR_RELATIVE_PATH: emailsDirRelativePath,
|
|
848
|
+
EMAILS_DIR_ABSOLUTE_PATH: path.resolve(userProjectLocation, emailsDirRelativePath),
|
|
849
|
+
USER_PROJECT_LOCATION: userProjectLocation
|
|
850
|
+
},
|
|
851
|
+
// this is needed so that the code for building emails works properly
|
|
852
|
+
webpack: (
|
|
853
|
+
/** @type {import('webpack').Configuration & { externals: string[] }} */
|
|
854
|
+
config,
|
|
855
|
+
{ isServer }
|
|
856
|
+
) => {
|
|
857
|
+
if (isServer) {
|
|
858
|
+
config.externals.push('esbuild');
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
return config;
|
|
862
|
+
},
|
|
863
|
+
typescript: {
|
|
864
|
+
ignoreBuildErrors: true
|
|
865
|
+
},
|
|
866
|
+
eslint: {
|
|
867
|
+
ignoreDuringBuilds: true
|
|
868
|
+
},
|
|
869
|
+
experimental: {
|
|
870
|
+
webpackBuildWorker: true
|
|
871
|
+
},
|
|
872
|
+
}`;
|
|
873
|
+
await import_node_fs5.default.promises.writeFile(
|
|
874
|
+
import_node_path8.default.resolve(builtPreviewAppPath, "./next.config.js"),
|
|
875
|
+
nextConfigContents,
|
|
876
|
+
"utf8"
|
|
877
|
+
);
|
|
878
|
+
};
|
|
879
|
+
var getEmailSlugsFromEmailDirectory = (emailDirectory, emailsDirectoryAbsolutePath) => {
|
|
880
|
+
const directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
|
|
881
|
+
const slugs = [];
|
|
882
|
+
emailDirectory.emailFilenames.forEach(
|
|
883
|
+
(filename) => slugs.push(
|
|
884
|
+
import_node_path8.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path8.default.sep).filter((segment) => segment.length > 0)
|
|
885
|
+
)
|
|
886
|
+
);
|
|
887
|
+
emailDirectory.subDirectories.forEach((directory) => {
|
|
888
|
+
slugs.push(
|
|
889
|
+
...getEmailSlugsFromEmailDirectory(
|
|
890
|
+
directory,
|
|
891
|
+
emailsDirectoryAbsolutePath
|
|
892
|
+
)
|
|
893
|
+
);
|
|
894
|
+
});
|
|
895
|
+
return slugs;
|
|
896
|
+
};
|
|
897
|
+
var forceSSGForEmailPreviews = async (emailsDirPath, builtPreviewAppPath) => {
|
|
898
|
+
const emailDirectoryMetadata = (
|
|
899
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
900
|
+
await getEmailsDirectoryMetadata(emailsDirPath)
|
|
901
|
+
);
|
|
902
|
+
const parameters = getEmailSlugsFromEmailDirectory(
|
|
903
|
+
emailDirectoryMetadata,
|
|
904
|
+
emailsDirPath
|
|
905
|
+
).map((slug) => ({ slug }));
|
|
906
|
+
const removeForceDynamic = async (filePath) => {
|
|
907
|
+
const contents = await import_node_fs5.default.promises.readFile(filePath, "utf8");
|
|
908
|
+
await import_node_fs5.default.promises.writeFile(
|
|
909
|
+
filePath,
|
|
910
|
+
contents.replace("export const dynamic = 'force-dynamic';", ""),
|
|
911
|
+
"utf8"
|
|
912
|
+
);
|
|
913
|
+
};
|
|
914
|
+
await removeForceDynamic(
|
|
915
|
+
import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/layout.tsx")
|
|
916
|
+
);
|
|
917
|
+
await removeForceDynamic(
|
|
918
|
+
import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx")
|
|
919
|
+
);
|
|
920
|
+
await import_node_fs5.default.promises.appendFile(
|
|
921
|
+
import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"),
|
|
922
|
+
`
|
|
923
|
+
|
|
924
|
+
export function generateStaticParams() {
|
|
925
|
+
return Promise.resolve(
|
|
926
|
+
${JSON.stringify(parameters)}
|
|
927
|
+
);
|
|
928
|
+
}`,
|
|
929
|
+
"utf8"
|
|
930
|
+
);
|
|
931
|
+
};
|
|
932
|
+
var updatePackageJson = async (builtPreviewAppPath) => {
|
|
933
|
+
const packageJsonPath = import_node_path8.default.resolve(builtPreviewAppPath, "./package.json");
|
|
934
|
+
const packageJson = JSON.parse(
|
|
935
|
+
await import_node_fs5.default.promises.readFile(packageJsonPath, "utf8")
|
|
936
|
+
);
|
|
937
|
+
packageJson.scripts.build = "next build";
|
|
938
|
+
packageJson.scripts.start = "next start";
|
|
939
|
+
packageJson.name = "preview-server";
|
|
940
|
+
delete packageJson.devDependencies["@react-email/render"];
|
|
941
|
+
delete packageJson.devDependencies["@react-email/components"];
|
|
942
|
+
await import_node_fs5.default.promises.writeFile(
|
|
943
|
+
packageJsonPath,
|
|
944
|
+
JSON.stringify(packageJson),
|
|
945
|
+
"utf8"
|
|
946
|
+
);
|
|
947
|
+
};
|
|
948
|
+
var npmInstall = async (builtPreviewAppPath, packageManager) => {
|
|
949
|
+
return new Promise((resolve, reject) => {
|
|
950
|
+
const childProc = (0, import_node_child_process.spawn)(
|
|
951
|
+
packageManager,
|
|
952
|
+
["install", "--silent", "--include=dev"],
|
|
953
|
+
{
|
|
954
|
+
cwd: builtPreviewAppPath,
|
|
955
|
+
shell: true
|
|
956
|
+
}
|
|
957
|
+
);
|
|
958
|
+
childProc.stdout.pipe(process.stdout);
|
|
959
|
+
childProc.stderr.pipe(process.stderr);
|
|
960
|
+
childProc.on("close", (code) => {
|
|
961
|
+
if (code === 0) {
|
|
962
|
+
resolve();
|
|
963
|
+
} else {
|
|
964
|
+
reject(
|
|
965
|
+
new Error(
|
|
966
|
+
`Unable to install the dependencies and it exited with code: ${code}`
|
|
967
|
+
)
|
|
968
|
+
);
|
|
969
|
+
}
|
|
2132
970
|
});
|
|
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
|
-
});
|
|
971
|
+
});
|
|
972
|
+
};
|
|
973
|
+
var build = async ({
|
|
974
|
+
dir: emailsDirRelativePath,
|
|
975
|
+
packageManager
|
|
976
|
+
}) => {
|
|
977
|
+
try {
|
|
978
|
+
const spinner = (0, import_ora2.default)({
|
|
979
|
+
text: "Starting build process...",
|
|
980
|
+
prefixText: " "
|
|
981
|
+
}).start();
|
|
982
|
+
registerSpinnerAutostopping(spinner);
|
|
983
|
+
spinner.text = `Checking if ${emailsDirRelativePath} folder exists`;
|
|
984
|
+
if (!import_node_fs5.default.existsSync(emailsDirRelativePath)) {
|
|
985
|
+
process.exit(1);
|
|
986
|
+
}
|
|
987
|
+
const emailsDirPath = import_node_path8.default.join(process.cwd(), emailsDirRelativePath);
|
|
988
|
+
const staticPath = import_node_path8.default.join(emailsDirPath, "static");
|
|
989
|
+
const builtPreviewAppPath = import_node_path8.default.join(process.cwd(), ".react-email");
|
|
990
|
+
if (import_node_fs5.default.existsSync(builtPreviewAppPath)) {
|
|
991
|
+
spinner.text = "Deleting pre-existing `.react-email` folder";
|
|
992
|
+
await import_node_fs5.default.promises.rm(builtPreviewAppPath, { recursive: true });
|
|
993
|
+
}
|
|
994
|
+
spinner.text = "Copying preview app from CLI to `.react-email`";
|
|
995
|
+
await import_node_fs5.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
|
|
996
|
+
recursive: true,
|
|
997
|
+
filter: (source) => {
|
|
998
|
+
return !/(\/|\\)cli(\/|\\)?/.test(source) && !/(\/|\\)\.next(\/|\\)?/.test(source) && !/(\/|\\)\.turbo(\/|\\)?/.test(source) && !/(\/|\\)node_modules(\/|\\)?$/.test(source);
|
|
999
|
+
}
|
|
2263
1000
|
});
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
1001
|
+
if (import_node_fs5.default.existsSync(staticPath)) {
|
|
1002
|
+
spinner.text = "Copying `static` folder into `.react-email/public/static`";
|
|
1003
|
+
const builtStaticDirectory = import_node_path8.default.resolve(
|
|
1004
|
+
builtPreviewAppPath,
|
|
1005
|
+
"./public/static"
|
|
1006
|
+
);
|
|
1007
|
+
await import_node_fs5.default.promises.cp(staticPath, builtStaticDirectory, {
|
|
1008
|
+
recursive: true
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
spinner.text = "Setting Next environment variables for preview app to work properly";
|
|
1012
|
+
await setNextEnvironmentVariablesForBuild(
|
|
1013
|
+
emailsDirRelativePath,
|
|
1014
|
+
builtPreviewAppPath
|
|
1015
|
+
);
|
|
1016
|
+
spinner.text = "Setting server side generation for the email preview pages";
|
|
1017
|
+
await forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath);
|
|
1018
|
+
spinner.text = "Updating package.json's build and start scripts";
|
|
1019
|
+
await updatePackageJson(builtPreviewAppPath);
|
|
1020
|
+
spinner.text = "Installing dependencies on `.react-email`";
|
|
1021
|
+
await npmInstall(builtPreviewAppPath, packageManager);
|
|
1022
|
+
spinner.stopAndPersist({
|
|
1023
|
+
text: "Successfully prepared `.react-email` for `next build`",
|
|
1024
|
+
symbol: import_log_symbols3.default.success
|
|
1025
|
+
});
|
|
1026
|
+
await buildPreviewApp(builtPreviewAppPath);
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
console.log(error);
|
|
1029
|
+
process.exit(1);
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
|
|
2268
1033
|
// src/cli/commands/dev.ts
|
|
2269
1034
|
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
|
-
}();
|
|
1035
|
+
var dev = async ({ dir: emailsDirRelativePath, port }) => {
|
|
1036
|
+
try {
|
|
1037
|
+
if (!import_node_fs6.default.existsSync(emailsDirRelativePath)) {
|
|
1038
|
+
console.error(`Missing ${emailsDirRelativePath} folder`);
|
|
1039
|
+
process.exit(1);
|
|
1040
|
+
}
|
|
1041
|
+
const devServer2 = await startDevServer(
|
|
1042
|
+
emailsDirRelativePath,
|
|
1043
|
+
emailsDirRelativePath,
|
|
1044
|
+
// defaults to ./emails/static for the static files that are served to the preview
|
|
1045
|
+
Number.parseInt(port)
|
|
1046
|
+
);
|
|
1047
|
+
await setupHotreloading(devServer2, emailsDirRelativePath);
|
|
1048
|
+
} catch (error) {
|
|
1049
|
+
console.log(error);
|
|
1050
|
+
process.exit(1);
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
|
|
2325
1054
|
// src/cli/commands/export.ts
|
|
2326
1055
|
var import_node_fs8 = __toESM(require("fs"));
|
|
2327
1056
|
var import_node_path10 = __toESM(require("path"));
|
|
@@ -2330,457 +1059,244 @@ var import_glob = require("glob");
|
|
|
2330
1059
|
var import_log_symbols4 = __toESM(require("log-symbols"));
|
|
2331
1060
|
var import_normalize_path = __toESM(require("normalize-path"));
|
|
2332
1061
|
var import_ora3 = __toESM(require("ora"));
|
|
1062
|
+
|
|
2333
1063
|
// src/utils/esbuild/renderring-utilities-exporter.ts
|
|
2334
1064
|
var import_node_fs7 = require("fs");
|
|
2335
1065
|
var import_node_path9 = __toESM(require("path"));
|
|
1066
|
+
|
|
2336
1067
|
// src/utils/esbuild/escape-string-for-regex.ts
|
|
2337
1068
|
function escapeStringForRegex(string) {
|
|
2338
|
-
|
|
1069
|
+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
2339
1070
|
}
|
|
1071
|
+
|
|
2340
1072
|
// 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
|
-
}());
|
|
1073
|
+
var renderingUtilitiesExporter = (emailTemplates) => ({
|
|
1074
|
+
name: "rendering-utilities-exporter",
|
|
1075
|
+
setup: (b) => {
|
|
1076
|
+
b.onLoad(
|
|
1077
|
+
{
|
|
1078
|
+
filter: new RegExp(
|
|
1079
|
+
emailTemplates.map((emailPath) => escapeStringForRegex(emailPath)).join("|")
|
|
1080
|
+
)
|
|
1081
|
+
},
|
|
1082
|
+
async ({ path: pathToFile }) => {
|
|
1083
|
+
return {
|
|
1084
|
+
contents: `${await import_node_fs7.promises.readFile(pathToFile, "utf8")};
|
|
1085
|
+
export { render } from 'react-email-module-that-will-export-render'
|
|
1086
|
+
export { createElement as reactEmailCreateReactElement } from 'react';
|
|
1087
|
+
`,
|
|
1088
|
+
loader: import_node_path9.default.extname(pathToFile).slice(1)
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
);
|
|
1092
|
+
b.onResolve(
|
|
1093
|
+
{ filter: /^react-email-module-that-will-export-render$/ },
|
|
1094
|
+
async (args) => {
|
|
1095
|
+
const options = {
|
|
1096
|
+
kind: "import-statement",
|
|
1097
|
+
importer: args.importer,
|
|
1098
|
+
resolveDir: args.resolveDir,
|
|
1099
|
+
namespace: args.namespace
|
|
1100
|
+
};
|
|
1101
|
+
let result = await b.resolve("@react-email/render", options);
|
|
1102
|
+
if (result.errors.length === 0) {
|
|
1103
|
+
return result;
|
|
2423
1104
|
}
|
|
2424
|
-
|
|
2425
|
-
|
|
1105
|
+
result = await b.resolve("@react-email/components", options);
|
|
1106
|
+
if (result.errors.length > 0 && result.errors[0]) {
|
|
1107
|
+
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?";
|
|
1108
|
+
}
|
|
1109
|
+
return result;
|
|
1110
|
+
}
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
|
|
2426
1115
|
// src/cli/commands/export.ts
|
|
2427
|
-
var getEmailTemplatesFromDirectory =
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
return templatePaths;
|
|
1116
|
+
var getEmailTemplatesFromDirectory = (emailDirectory) => {
|
|
1117
|
+
const templatePaths = [];
|
|
1118
|
+
emailDirectory.emailFilenames.forEach(
|
|
1119
|
+
(filename) => templatePaths.push(import_node_path10.default.join(emailDirectory.absolutePath, filename))
|
|
1120
|
+
);
|
|
1121
|
+
emailDirectory.subDirectories.forEach((directory) => {
|
|
1122
|
+
templatePaths.push(...getEmailTemplatesFromDirectory(directory));
|
|
1123
|
+
});
|
|
1124
|
+
return templatePaths;
|
|
2437
1125
|
};
|
|
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
|
-
}
|
|
1126
|
+
var exportTemplates = async (pathToWhereEmailMarkupShouldBeDumped, emailsDirectoryPath, options) => {
|
|
1127
|
+
if (import_node_fs8.default.existsSync(pathToWhereEmailMarkupShouldBeDumped)) {
|
|
1128
|
+
import_node_fs8.default.rmSync(pathToWhereEmailMarkupShouldBeDumped, { recursive: true });
|
|
1129
|
+
}
|
|
1130
|
+
let spinner;
|
|
1131
|
+
if (!options.silent) {
|
|
1132
|
+
spinner = (0, import_ora3.default)("Preparing files...\n").start();
|
|
1133
|
+
registerSpinnerAutostopping(spinner);
|
|
1134
|
+
}
|
|
1135
|
+
const emailsDirectoryMetadata = await getEmailsDirectoryMetadata(
|
|
1136
|
+
import_node_path10.default.resolve(process.cwd(), emailsDirectoryPath),
|
|
1137
|
+
true
|
|
1138
|
+
);
|
|
1139
|
+
if (typeof emailsDirectoryMetadata === "undefined") {
|
|
1140
|
+
if (spinner) {
|
|
1141
|
+
spinner.stopAndPersist({
|
|
1142
|
+
symbol: import_log_symbols4.default.error,
|
|
1143
|
+
text: `Could not find the directory at ${emailsDirectoryPath}`
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
const allTemplates = getEmailTemplatesFromDirectory(emailsDirectoryMetadata);
|
|
1149
|
+
try {
|
|
1150
|
+
await (0, import_esbuild.build)({
|
|
1151
|
+
bundle: true,
|
|
1152
|
+
entryPoints: allTemplates,
|
|
1153
|
+
plugins: [renderingUtilitiesExporter(allTemplates)],
|
|
1154
|
+
platform: "node",
|
|
1155
|
+
format: "cjs",
|
|
1156
|
+
loader: { ".js": "jsx" },
|
|
1157
|
+
outExtension: { ".js": ".cjs" },
|
|
1158
|
+
jsx: "transform",
|
|
1159
|
+
write: true,
|
|
1160
|
+
outdir: pathToWhereEmailMarkupShouldBeDumped
|
|
1161
|
+
});
|
|
1162
|
+
} catch (exception) {
|
|
1163
|
+
const buildFailure = exception;
|
|
1164
|
+
if (spinner) {
|
|
1165
|
+
spinner.stopAndPersist({
|
|
1166
|
+
symbol: import_log_symbols4.default.error,
|
|
1167
|
+
text: "Failed to build emails"
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
process.exit(1);
|
|
1171
|
+
}
|
|
1172
|
+
if (spinner) {
|
|
1173
|
+
spinner.succeed();
|
|
1174
|
+
}
|
|
1175
|
+
const allBuiltTemplates = import_glob.glob.sync(
|
|
1176
|
+
(0, import_normalize_path.default)(`${pathToWhereEmailMarkupShouldBeDumped}/**/*.cjs`),
|
|
1177
|
+
{
|
|
1178
|
+
absolute: true
|
|
1179
|
+
}
|
|
1180
|
+
);
|
|
1181
|
+
for await (const template of allBuiltTemplates) {
|
|
1182
|
+
try {
|
|
1183
|
+
if (spinner) {
|
|
1184
|
+
spinner.text = `rendering ${template.split("/").pop()}`;
|
|
1185
|
+
spinner.render();
|
|
1186
|
+
}
|
|
1187
|
+
delete require.cache[template];
|
|
1188
|
+
const emailModule = require(template);
|
|
1189
|
+
const rendered = await emailModule.render(
|
|
1190
|
+
emailModule.reactEmailCreateReactElement(emailModule.default, {}),
|
|
1191
|
+
options
|
|
1192
|
+
);
|
|
1193
|
+
const htmlPath = template.replace(
|
|
1194
|
+
".cjs",
|
|
1195
|
+
options.plainText ? ".txt" : ".html"
|
|
1196
|
+
);
|
|
1197
|
+
(0, import_node_fs8.writeFileSync)(htmlPath, rendered);
|
|
1198
|
+
(0, import_node_fs8.unlinkSync)(template);
|
|
1199
|
+
} catch (exception) {
|
|
1200
|
+
if (spinner) {
|
|
1201
|
+
spinner.stopAndPersist({
|
|
1202
|
+
symbol: import_log_symbols4.default.error,
|
|
1203
|
+
text: `failed when rendering ${template.split("/").pop()}`
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
console.error(exception);
|
|
1207
|
+
process.exit(1);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
if (spinner) {
|
|
1211
|
+
spinner.succeed("Rendered all files");
|
|
1212
|
+
spinner.text = "Copying static files";
|
|
1213
|
+
spinner.render();
|
|
1214
|
+
}
|
|
1215
|
+
const staticDirectoryPath = import_node_path10.default.join(emailsDirectoryPath, "static");
|
|
1216
|
+
if (import_node_fs8.default.existsSync(staticDirectoryPath)) {
|
|
1217
|
+
const pathToDumpStaticFilesInto = import_node_path10.default.join(
|
|
1218
|
+
pathToWhereEmailMarkupShouldBeDumped,
|
|
1219
|
+
"static"
|
|
1220
|
+
);
|
|
1221
|
+
if (import_node_fs8.default.existsSync(pathToDumpStaticFilesInto))
|
|
1222
|
+
await import_node_fs8.default.promises.rm(pathToDumpStaticFilesInto, { recursive: true });
|
|
1223
|
+
try {
|
|
1224
|
+
await import_node_fs8.default.promises.cp(staticDirectoryPath, pathToDumpStaticFilesInto, {
|
|
1225
|
+
recursive: true
|
|
1226
|
+
});
|
|
1227
|
+
} catch (exception) {
|
|
1228
|
+
console.error(exception);
|
|
1229
|
+
if (spinner) {
|
|
1230
|
+
spinner.stopAndPersist({
|
|
1231
|
+
symbol: import_log_symbols4.default.error,
|
|
1232
|
+
text: "Failed to copy static files"
|
|
2726
1233
|
});
|
|
1234
|
+
}
|
|
1235
|
+
console.error(
|
|
1236
|
+
`Something went wrong while copying the file to ${pathToWhereEmailMarkupShouldBeDumped}/static, ${exception}`
|
|
1237
|
+
);
|
|
1238
|
+
process.exit(1);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
if (spinner && !options.silent) {
|
|
1242
|
+
spinner.succeed();
|
|
1243
|
+
const fileTree = await tree(pathToWhereEmailMarkupShouldBeDumped, 4);
|
|
1244
|
+
console.log(fileTree);
|
|
1245
|
+
spinner.stopAndPersist({
|
|
1246
|
+
symbol: import_log_symbols4.default.success,
|
|
1247
|
+
text: "Successfully exported emails"
|
|
2727
1248
|
});
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
}();
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
|
|
2732
1252
|
// src/cli/commands/start.ts
|
|
2733
1253
|
var import_node_child_process2 = require("child_process");
|
|
2734
1254
|
var import_node_fs9 = __toESM(require("fs"));
|
|
2735
1255
|
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
|
-
});
|
|
1256
|
+
var start = async () => {
|
|
1257
|
+
try {
|
|
1258
|
+
const usersProjectLocation = process.cwd();
|
|
1259
|
+
const builtPreviewPath = import_node_path11.default.resolve(
|
|
1260
|
+
usersProjectLocation,
|
|
1261
|
+
"./.react-email"
|
|
1262
|
+
);
|
|
1263
|
+
if (!import_node_fs9.default.existsSync(builtPreviewPath)) {
|
|
1264
|
+
console.error(
|
|
1265
|
+
"Could not find .react-email, maybe you haven't ran email build?"
|
|
1266
|
+
);
|
|
1267
|
+
process.exit(1);
|
|
1268
|
+
}
|
|
1269
|
+
const nextStart = (0, import_node_child_process2.spawn)("npm", ["start"], {
|
|
1270
|
+
cwd: builtPreviewPath,
|
|
1271
|
+
stdio: "inherit"
|
|
2767
1272
|
});
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
};
|
|
2771
|
-
|
|
1273
|
+
process.on("SIGINT", () => {
|
|
1274
|
+
nextStart.kill("SIGINT");
|
|
1275
|
+
});
|
|
1276
|
+
nextStart.on("exit", (code) => {
|
|
1277
|
+
process.exit(code ?? 0);
|
|
1278
|
+
});
|
|
1279
|
+
} catch (error) {
|
|
1280
|
+
console.log(error);
|
|
1281
|
+
process.exit(1);
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
|
|
2772
1285
|
// src/cli/index.ts
|
|
2773
1286
|
var PACKAGE_NAME = "react-email";
|
|
2774
1287
|
import_commander.program.name(PACKAGE_NAME).description("A live preview of your emails right in your browser").version(package_default.version);
|
|
2775
1288
|
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(
|
|
1289
|
+
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(
|
|
1290
|
+
"-p --packageManager <name>",
|
|
1291
|
+
"Package name to use on installation on `.react-email`",
|
|
1292
|
+
"npm"
|
|
1293
|
+
).action(build);
|
|
2777
1294
|
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
|
-
});
|
|
1295
|
+
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(
|
|
1296
|
+
"-s, --silent",
|
|
1297
|
+
"To, or not to show a spinner with process information",
|
|
1298
|
+
false
|
|
1299
|
+
).action(
|
|
1300
|
+
({ outDir, pretty, plainText, silent, dir: srcDir }) => exportTemplates(outDir, srcDir, { pretty, silent, plainText })
|
|
1301
|
+
);
|
|
2786
1302
|
import_commander.program.parse();
|