react-email 4.0.8 → 4.0.9
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 +14 -0
- package/dist/cli/index.mjs +205 -180
- package/dist/preview/.next/BUILD_ID +1 -1
- package/dist/preview/.next/app-build-manifest.json +14 -14
- package/dist/preview/.next/build-manifest.json +2 -2
- 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 +3 -3
- 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/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 +137 -75
- 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/267.js +14 -0
- package/dist/preview/.next/server/chunks/346.js +1 -0
- package/dist/preview/.next/server/chunks/{886.js → 775.js} +3 -3
- package/dist/preview/.next/server/pages/500.html +1 -1
- package/dist/preview/.next/server/server-reference-manifest.js +1 -1
- package/dist/preview/.next/server/server-reference-manifest.json +1 -1
- package/dist/preview/.next/static/chunks/33-ff3f70a80570ecda.js +1 -0
- package/dist/preview/.next/static/chunks/416-9c899340cfaa07d4.js +1 -0
- package/dist/preview/.next/static/chunks/516-2716d86d2f8b9000.js +1 -0
- package/dist/preview/.next/static/chunks/{587-2b8de61789f0fd1b.js → 587-0644242ce9489212.js} +1 -1
- package/dist/preview/.next/static/chunks/app/{layout-a3d4e7b4de277118.js → layout-2726a60e293495d3.js} +1 -1
- package/dist/preview/.next/static/chunks/app/{page-0ee3a37f3a3f6f17.js → page-1d98e2313c60dd77.js} +1 -1
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-c77ff9f2bb1709b3.js +1 -0
- package/dist/preview/.next/static/chunks/f33a14d2-a04f3be0523bd1fa.js +6 -0
- package/dist/preview/.next/static/css/6f42d128f111d7fa.css +3 -0
- package/dist/preview/.next/trace +27 -27
- package/package.json +44 -46
- package/src/actions/email-validation/check-compatibility.ts +1 -1
- package/src/actions/email-validation/check-images.spec.tsx +1 -1
- package/src/actions/email-validation/check-links.spec.tsx +1 -1
- package/src/actions/email-validation/quick-fetch.ts +1 -1
- package/src/actions/render-email-by-path.tsx +6 -6
- package/src/app/preview/[...slug]/preview.tsx +1 -1
- package/src/components/toolbar.tsx +1 -0
- package/src/contexts/emails.tsx +1 -3
- package/src/contexts/fragment-identifier.tsx +3 -1
- package/src/contexts/preview.tsx +1 -3
- package/src/hooks/use-email-rendering-result.ts +18 -5
- package/src/hooks/use-hot-reload.ts +1 -1
- package/src/utils/__snapshots__/get-email-component.spec.ts.snap +1 -1
- package/src/utils/caniemail/ast/get-object-variables.ts +1 -1
- package/src/utils/caniemail/tailwind/generate-tailwind-rules.ts +1 -1
- package/src/utils/caniemail/tailwind/get-tailwind-config.ts +1 -1
- package/src/utils/caniemail/tailwind/get-tailwind-metadata.ts +1 -1
- package/src/utils/contains-email-template.spec.ts +107 -0
- package/src/utils/contains-email-template.ts +33 -0
- package/src/utils/get-email-component.ts +16 -1
- package/src/utils/get-emails-directory-metadata.ts +24 -13
- package/src/utils/index.ts +2 -2
- package/src/utils/run-bundled-code.ts +1 -1
- package/tailwind.config.ts +2 -1
- package/tsconfig.json +1 -1
- package/dist/cli/index.d.mts +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -1320
- package/dist/index.js +0 -1234
- package/dist/preview/.next/server/chunks/265.js +0 -1
- package/dist/preview/.next/server/chunks/840.js +0 -14
- package/dist/preview/.next/static/chunks/246-e7336e2929971f63.js +0 -1
- package/dist/preview/.next/static/chunks/539-6e9405ecdc007bb7.js +0 -1
- package/dist/preview/.next/static/chunks/853-a01d49f63a859f3d.js +0 -1
- package/dist/preview/.next/static/chunks/afa401a5-55858bf5265319eb.js +0 -6
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-cab7e5e69e3b91e2.js +0 -1
- package/dist/preview/.next/static/css/67e57230289273a9.css +0 -3
- /package/dist/preview/.next/static/{t22IN7aANTezJAJOfFnv- → 3apYH6rky7aNn7g4RIJp5}/_buildManifest.js +0 -0
- /package/dist/preview/.next/static/{t22IN7aANTezJAJOfFnv- → 3apYH6rky7aNn7g4RIJp5}/_ssgManifest.js +0 -0
package/dist/index.js
DELETED
|
@@ -1,1234 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined")
|
|
6
|
-
return require.apply(this, arguments);
|
|
7
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
// src/index.ts
|
|
11
|
-
import { program } from "commander";
|
|
12
|
-
import fs10 from "node:fs/promises";
|
|
13
|
-
import path12 from "node:path";
|
|
14
|
-
|
|
15
|
-
// src/commands/build.ts
|
|
16
|
-
import { spawn } from "node:child_process";
|
|
17
|
-
import fs5 from "node:fs";
|
|
18
|
-
import path8 from "node:path";
|
|
19
|
-
import logSymbols3 from "log-symbols";
|
|
20
|
-
import ora2 from "ora";
|
|
21
|
-
|
|
22
|
-
// src/utils/get-emails-directory-metadata.ts
|
|
23
|
-
import fs from "node:fs";
|
|
24
|
-
import path from "node:path";
|
|
25
|
-
var isFileAnEmail = (fullPath) => {
|
|
26
|
-
const stat = fs.statSync(fullPath);
|
|
27
|
-
if (stat.isDirectory())
|
|
28
|
-
return false;
|
|
29
|
-
const { ext } = path.parse(fullPath);
|
|
30
|
-
if (![".js", ".tsx", ".jsx"].includes(ext))
|
|
31
|
-
return false;
|
|
32
|
-
if (!fs.existsSync(fullPath)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
const fileContents = fs.readFileSync(fullPath, "utf8");
|
|
36
|
-
const hasES6DefaultExport = /\bexport\s+default\b/gm.test(fileContents);
|
|
37
|
-
const hasCommonJSExport = /\bmodule\.exports\s*=/gm.test(fileContents);
|
|
38
|
-
const hasNamedExport = /\bexport\s+\{[^}]*\bdefault\b[^}]*\}/gm.test(
|
|
39
|
-
fileContents
|
|
40
|
-
);
|
|
41
|
-
return hasES6DefaultExport || hasCommonJSExport || hasNamedExport;
|
|
42
|
-
};
|
|
43
|
-
var mergeDirectoriesWithSubDirectories = (emailsDirectoryMetadata) => {
|
|
44
|
-
let currentResultingMergedDirectory = emailsDirectoryMetadata;
|
|
45
|
-
while (currentResultingMergedDirectory.emailFilenames.length === 0 && currentResultingMergedDirectory.subDirectories.length === 1) {
|
|
46
|
-
const onlySubDirectory = currentResultingMergedDirectory.subDirectories[0];
|
|
47
|
-
currentResultingMergedDirectory = {
|
|
48
|
-
...onlySubDirectory,
|
|
49
|
-
directoryName: path.join(
|
|
50
|
-
currentResultingMergedDirectory.directoryName,
|
|
51
|
-
onlySubDirectory.directoryName
|
|
52
|
-
)
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return currentResultingMergedDirectory;
|
|
56
|
-
};
|
|
57
|
-
var getEmailsDirectoryMetadata = async (absolutePathToEmailsDirectory, keepFileExtensions = false, isSubDirectory = false, baseDirectoryPath = absolutePathToEmailsDirectory) => {
|
|
58
|
-
if (!fs.existsSync(absolutePathToEmailsDirectory))
|
|
59
|
-
return;
|
|
60
|
-
const dirents = await fs.promises.readdir(absolutePathToEmailsDirectory, {
|
|
61
|
-
withFileTypes: true
|
|
62
|
-
});
|
|
63
|
-
const emailFilenames = dirents.filter(
|
|
64
|
-
(dirent) => isFileAnEmail(path.join(absolutePathToEmailsDirectory, dirent.name))
|
|
65
|
-
).map(
|
|
66
|
-
(dirent) => keepFileExtensions ? dirent.name : dirent.name.replace(path.extname(dirent.name), "")
|
|
67
|
-
);
|
|
68
|
-
const subDirectories = await Promise.all(
|
|
69
|
-
dirents.filter(
|
|
70
|
-
(dirent) => dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static"
|
|
71
|
-
).map((dirent) => {
|
|
72
|
-
const direntAbsolutePath = path.join(
|
|
73
|
-
absolutePathToEmailsDirectory,
|
|
74
|
-
dirent.name
|
|
75
|
-
);
|
|
76
|
-
return getEmailsDirectoryMetadata(
|
|
77
|
-
direntAbsolutePath,
|
|
78
|
-
keepFileExtensions,
|
|
79
|
-
true,
|
|
80
|
-
baseDirectoryPath
|
|
81
|
-
);
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
const emailsMetadata = {
|
|
85
|
-
absolutePath: absolutePathToEmailsDirectory,
|
|
86
|
-
relativePath: path.relative(
|
|
87
|
-
baseDirectoryPath,
|
|
88
|
-
absolutePathToEmailsDirectory
|
|
89
|
-
),
|
|
90
|
-
directoryName: absolutePathToEmailsDirectory.split(path.sep).pop(),
|
|
91
|
-
emailFilenames,
|
|
92
|
-
subDirectories
|
|
93
|
-
};
|
|
94
|
-
return isSubDirectory ? mergeDirectoriesWithSubDirectories(emailsMetadata) : emailsMetadata;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// src/utils/register-spinner-autostopping.ts
|
|
98
|
-
import logSymbols from "log-symbols";
|
|
99
|
-
var spinners = /* @__PURE__ */ new Set();
|
|
100
|
-
process.on("SIGINT", () => {
|
|
101
|
-
spinners.forEach((spinner) => {
|
|
102
|
-
if (spinner.isSpinning) {
|
|
103
|
-
spinner.stop();
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
process.on("exit", (code) => {
|
|
108
|
-
if (code !== 0) {
|
|
109
|
-
spinners.forEach((spinner) => {
|
|
110
|
-
if (spinner.isSpinning) {
|
|
111
|
-
spinner.stopAndPersist({
|
|
112
|
-
symbol: logSymbols.error
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
var registerSpinnerAutostopping = (spinner) => {
|
|
119
|
-
spinners.add(spinner);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// src/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
123
|
-
import path6 from "node:path";
|
|
124
|
-
import { watch } from "chokidar";
|
|
125
|
-
import debounce from "debounce";
|
|
126
|
-
import { Server as SocketServer } from "socket.io";
|
|
127
|
-
|
|
128
|
-
// src/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
129
|
-
import { existsSync as existsSync2, promises as fs3, statSync } from "node:fs";
|
|
130
|
-
import path5 from "node:path";
|
|
131
|
-
|
|
132
|
-
// src/utils/preview/start-dev-server.ts
|
|
133
|
-
import http from "node:http";
|
|
134
|
-
import path4 from "node:path";
|
|
135
|
-
import url from "node:url";
|
|
136
|
-
import chalk from "chalk";
|
|
137
|
-
import logSymbols2 from "log-symbols";
|
|
138
|
-
import ora from "ora";
|
|
139
|
-
|
|
140
|
-
// src/utils/preview/get-env-variables-for-preview-app.ts
|
|
141
|
-
import path2 from "node:path";
|
|
142
|
-
var getEnvVariablesForPreviewApp = (relativePathToEmailsDirectory, cwd) => {
|
|
143
|
-
return {
|
|
144
|
-
EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
|
|
145
|
-
EMAILS_DIR_ABSOLUTE_PATH: path2.resolve(cwd, relativePathToEmailsDirectory),
|
|
146
|
-
USER_PROJECT_LOCATION: cwd,
|
|
147
|
-
NEXT_PUBLIC_IS_PREVIEW_DEVELOPMENT: isDev ? "true" : "false"
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
// src/utils/preview/serve-static-file.ts
|
|
152
|
-
import { existsSync, promises as fs2 } from "node:fs";
|
|
153
|
-
import path3 from "node:path";
|
|
154
|
-
import { lookup } from "mime-types";
|
|
155
|
-
var serveStaticFile = async (res, parsedUrl, staticDirRelativePath) => {
|
|
156
|
-
const staticBaseDir = path3.join(process.cwd(), staticDirRelativePath);
|
|
157
|
-
const pathname = parsedUrl.pathname;
|
|
158
|
-
const ext = path3.parse(pathname).ext;
|
|
159
|
-
const fileAbsolutePath = path3.join(staticBaseDir, pathname);
|
|
160
|
-
try {
|
|
161
|
-
const fileHandle = await fs2.open(fileAbsolutePath, "r");
|
|
162
|
-
const fileData = await fs2.readFile(fileHandle);
|
|
163
|
-
res.setHeader("Content-type", lookup(ext) || "text/plain");
|
|
164
|
-
res.end(fileData);
|
|
165
|
-
fileHandle.close();
|
|
166
|
-
} catch (exception) {
|
|
167
|
-
if (!existsSync(fileAbsolutePath)) {
|
|
168
|
-
res.statusCode = 404;
|
|
169
|
-
res.end();
|
|
170
|
-
} else {
|
|
171
|
-
const sanitizedFilePath = fileAbsolutePath.replace(/\n|\r/g, "");
|
|
172
|
-
console.error(
|
|
173
|
-
`Could not read file at ${sanitizedFilePath} to be served, here's the exception:`,
|
|
174
|
-
exception
|
|
175
|
-
);
|
|
176
|
-
res.statusCode = 500;
|
|
177
|
-
res.end(
|
|
178
|
-
"Could not read file to be served! Check your terminal for more information."
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
// src/utils/preview/start-dev-server.ts
|
|
185
|
-
import { createJiti } from "jiti";
|
|
186
|
-
var devServer;
|
|
187
|
-
var safeAsyncServerListen = (server, port) => {
|
|
188
|
-
return new Promise((resolve) => {
|
|
189
|
-
server.listen(port, () => {
|
|
190
|
-
resolve({ portAlreadyInUse: false });
|
|
191
|
-
});
|
|
192
|
-
server.on("error", (e) => {
|
|
193
|
-
if (e.code === "EADDRINUSE") {
|
|
194
|
-
resolve({ portAlreadyInUse: true });
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
var usersProject = createJiti(process.cwd());
|
|
200
|
-
var isDev = !import.meta.dirname.includes("dist");
|
|
201
|
-
var cliPackageLocation = path4.resolve(import.meta.dirname, "../..");
|
|
202
|
-
var previewServerLocation = path4.dirname(
|
|
203
|
-
url.parse(usersProject.esmResolve("@react-email/preview-server"), true).path
|
|
204
|
-
);
|
|
205
|
-
var previewServer = createJiti(previewServerLocation);
|
|
206
|
-
var startDevServer = async (emailsDirRelativePath, staticBaseDirRelativePath, port) => {
|
|
207
|
-
const { default: next } = await previewServer.import("next");
|
|
208
|
-
devServer = http.createServer((req, res) => {
|
|
209
|
-
if (!req.url) {
|
|
210
|
-
res.end(404);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const parsedUrl = url.parse(req.url, true);
|
|
214
|
-
res.setHeader(
|
|
215
|
-
"Cache-Control",
|
|
216
|
-
"no-cache, max-age=0, must-revalidate, no-store"
|
|
217
|
-
);
|
|
218
|
-
res.setHeader("Pragma", "no-cache");
|
|
219
|
-
res.setHeader("Expires", "-1");
|
|
220
|
-
try {
|
|
221
|
-
if (parsedUrl.path?.includes("static/") && !parsedUrl.path.includes("_next/static/")) {
|
|
222
|
-
void serveStaticFile(res, parsedUrl, staticBaseDirRelativePath);
|
|
223
|
-
} else if (!isNextReady) {
|
|
224
|
-
void nextReadyPromise.then(
|
|
225
|
-
() => nextHandleRequest?.(req, res, parsedUrl)
|
|
226
|
-
);
|
|
227
|
-
} else {
|
|
228
|
-
void nextHandleRequest?.(req, res, parsedUrl);
|
|
229
|
-
}
|
|
230
|
-
} catch (e) {
|
|
231
|
-
console.error("caught error", e);
|
|
232
|
-
res.writeHead(500);
|
|
233
|
-
res.end();
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
const { portAlreadyInUse } = await safeAsyncServerListen(devServer, port);
|
|
237
|
-
if (!portAlreadyInUse) {
|
|
238
|
-
console.log(chalk.greenBright(` React Email ${packageJson.version}`));
|
|
239
|
-
console.log(` Running preview at: http://localhost:${port}
|
|
240
|
-
`);
|
|
241
|
-
} else {
|
|
242
|
-
const nextPortToTry = port + 1;
|
|
243
|
-
console.warn(
|
|
244
|
-
` ${logSymbols2.warning} Port ${port} is already in use, trying ${nextPortToTry}`
|
|
245
|
-
);
|
|
246
|
-
return startDevServer(
|
|
247
|
-
emailsDirRelativePath,
|
|
248
|
-
staticBaseDirRelativePath,
|
|
249
|
-
nextPortToTry
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
devServer.on("close", async () => {
|
|
253
|
-
await app.close();
|
|
254
|
-
});
|
|
255
|
-
devServer.on("error", (e) => {
|
|
256
|
-
console.error(
|
|
257
|
-
` ${logSymbols2.error} preview server error: `,
|
|
258
|
-
JSON.stringify(e)
|
|
259
|
-
);
|
|
260
|
-
process.exit(1);
|
|
261
|
-
});
|
|
262
|
-
const spinner = ora({
|
|
263
|
-
text: "Getting react-email preview server ready...\n",
|
|
264
|
-
prefixText: " "
|
|
265
|
-
}).start();
|
|
266
|
-
registerSpinnerAutostopping(spinner);
|
|
267
|
-
const timeBeforeNextReady = performance.now();
|
|
268
|
-
process.env = {
|
|
269
|
-
NODE_ENV: "development",
|
|
270
|
-
...process.env,
|
|
271
|
-
...getEnvVariablesForPreviewApp(
|
|
272
|
-
// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
|
|
273
|
-
path4.normalize(emailsDirRelativePath),
|
|
274
|
-
process.cwd()
|
|
275
|
-
)
|
|
276
|
-
};
|
|
277
|
-
const app = next({
|
|
278
|
-
// passing in env here does not get the environment variables there
|
|
279
|
-
dev: isDev,
|
|
280
|
-
conf: {
|
|
281
|
-
images: {
|
|
282
|
-
// This is to avoid the warning with sharp
|
|
283
|
-
unoptimized: true
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
hostname: "localhost",
|
|
287
|
-
port,
|
|
288
|
-
dir: previewServerLocation
|
|
289
|
-
});
|
|
290
|
-
let isNextReady = false;
|
|
291
|
-
const nextReadyPromise = app.prepare();
|
|
292
|
-
await nextReadyPromise;
|
|
293
|
-
isNextReady = true;
|
|
294
|
-
const nextHandleRequest = app.getRequestHandler();
|
|
295
|
-
const secondsToNextReady = ((performance.now() - timeBeforeNextReady) / 1e3).toFixed(1);
|
|
296
|
-
spinner.stopAndPersist({
|
|
297
|
-
text: `Ready in ${secondsToNextReady}s
|
|
298
|
-
`,
|
|
299
|
-
symbol: logSymbols2.success
|
|
300
|
-
});
|
|
301
|
-
return devServer;
|
|
302
|
-
};
|
|
303
|
-
var makeExitHandler = (options) => (codeSignalOrError) => {
|
|
304
|
-
if (typeof devServer !== "undefined") {
|
|
305
|
-
console.log("\nshutting down dev server");
|
|
306
|
-
devServer.close();
|
|
307
|
-
devServer = void 0;
|
|
308
|
-
}
|
|
309
|
-
if (codeSignalOrError instanceof Error) {
|
|
310
|
-
console.error(codeSignalOrError);
|
|
311
|
-
}
|
|
312
|
-
if (options?.shouldKillProcess) {
|
|
313
|
-
process.exit(options.killWithErrorCode ? 1 : 0);
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
process.on("exit", makeExitHandler());
|
|
317
|
-
process.on(
|
|
318
|
-
"SIGINT",
|
|
319
|
-
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
320
|
-
);
|
|
321
|
-
process.on(
|
|
322
|
-
"SIGUSR1",
|
|
323
|
-
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
324
|
-
);
|
|
325
|
-
process.on(
|
|
326
|
-
"SIGUSR2",
|
|
327
|
-
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: false })
|
|
328
|
-
);
|
|
329
|
-
process.on(
|
|
330
|
-
"uncaughtException",
|
|
331
|
-
makeExitHandler({ shouldKillProcess: true, killWithErrorCode: true })
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
// src/utils/preview/hot-reloading/get-imported-modules.ts
|
|
335
|
-
import { parse } from "@babel/parser";
|
|
336
|
-
import traverse from "@babel/traverse";
|
|
337
|
-
var getImportedModules = (contents) => {
|
|
338
|
-
const importedPaths = [];
|
|
339
|
-
const parsedContents = parse(contents, {
|
|
340
|
-
sourceType: "unambiguous",
|
|
341
|
-
strictMode: false,
|
|
342
|
-
errorRecovery: true,
|
|
343
|
-
plugins: ["jsx", "typescript", "decorators"]
|
|
344
|
-
});
|
|
345
|
-
traverse.default(parsedContents, {
|
|
346
|
-
ImportDeclaration({ node }) {
|
|
347
|
-
importedPaths.push(node.source.value);
|
|
348
|
-
},
|
|
349
|
-
ExportAllDeclaration({ node }) {
|
|
350
|
-
importedPaths.push(node.source.value);
|
|
351
|
-
},
|
|
352
|
-
ExportNamedDeclaration({ node }) {
|
|
353
|
-
if (node.source) {
|
|
354
|
-
importedPaths.push(node.source.value);
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
CallExpression({ node }) {
|
|
358
|
-
if ("name" in node.callee && node.callee.name === "require") {
|
|
359
|
-
if (node.arguments.length === 1) {
|
|
360
|
-
const importPathNode = node.arguments[0];
|
|
361
|
-
if (importPathNode.type === "StringLiteral") {
|
|
362
|
-
importedPaths.push(importPathNode.value);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
return importedPaths;
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
// src/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
372
|
-
var readAllFilesInsideDirectory = async (directory) => {
|
|
373
|
-
let allFilePaths = [];
|
|
374
|
-
const topLevelDirents = await fs3.readdir(directory, { withFileTypes: true });
|
|
375
|
-
for await (const dirent of topLevelDirents) {
|
|
376
|
-
const pathToDirent = path5.join(directory, dirent.name);
|
|
377
|
-
if (dirent.isDirectory()) {
|
|
378
|
-
allFilePaths = allFilePaths.concat(
|
|
379
|
-
await readAllFilesInsideDirectory(pathToDirent)
|
|
380
|
-
);
|
|
381
|
-
} else {
|
|
382
|
-
allFilePaths.push(pathToDirent);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return allFilePaths;
|
|
386
|
-
};
|
|
387
|
-
var isJavascriptModule = (filePath) => {
|
|
388
|
-
const extensionName = path5.extname(filePath);
|
|
389
|
-
return [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"].includes(extensionName);
|
|
390
|
-
};
|
|
391
|
-
var checkFileExtensionsUntilItExists = (pathWithoutExtension) => {
|
|
392
|
-
if (existsSync2(`${pathWithoutExtension}.ts`)) {
|
|
393
|
-
return `${pathWithoutExtension}.ts`;
|
|
394
|
-
}
|
|
395
|
-
if (existsSync2(`${pathWithoutExtension}.tsx`)) {
|
|
396
|
-
return `${pathWithoutExtension}.tsx`;
|
|
397
|
-
}
|
|
398
|
-
if (existsSync2(`${pathWithoutExtension}.js`)) {
|
|
399
|
-
return `${pathWithoutExtension}.js`;
|
|
400
|
-
}
|
|
401
|
-
if (existsSync2(`${pathWithoutExtension}.jsx`)) {
|
|
402
|
-
return `${pathWithoutExtension}.jsx`;
|
|
403
|
-
}
|
|
404
|
-
if (existsSync2(`${pathWithoutExtension}.mjs`)) {
|
|
405
|
-
return `${pathWithoutExtension}.mjs`;
|
|
406
|
-
}
|
|
407
|
-
if (existsSync2(`${pathWithoutExtension}.cjs`)) {
|
|
408
|
-
return `${pathWithoutExtension}.cjs`;
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
var createDependencyGraph = async (directory) => {
|
|
412
|
-
const filePaths = await readAllFilesInsideDirectory(directory);
|
|
413
|
-
const modulePaths = filePaths.filter(isJavascriptModule);
|
|
414
|
-
const graph = Object.fromEntries(
|
|
415
|
-
modulePaths.map((path13) => [
|
|
416
|
-
path13,
|
|
417
|
-
{
|
|
418
|
-
path: path13,
|
|
419
|
-
dependencyPaths: [],
|
|
420
|
-
dependentPaths: [],
|
|
421
|
-
moduleDependencies: []
|
|
422
|
-
}
|
|
423
|
-
])
|
|
424
|
-
);
|
|
425
|
-
const getDependencyPaths = async (filePath) => {
|
|
426
|
-
const contents = await fs3.readFile(filePath, "utf8");
|
|
427
|
-
const importedPaths = isJavascriptModule(filePath) ? getImportedModules(contents) : [];
|
|
428
|
-
const importedPathsRelativeToDirectory = importedPaths.map(
|
|
429
|
-
(dependencyPath) => {
|
|
430
|
-
const isModulePath = !dependencyPath.startsWith(".");
|
|
431
|
-
if (isModulePath || path5.isAbsolute(dependencyPath)) {
|
|
432
|
-
return dependencyPath;
|
|
433
|
-
}
|
|
434
|
-
let pathToDependencyFromDirectory = path5.resolve(
|
|
435
|
-
/*
|
|
436
|
-
path.resolve resolves paths differently from what imports on javascript do.
|
|
437
|
-
|
|
438
|
-
So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependency path of "./other-email"
|
|
439
|
-
would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
|
|
440
|
-
one the import is meant to go to
|
|
441
|
-
*/
|
|
442
|
-
path5.dirname(filePath),
|
|
443
|
-
dependencyPath
|
|
444
|
-
);
|
|
445
|
-
let isDirectory = false;
|
|
446
|
-
try {
|
|
447
|
-
isDirectory = statSync(pathToDependencyFromDirectory).isDirectory();
|
|
448
|
-
} catch (_) {
|
|
449
|
-
}
|
|
450
|
-
if (isDirectory) {
|
|
451
|
-
const pathToSubDirectory = pathToDependencyFromDirectory;
|
|
452
|
-
const pathWithExtension = checkFileExtensionsUntilItExists(
|
|
453
|
-
`${pathToSubDirectory}/index`
|
|
454
|
-
);
|
|
455
|
-
if (pathWithExtension) {
|
|
456
|
-
pathToDependencyFromDirectory = pathWithExtension;
|
|
457
|
-
} else if (isDev) {
|
|
458
|
-
console.warn(
|
|
459
|
-
`Could not find index file for directory at ${pathToDependencyFromDirectory}. This is probably going to cause issues with both hot reloading and your code.`
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
if (!isJavascriptModule(pathToDependencyFromDirectory)) {
|
|
464
|
-
const pathWithExtension = path5.extname(pathToDependencyFromDirectory).length > 0 ? pathToDependencyFromDirectory : checkFileExtensionsUntilItExists(pathToDependencyFromDirectory);
|
|
465
|
-
if (pathWithExtension) {
|
|
466
|
-
pathToDependencyFromDirectory = pathWithExtension;
|
|
467
|
-
} else if (isDev) {
|
|
468
|
-
console.warn(
|
|
469
|
-
`Could not determine the file extension for the file at ${pathToDependencyFromDirectory}`
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return pathToDependencyFromDirectory;
|
|
474
|
-
}
|
|
475
|
-
);
|
|
476
|
-
const moduleDependencies = importedPathsRelativeToDirectory.filter(
|
|
477
|
-
(dependencyPath) => !dependencyPath.startsWith(".") && !path5.isAbsolute(dependencyPath)
|
|
478
|
-
);
|
|
479
|
-
const nonNodeModuleImportPathsRelativeToDirectory = importedPathsRelativeToDirectory.filter(
|
|
480
|
-
(dependencyPath) => dependencyPath.startsWith(".") || path5.isAbsolute(dependencyPath)
|
|
481
|
-
);
|
|
482
|
-
return {
|
|
483
|
-
dependencyPaths: nonNodeModuleImportPathsRelativeToDirectory,
|
|
484
|
-
moduleDependencies
|
|
485
|
-
};
|
|
486
|
-
};
|
|
487
|
-
const updateModuleDependenciesInGraph = async (moduleFilePath) => {
|
|
488
|
-
if (graph[moduleFilePath] === void 0) {
|
|
489
|
-
graph[moduleFilePath] = {
|
|
490
|
-
path: moduleFilePath,
|
|
491
|
-
dependencyPaths: [],
|
|
492
|
-
dependentPaths: [],
|
|
493
|
-
moduleDependencies: []
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
const { moduleDependencies, dependencyPaths: newDependencyPaths } = await getDependencyPaths(moduleFilePath);
|
|
497
|
-
graph[moduleFilePath].moduleDependencies = moduleDependencies;
|
|
498
|
-
for (const dependencyPath of graph[moduleFilePath].dependencyPaths) {
|
|
499
|
-
if (newDependencyPaths.includes(dependencyPath))
|
|
500
|
-
continue;
|
|
501
|
-
const dependencyModule = graph[dependencyPath];
|
|
502
|
-
if (dependencyModule !== void 0) {
|
|
503
|
-
dependencyModule.dependentPaths = dependencyModule.dependentPaths.filter(
|
|
504
|
-
(dependentPath) => dependentPath !== moduleFilePath
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
graph[moduleFilePath].dependencyPaths = newDependencyPaths;
|
|
509
|
-
for await (const dependencyPath of newDependencyPaths) {
|
|
510
|
-
if (graph[dependencyPath] === void 0) {
|
|
511
|
-
await updateModuleDependenciesInGraph(dependencyPath);
|
|
512
|
-
}
|
|
513
|
-
const dependencyModule = graph[dependencyPath];
|
|
514
|
-
if (dependencyModule === void 0) {
|
|
515
|
-
throw new Error(
|
|
516
|
-
`Loading the dependency path ${dependencyPath} did not initialize it at all. This is a bug in React Email.`
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
if (!dependencyModule.dependentPaths.includes(moduleFilePath)) {
|
|
520
|
-
dependencyModule.dependentPaths.push(moduleFilePath);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
for (const filePath of modulePaths) {
|
|
525
|
-
await updateModuleDependenciesInGraph(filePath);
|
|
526
|
-
}
|
|
527
|
-
const removeModuleFromGraph = (filePath) => {
|
|
528
|
-
const module = graph[filePath];
|
|
529
|
-
if (module) {
|
|
530
|
-
for (const dependencyPath of module.dependencyPaths) {
|
|
531
|
-
if (graph[dependencyPath]) {
|
|
532
|
-
graph[dependencyPath].dependentPaths = graph[dependencyPath].dependentPaths.filter(
|
|
533
|
-
(dependentPath) => dependentPath !== filePath
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
delete graph[filePath];
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
return [
|
|
541
|
-
graph,
|
|
542
|
-
async (event, pathToModified) => {
|
|
543
|
-
switch (event) {
|
|
544
|
-
case "change":
|
|
545
|
-
if (isJavascriptModule(pathToModified)) {
|
|
546
|
-
await updateModuleDependenciesInGraph(pathToModified);
|
|
547
|
-
}
|
|
548
|
-
break;
|
|
549
|
-
case "add":
|
|
550
|
-
if (isJavascriptModule(pathToModified)) {
|
|
551
|
-
await updateModuleDependenciesInGraph(pathToModified);
|
|
552
|
-
}
|
|
553
|
-
break;
|
|
554
|
-
case "addDir": {
|
|
555
|
-
const filesInsideAddedDirectory = await readAllFilesInsideDirectory(pathToModified);
|
|
556
|
-
const modulesInsideAddedDirectory = filesInsideAddedDirectory.filter(isJavascriptModule);
|
|
557
|
-
for await (const filePath of modulesInsideAddedDirectory) {
|
|
558
|
-
await updateModuleDependenciesInGraph(filePath);
|
|
559
|
-
}
|
|
560
|
-
break;
|
|
561
|
-
}
|
|
562
|
-
case "unlink":
|
|
563
|
-
if (isJavascriptModule(pathToModified)) {
|
|
564
|
-
removeModuleFromGraph(pathToModified);
|
|
565
|
-
}
|
|
566
|
-
break;
|
|
567
|
-
case "unlinkDir": {
|
|
568
|
-
const filesInsideDeletedDirectory = await readAllFilesInsideDirectory(pathToModified);
|
|
569
|
-
const modulesInsideDeletedDirectory = filesInsideDeletedDirectory.filter(isJavascriptModule);
|
|
570
|
-
for await (const filePath of modulesInsideDeletedDirectory) {
|
|
571
|
-
removeModuleFromGraph(filePath);
|
|
572
|
-
}
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
{
|
|
578
|
-
resolveDependentsOf: function resolveDependentsOf(pathToModule) {
|
|
579
|
-
const moduleEntry = graph[pathToModule];
|
|
580
|
-
const dependentPaths = [];
|
|
581
|
-
if (moduleEntry) {
|
|
582
|
-
for (const dependentPath of moduleEntry.dependentPaths) {
|
|
583
|
-
const dependentsOfDependent = resolveDependentsOf(dependentPath);
|
|
584
|
-
dependentPaths.push(...dependentsOfDependent);
|
|
585
|
-
dependentPaths.push(dependentPath);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
return dependentPaths;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
];
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
// src/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
595
|
-
var setupHotreloading = async (devServer2, emailDirRelativePath) => {
|
|
596
|
-
let clients = [];
|
|
597
|
-
const io = new SocketServer(devServer2);
|
|
598
|
-
io.on("connection", (client) => {
|
|
599
|
-
clients.push(client);
|
|
600
|
-
client.on("disconnect", () => {
|
|
601
|
-
clients = clients.filter((item) => item !== client);
|
|
602
|
-
});
|
|
603
|
-
});
|
|
604
|
-
let changes = [];
|
|
605
|
-
const reload = debounce(() => {
|
|
606
|
-
clients.forEach((client) => {
|
|
607
|
-
client.emit(
|
|
608
|
-
"reload",
|
|
609
|
-
changes.filter(
|
|
610
|
-
(change) => (
|
|
611
|
-
// Ensures only changes inside the emails directory are emitted
|
|
612
|
-
path6.resolve(absolutePathToEmailsDirectory, change.filename).startsWith(absolutePathToEmailsDirectory)
|
|
613
|
-
)
|
|
614
|
-
)
|
|
615
|
-
);
|
|
616
|
-
});
|
|
617
|
-
changes = [];
|
|
618
|
-
}, 150);
|
|
619
|
-
const absolutePathToEmailsDirectory = path6.resolve(
|
|
620
|
-
process.cwd(),
|
|
621
|
-
emailDirRelativePath
|
|
622
|
-
);
|
|
623
|
-
const [dependencyGraph, updateDependencyGraph, { resolveDependentsOf }] = await createDependencyGraph(absolutePathToEmailsDirectory);
|
|
624
|
-
const watcher = watch("", {
|
|
625
|
-
ignoreInitial: true,
|
|
626
|
-
cwd: absolutePathToEmailsDirectory
|
|
627
|
-
});
|
|
628
|
-
const getFilesOutsideEmailsDirectory = () => Object.keys(dependencyGraph).filter(
|
|
629
|
-
(p) => path6.relative(absolutePathToEmailsDirectory, p).startsWith("..")
|
|
630
|
-
);
|
|
631
|
-
let filesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
632
|
-
for (const p of filesOutsideEmailsDirectory) {
|
|
633
|
-
watcher.add(p);
|
|
634
|
-
}
|
|
635
|
-
const exit = async () => {
|
|
636
|
-
await watcher.close();
|
|
637
|
-
};
|
|
638
|
-
process.on("SIGINT", exit);
|
|
639
|
-
process.on("uncaughtException", exit);
|
|
640
|
-
watcher.on("all", async (event, relativePathToChangeTarget) => {
|
|
641
|
-
const file = relativePathToChangeTarget.split(path6.sep);
|
|
642
|
-
if (file.length === 0) {
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
const pathToChangeTarget = path6.resolve(
|
|
646
|
-
absolutePathToEmailsDirectory,
|
|
647
|
-
relativePathToChangeTarget
|
|
648
|
-
);
|
|
649
|
-
await updateDependencyGraph(event, pathToChangeTarget);
|
|
650
|
-
const newFilesOutsideEmailsDirectory = getFilesOutsideEmailsDirectory();
|
|
651
|
-
for (const p of filesOutsideEmailsDirectory) {
|
|
652
|
-
if (!newFilesOutsideEmailsDirectory.includes(p)) {
|
|
653
|
-
watcher.unwatch(p);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
for (const p of newFilesOutsideEmailsDirectory) {
|
|
657
|
-
if (!filesOutsideEmailsDirectory.includes(p)) {
|
|
658
|
-
watcher.add(p);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
filesOutsideEmailsDirectory = newFilesOutsideEmailsDirectory;
|
|
662
|
-
changes.push({
|
|
663
|
-
event,
|
|
664
|
-
filename: relativePathToChangeTarget
|
|
665
|
-
});
|
|
666
|
-
for (const dependentPath of resolveDependentsOf(pathToChangeTarget)) {
|
|
667
|
-
changes.push({
|
|
668
|
-
event: "change",
|
|
669
|
-
filename: path6.relative(absolutePathToEmailsDirectory, dependentPath)
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
reload();
|
|
673
|
-
});
|
|
674
|
-
return watcher;
|
|
675
|
-
};
|
|
676
|
-
|
|
677
|
-
// src/utils/tree.ts
|
|
678
|
-
import { promises as fs4 } from "node:fs";
|
|
679
|
-
import os from "node:os";
|
|
680
|
-
import path7 from "node:path";
|
|
681
|
-
var SYMBOLS = {
|
|
682
|
-
BRANCH: "\u251C\u2500\u2500 ",
|
|
683
|
-
EMPTY: "",
|
|
684
|
-
INDENT: " ",
|
|
685
|
-
LAST_BRANCH: "\u2514\u2500\u2500 ",
|
|
686
|
-
VERTICAL: "\u2502 "
|
|
687
|
-
};
|
|
688
|
-
var getTreeLines = async (dirPath, depth, currentDepth = 0) => {
|
|
689
|
-
const base = process.cwd();
|
|
690
|
-
const dirFullpath = path7.resolve(base, dirPath);
|
|
691
|
-
const dirname = path7.basename(dirFullpath);
|
|
692
|
-
let lines = [dirname];
|
|
693
|
-
const dirStat = await fs4.stat(dirFullpath);
|
|
694
|
-
if (dirStat.isDirectory() && currentDepth < depth) {
|
|
695
|
-
const childDirents = await fs4.readdir(dirFullpath, { withFileTypes: true });
|
|
696
|
-
childDirents.sort((a, b) => {
|
|
697
|
-
if (a.isDirectory() && b.isFile()) {
|
|
698
|
-
return -1;
|
|
699
|
-
}
|
|
700
|
-
if (a.isFile() && b.isDirectory()) {
|
|
701
|
-
return 1;
|
|
702
|
-
}
|
|
703
|
-
return b.name > a.name ? -1 : 1;
|
|
704
|
-
});
|
|
705
|
-
for (let i = 0; i < childDirents.length; i++) {
|
|
706
|
-
const dirent = childDirents[i];
|
|
707
|
-
const isLast = i === childDirents.length - 1;
|
|
708
|
-
const branchingSymbol = isLast ? SYMBOLS.LAST_BRANCH : SYMBOLS.BRANCH;
|
|
709
|
-
const verticalSymbol = isLast ? SYMBOLS.INDENT : SYMBOLS.VERTICAL;
|
|
710
|
-
if (dirent.isFile()) {
|
|
711
|
-
lines.push(`${branchingSymbol}${dirent.name}`);
|
|
712
|
-
} else {
|
|
713
|
-
const pathToDirectory = path7.join(dirFullpath, dirent.name);
|
|
714
|
-
const treeLinesForSubDirectory = await getTreeLines(
|
|
715
|
-
pathToDirectory,
|
|
716
|
-
depth,
|
|
717
|
-
currentDepth + 1
|
|
718
|
-
);
|
|
719
|
-
lines = lines.concat(
|
|
720
|
-
treeLinesForSubDirectory.map(
|
|
721
|
-
(line, index) => index === 0 ? `${branchingSymbol}${line}` : `${verticalSymbol}${line}`
|
|
722
|
-
)
|
|
723
|
-
);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
return lines;
|
|
728
|
-
};
|
|
729
|
-
var tree = async (dirPath, depth) => {
|
|
730
|
-
const lines = await getTreeLines(dirPath, depth);
|
|
731
|
-
return lines.join(os.EOL);
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
// src/commands/build.ts
|
|
735
|
-
var buildPreviewApp = (absoluteDirectory) => {
|
|
736
|
-
return new Promise((resolve, reject) => {
|
|
737
|
-
const nextBuild = spawn("npm", ["run", "build"], {
|
|
738
|
-
cwd: absoluteDirectory,
|
|
739
|
-
shell: true
|
|
740
|
-
});
|
|
741
|
-
nextBuild.stdout.pipe(process.stdout);
|
|
742
|
-
nextBuild.stderr.pipe(process.stderr);
|
|
743
|
-
nextBuild.on("close", (code) => {
|
|
744
|
-
if (code === 0) {
|
|
745
|
-
resolve();
|
|
746
|
-
} else {
|
|
747
|
-
reject(
|
|
748
|
-
new Error(
|
|
749
|
-
`Unable to build the Next app and it exited with code: ${code}`
|
|
750
|
-
)
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
});
|
|
754
|
-
});
|
|
755
|
-
};
|
|
756
|
-
var setNextEnvironmentVariablesForBuild = async (emailsDirRelativePath, builtPreviewAppPath) => {
|
|
757
|
-
const nextConfigContents = `
|
|
758
|
-
const path = require('path');
|
|
759
|
-
const emailsDirRelativePath = path.normalize('${emailsDirRelativePath}');
|
|
760
|
-
const userProjectLocation = path.resolve(process.cwd(), '../');
|
|
761
|
-
/** @type {import('next').NextConfig} */
|
|
762
|
-
module.exports = {
|
|
763
|
-
env: {
|
|
764
|
-
NEXT_PUBLIC_IS_BUILDING: 'true',
|
|
765
|
-
EMAILS_DIR_RELATIVE_PATH: emailsDirRelativePath,
|
|
766
|
-
EMAILS_DIR_ABSOLUTE_PATH: path.resolve(userProjectLocation, emailsDirRelativePath),
|
|
767
|
-
USER_PROJECT_LOCATION: userProjectLocation
|
|
768
|
-
},
|
|
769
|
-
// this is needed so that the code for building emails works properly
|
|
770
|
-
webpack: (
|
|
771
|
-
/** @type {import('webpack').Configuration & { externals: string[] }} */
|
|
772
|
-
config,
|
|
773
|
-
{ isServer }
|
|
774
|
-
) => {
|
|
775
|
-
if (isServer) {
|
|
776
|
-
config.externals.push('esbuild');
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
return config;
|
|
780
|
-
},
|
|
781
|
-
typescript: {
|
|
782
|
-
ignoreBuildErrors: true
|
|
783
|
-
},
|
|
784
|
-
eslint: {
|
|
785
|
-
ignoreDuringBuilds: true
|
|
786
|
-
},
|
|
787
|
-
experimental: {
|
|
788
|
-
webpackBuildWorker: true
|
|
789
|
-
},
|
|
790
|
-
}`;
|
|
791
|
-
await fs5.promises.writeFile(
|
|
792
|
-
path8.resolve(builtPreviewAppPath, "./next.config.js"),
|
|
793
|
-
nextConfigContents,
|
|
794
|
-
"utf8"
|
|
795
|
-
);
|
|
796
|
-
};
|
|
797
|
-
var getEmailSlugsFromEmailDirectory = (emailDirectory, emailsDirectoryAbsolutePath) => {
|
|
798
|
-
const directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
|
|
799
|
-
const slugs = [];
|
|
800
|
-
emailDirectory.emailFilenames.forEach(
|
|
801
|
-
(filename) => slugs.push(
|
|
802
|
-
path8.join(directoryPathRelativeToEmailsDirectory, filename).split(path8.sep).filter((segment) => segment.length > 0)
|
|
803
|
-
)
|
|
804
|
-
);
|
|
805
|
-
emailDirectory.subDirectories.forEach((directory) => {
|
|
806
|
-
slugs.push(
|
|
807
|
-
...getEmailSlugsFromEmailDirectory(
|
|
808
|
-
directory,
|
|
809
|
-
emailsDirectoryAbsolutePath
|
|
810
|
-
)
|
|
811
|
-
);
|
|
812
|
-
});
|
|
813
|
-
return slugs;
|
|
814
|
-
};
|
|
815
|
-
var forceSSGForEmailPreviews = async (emailsDirPath, builtPreviewAppPath) => {
|
|
816
|
-
const emailDirectoryMetadata = (
|
|
817
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
818
|
-
await getEmailsDirectoryMetadata(emailsDirPath)
|
|
819
|
-
);
|
|
820
|
-
const parameters = getEmailSlugsFromEmailDirectory(
|
|
821
|
-
emailDirectoryMetadata,
|
|
822
|
-
emailsDirPath
|
|
823
|
-
).map((slug) => ({ slug }));
|
|
824
|
-
const removeForceDynamic = async (filePath) => {
|
|
825
|
-
const contents = await fs5.promises.readFile(filePath, "utf8");
|
|
826
|
-
await fs5.promises.writeFile(
|
|
827
|
-
filePath,
|
|
828
|
-
contents.replace("export const dynamic = 'force-dynamic';", ""),
|
|
829
|
-
"utf8"
|
|
830
|
-
);
|
|
831
|
-
};
|
|
832
|
-
await removeForceDynamic(
|
|
833
|
-
path8.resolve(builtPreviewAppPath, "./src/app/layout.tsx")
|
|
834
|
-
);
|
|
835
|
-
await removeForceDynamic(
|
|
836
|
-
path8.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx")
|
|
837
|
-
);
|
|
838
|
-
await fs5.promises.appendFile(
|
|
839
|
-
path8.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"),
|
|
840
|
-
`
|
|
841
|
-
|
|
842
|
-
export function generateStaticParams() {
|
|
843
|
-
return Promise.resolve(
|
|
844
|
-
${JSON.stringify(parameters)}
|
|
845
|
-
);
|
|
846
|
-
}`,
|
|
847
|
-
"utf8"
|
|
848
|
-
);
|
|
849
|
-
};
|
|
850
|
-
var updatePackageJson = async (builtPreviewAppPath) => {
|
|
851
|
-
const packageJsonPath = path8.resolve(builtPreviewAppPath, "./package.json");
|
|
852
|
-
const packageJson2 = JSON.parse(
|
|
853
|
-
await fs5.promises.readFile(packageJsonPath, "utf8")
|
|
854
|
-
);
|
|
855
|
-
packageJson2.scripts.build = "next build";
|
|
856
|
-
packageJson2.scripts.start = "next start";
|
|
857
|
-
packageJson2.name = "preview-server";
|
|
858
|
-
delete packageJson2.devDependencies["@react-email/render"];
|
|
859
|
-
delete packageJson2.devDependencies["@react-email/components"];
|
|
860
|
-
delete packageJson2.scripts.prepare;
|
|
861
|
-
await fs5.promises.writeFile(
|
|
862
|
-
packageJsonPath,
|
|
863
|
-
JSON.stringify(packageJson2),
|
|
864
|
-
"utf8"
|
|
865
|
-
);
|
|
866
|
-
};
|
|
867
|
-
var npmInstall = async (builtPreviewAppPath, packageManager) => {
|
|
868
|
-
return new Promise((resolve, reject) => {
|
|
869
|
-
const childProc = spawn(
|
|
870
|
-
packageManager,
|
|
871
|
-
[
|
|
872
|
-
"install",
|
|
873
|
-
packageManager === "deno" ? "" : "--include=dev",
|
|
874
|
-
packageManager === "deno" ? "--quiet" : "--silent"
|
|
875
|
-
],
|
|
876
|
-
{
|
|
877
|
-
cwd: builtPreviewAppPath,
|
|
878
|
-
shell: true
|
|
879
|
-
}
|
|
880
|
-
);
|
|
881
|
-
childProc.stdout.pipe(process.stdout);
|
|
882
|
-
childProc.stderr.pipe(process.stderr);
|
|
883
|
-
childProc.on("close", (code) => {
|
|
884
|
-
if (code === 0) {
|
|
885
|
-
resolve();
|
|
886
|
-
} else {
|
|
887
|
-
reject(
|
|
888
|
-
new Error(
|
|
889
|
-
`Unable to install the dependencies and it exited with code: ${code}`
|
|
890
|
-
)
|
|
891
|
-
);
|
|
892
|
-
}
|
|
893
|
-
});
|
|
894
|
-
});
|
|
895
|
-
};
|
|
896
|
-
var build = async ({
|
|
897
|
-
dir: emailsDirRelativePath,
|
|
898
|
-
packageManager
|
|
899
|
-
}) => {
|
|
900
|
-
try {
|
|
901
|
-
const spinner = ora2({
|
|
902
|
-
text: "Starting build process...",
|
|
903
|
-
prefixText: " "
|
|
904
|
-
}).start();
|
|
905
|
-
registerSpinnerAutostopping(spinner);
|
|
906
|
-
spinner.text = `Checking if ${emailsDirRelativePath} folder exists`;
|
|
907
|
-
if (!fs5.existsSync(emailsDirRelativePath)) {
|
|
908
|
-
process.exit(1);
|
|
909
|
-
}
|
|
910
|
-
const emailsDirPath = path8.join(process.cwd(), emailsDirRelativePath);
|
|
911
|
-
const staticPath = path8.join(emailsDirPath, "static");
|
|
912
|
-
const builtPreviewAppPath = path8.join(process.cwd(), ".react-email");
|
|
913
|
-
if (fs5.existsSync(builtPreviewAppPath)) {
|
|
914
|
-
spinner.text = "Deleting pre-existing `.react-email` folder";
|
|
915
|
-
await fs5.promises.rm(builtPreviewAppPath, { recursive: true });
|
|
916
|
-
}
|
|
917
|
-
spinner.text = "Copying preview app from CLI to `.react-email`";
|
|
918
|
-
await fs5.promises.cp(cliPackageLocation, builtPreviewAppPath, {
|
|
919
|
-
recursive: true,
|
|
920
|
-
filter: (source) => {
|
|
921
|
-
return !/(\/|\\)cli(\/|\\)?/.test(source) && !/(\/|\\)\.next(\/|\\)?/.test(source) && !/(\/|\\)\.turbo(\/|\\)?/.test(source) && !/(\/|\\)node_modules(\/|\\)?$/.test(source);
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
if (fs5.existsSync(staticPath)) {
|
|
925
|
-
spinner.text = "Copying `static` folder into `.react-email/public/static`";
|
|
926
|
-
const builtStaticDirectory = path8.resolve(
|
|
927
|
-
builtPreviewAppPath,
|
|
928
|
-
"./public/static"
|
|
929
|
-
);
|
|
930
|
-
await fs5.promises.cp(staticPath, builtStaticDirectory, {
|
|
931
|
-
recursive: true
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
spinner.text = "Setting Next environment variables for preview app to work properly";
|
|
935
|
-
await setNextEnvironmentVariablesForBuild(
|
|
936
|
-
emailsDirRelativePath,
|
|
937
|
-
builtPreviewAppPath
|
|
938
|
-
);
|
|
939
|
-
spinner.text = "Setting server side generation for the email preview pages";
|
|
940
|
-
await forceSSGForEmailPreviews(emailsDirPath, builtPreviewAppPath);
|
|
941
|
-
spinner.text = "Updating package.json's build and start scripts";
|
|
942
|
-
await updatePackageJson(builtPreviewAppPath);
|
|
943
|
-
spinner.text = "Installing dependencies on `.react-email`";
|
|
944
|
-
await npmInstall(builtPreviewAppPath, packageManager);
|
|
945
|
-
spinner.stopAndPersist({
|
|
946
|
-
text: "Successfully prepared `.react-email` for `next build`",
|
|
947
|
-
symbol: logSymbols3.success
|
|
948
|
-
});
|
|
949
|
-
await buildPreviewApp(builtPreviewAppPath);
|
|
950
|
-
} catch (error) {
|
|
951
|
-
console.log(error);
|
|
952
|
-
process.exit(1);
|
|
953
|
-
}
|
|
954
|
-
};
|
|
955
|
-
|
|
956
|
-
// src/commands/dev.ts
|
|
957
|
-
import fs6 from "node:fs";
|
|
958
|
-
var dev = async ({ dir: emailsDirRelativePath, port }) => {
|
|
959
|
-
try {
|
|
960
|
-
if (!fs6.existsSync(emailsDirRelativePath)) {
|
|
961
|
-
console.error(`Missing ${emailsDirRelativePath} folder`);
|
|
962
|
-
process.exit(1);
|
|
963
|
-
}
|
|
964
|
-
const devServer2 = await startDevServer(
|
|
965
|
-
emailsDirRelativePath,
|
|
966
|
-
emailsDirRelativePath,
|
|
967
|
-
// defaults to ./emails/static for the static files that are served to the preview
|
|
968
|
-
Number.parseInt(port)
|
|
969
|
-
);
|
|
970
|
-
await setupHotreloading(devServer2, emailsDirRelativePath);
|
|
971
|
-
} catch (error) {
|
|
972
|
-
console.log(error);
|
|
973
|
-
process.exit(1);
|
|
974
|
-
}
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
// src/commands/export.ts
|
|
978
|
-
import fs8, { unlinkSync, writeFileSync } from "node:fs";
|
|
979
|
-
import path10 from "node:path";
|
|
980
|
-
import { build as build2 } from "esbuild";
|
|
981
|
-
import { glob } from "glob";
|
|
982
|
-
import logSymbols4 from "log-symbols";
|
|
983
|
-
import normalize from "normalize-path";
|
|
984
|
-
import ora3 from "ora";
|
|
985
|
-
|
|
986
|
-
// src/utils/esbuild/renderring-utilities-exporter.ts
|
|
987
|
-
import { promises as fs7 } from "node:fs";
|
|
988
|
-
import path9 from "node:path";
|
|
989
|
-
|
|
990
|
-
// src/utils/esbuild/escape-string-for-regex.ts
|
|
991
|
-
function escapeStringForRegex(string) {
|
|
992
|
-
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// src/utils/esbuild/renderring-utilities-exporter.ts
|
|
996
|
-
var renderingUtilitiesExporter = (emailTemplates) => ({
|
|
997
|
-
name: "rendering-utilities-exporter",
|
|
998
|
-
setup: (b) => {
|
|
999
|
-
b.onLoad(
|
|
1000
|
-
{
|
|
1001
|
-
filter: new RegExp(
|
|
1002
|
-
emailTemplates.map((emailPath) => escapeStringForRegex(emailPath)).join("|")
|
|
1003
|
-
)
|
|
1004
|
-
},
|
|
1005
|
-
async ({ path: pathToFile }) => {
|
|
1006
|
-
return {
|
|
1007
|
-
contents: `${await fs7.readFile(pathToFile, "utf8")};
|
|
1008
|
-
export { render } from 'react-email-module-that-will-export-render'
|
|
1009
|
-
export { createElement as reactEmailCreateReactElement } from 'react';
|
|
1010
|
-
`,
|
|
1011
|
-
loader: path9.extname(pathToFile).slice(1)
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
);
|
|
1015
|
-
b.onResolve(
|
|
1016
|
-
{ filter: /^react-email-module-that-will-export-render$/ },
|
|
1017
|
-
async (args) => {
|
|
1018
|
-
const options = {
|
|
1019
|
-
kind: "import-statement",
|
|
1020
|
-
importer: args.importer,
|
|
1021
|
-
resolveDir: args.resolveDir,
|
|
1022
|
-
namespace: args.namespace
|
|
1023
|
-
};
|
|
1024
|
-
let result = await b.resolve("@react-email/render", options);
|
|
1025
|
-
if (result.errors.length === 0) {
|
|
1026
|
-
return result;
|
|
1027
|
-
}
|
|
1028
|
-
result = await b.resolve("@react-email/components", options);
|
|
1029
|
-
if (result.errors.length > 0 && result.errors[0]) {
|
|
1030
|
-
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?";
|
|
1031
|
-
}
|
|
1032
|
-
return result;
|
|
1033
|
-
}
|
|
1034
|
-
);
|
|
1035
|
-
}
|
|
1036
|
-
});
|
|
1037
|
-
|
|
1038
|
-
// src/commands/export.ts
|
|
1039
|
-
var getEmailTemplatesFromDirectory = (emailDirectory) => {
|
|
1040
|
-
const templatePaths = [];
|
|
1041
|
-
emailDirectory.emailFilenames.forEach(
|
|
1042
|
-
(filename) => templatePaths.push(path10.join(emailDirectory.absolutePath, filename))
|
|
1043
|
-
);
|
|
1044
|
-
emailDirectory.subDirectories.forEach((directory) => {
|
|
1045
|
-
templatePaths.push(...getEmailTemplatesFromDirectory(directory));
|
|
1046
|
-
});
|
|
1047
|
-
return templatePaths;
|
|
1048
|
-
};
|
|
1049
|
-
var exportTemplates = async (pathToWhereEmailMarkupShouldBeDumped, emailsDirectoryPath, options) => {
|
|
1050
|
-
if (fs8.existsSync(pathToWhereEmailMarkupShouldBeDumped)) {
|
|
1051
|
-
fs8.rmSync(pathToWhereEmailMarkupShouldBeDumped, { recursive: true });
|
|
1052
|
-
}
|
|
1053
|
-
let spinner;
|
|
1054
|
-
if (!options.silent) {
|
|
1055
|
-
spinner = ora3("Preparing files...\n").start();
|
|
1056
|
-
registerSpinnerAutostopping(spinner);
|
|
1057
|
-
}
|
|
1058
|
-
const emailsDirectoryMetadata = await getEmailsDirectoryMetadata(
|
|
1059
|
-
path10.resolve(process.cwd(), emailsDirectoryPath),
|
|
1060
|
-
true
|
|
1061
|
-
);
|
|
1062
|
-
if (typeof emailsDirectoryMetadata === "undefined") {
|
|
1063
|
-
if (spinner) {
|
|
1064
|
-
spinner.stopAndPersist({
|
|
1065
|
-
symbol: logSymbols4.error,
|
|
1066
|
-
text: `Could not find the directory at ${emailsDirectoryPath}`
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
return;
|
|
1070
|
-
}
|
|
1071
|
-
const allTemplates = getEmailTemplatesFromDirectory(emailsDirectoryMetadata);
|
|
1072
|
-
try {
|
|
1073
|
-
await build2({
|
|
1074
|
-
bundle: true,
|
|
1075
|
-
entryPoints: allTemplates,
|
|
1076
|
-
plugins: [renderingUtilitiesExporter(allTemplates)],
|
|
1077
|
-
platform: "node",
|
|
1078
|
-
format: "cjs",
|
|
1079
|
-
loader: { ".js": "jsx" },
|
|
1080
|
-
outExtension: { ".js": ".cjs" },
|
|
1081
|
-
jsx: "transform",
|
|
1082
|
-
write: true,
|
|
1083
|
-
outdir: pathToWhereEmailMarkupShouldBeDumped
|
|
1084
|
-
});
|
|
1085
|
-
} catch (exception) {
|
|
1086
|
-
const buildFailure = exception;
|
|
1087
|
-
if (spinner) {
|
|
1088
|
-
spinner.stopAndPersist({
|
|
1089
|
-
symbol: logSymbols4.error,
|
|
1090
|
-
text: "Failed to build emails"
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
process.exit(1);
|
|
1094
|
-
}
|
|
1095
|
-
if (spinner) {
|
|
1096
|
-
spinner.succeed();
|
|
1097
|
-
}
|
|
1098
|
-
const allBuiltTemplates = glob.sync(
|
|
1099
|
-
normalize(`${pathToWhereEmailMarkupShouldBeDumped}/**/*.cjs`),
|
|
1100
|
-
{
|
|
1101
|
-
absolute: true
|
|
1102
|
-
}
|
|
1103
|
-
);
|
|
1104
|
-
for await (const template of allBuiltTemplates) {
|
|
1105
|
-
try {
|
|
1106
|
-
if (spinner) {
|
|
1107
|
-
spinner.text = `rendering ${template.split("/").pop()}`;
|
|
1108
|
-
spinner.render();
|
|
1109
|
-
}
|
|
1110
|
-
delete __require.cache[template];
|
|
1111
|
-
const emailModule = __require(template);
|
|
1112
|
-
const rendered = await emailModule.render(
|
|
1113
|
-
emailModule.reactEmailCreateReactElement(emailModule.default, {}),
|
|
1114
|
-
options
|
|
1115
|
-
);
|
|
1116
|
-
const htmlPath = template.replace(
|
|
1117
|
-
".cjs",
|
|
1118
|
-
options.plainText ? ".txt" : ".html"
|
|
1119
|
-
);
|
|
1120
|
-
writeFileSync(htmlPath, rendered);
|
|
1121
|
-
unlinkSync(template);
|
|
1122
|
-
} catch (exception) {
|
|
1123
|
-
if (spinner) {
|
|
1124
|
-
spinner.stopAndPersist({
|
|
1125
|
-
symbol: logSymbols4.error,
|
|
1126
|
-
text: `failed when rendering ${template.split("/").pop()}`
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
console.error(exception);
|
|
1130
|
-
process.exit(1);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
if (spinner) {
|
|
1134
|
-
spinner.succeed("Rendered all files");
|
|
1135
|
-
spinner.text = "Copying static files";
|
|
1136
|
-
spinner.render();
|
|
1137
|
-
}
|
|
1138
|
-
const staticDirectoryPath = path10.join(emailsDirectoryPath, "static");
|
|
1139
|
-
if (fs8.existsSync(staticDirectoryPath)) {
|
|
1140
|
-
const pathToDumpStaticFilesInto = path10.join(
|
|
1141
|
-
pathToWhereEmailMarkupShouldBeDumped,
|
|
1142
|
-
"static"
|
|
1143
|
-
);
|
|
1144
|
-
if (fs8.existsSync(pathToDumpStaticFilesInto))
|
|
1145
|
-
await fs8.promises.rm(pathToDumpStaticFilesInto, { recursive: true });
|
|
1146
|
-
try {
|
|
1147
|
-
await fs8.promises.cp(staticDirectoryPath, pathToDumpStaticFilesInto, {
|
|
1148
|
-
recursive: true
|
|
1149
|
-
});
|
|
1150
|
-
} catch (exception) {
|
|
1151
|
-
console.error(exception);
|
|
1152
|
-
if (spinner) {
|
|
1153
|
-
spinner.stopAndPersist({
|
|
1154
|
-
symbol: logSymbols4.error,
|
|
1155
|
-
text: "Failed to copy static files"
|
|
1156
|
-
});
|
|
1157
|
-
}
|
|
1158
|
-
console.error(
|
|
1159
|
-
`Something went wrong while copying the file to ${pathToWhereEmailMarkupShouldBeDumped}/static, ${exception}`
|
|
1160
|
-
);
|
|
1161
|
-
process.exit(1);
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
if (spinner && !options.silent) {
|
|
1165
|
-
spinner.succeed();
|
|
1166
|
-
const fileTree = await tree(pathToWhereEmailMarkupShouldBeDumped, 4);
|
|
1167
|
-
console.log(fileTree);
|
|
1168
|
-
spinner.stopAndPersist({
|
|
1169
|
-
symbol: logSymbols4.success,
|
|
1170
|
-
text: "Successfully exported emails"
|
|
1171
|
-
});
|
|
1172
|
-
}
|
|
1173
|
-
};
|
|
1174
|
-
|
|
1175
|
-
// src/commands/start.ts
|
|
1176
|
-
import { spawn as spawn2 } from "node:child_process";
|
|
1177
|
-
import fs9 from "node:fs";
|
|
1178
|
-
import path11 from "node:path";
|
|
1179
|
-
var start = async () => {
|
|
1180
|
-
try {
|
|
1181
|
-
const usersProjectLocation = process.cwd();
|
|
1182
|
-
const builtPreviewPath = path11.resolve(
|
|
1183
|
-
usersProjectLocation,
|
|
1184
|
-
"./.react-email"
|
|
1185
|
-
);
|
|
1186
|
-
if (!fs9.existsSync(builtPreviewPath)) {
|
|
1187
|
-
console.error(
|
|
1188
|
-
"Could not find .react-email, maybe you haven't ran email build?"
|
|
1189
|
-
);
|
|
1190
|
-
process.exit(1);
|
|
1191
|
-
}
|
|
1192
|
-
const nextStart = spawn2("npm", ["start"], {
|
|
1193
|
-
cwd: builtPreviewPath,
|
|
1194
|
-
stdio: "inherit"
|
|
1195
|
-
});
|
|
1196
|
-
process.on("SIGINT", () => {
|
|
1197
|
-
nextStart.kill("SIGINT");
|
|
1198
|
-
});
|
|
1199
|
-
nextStart.on("exit", (code) => {
|
|
1200
|
-
process.exit(code ?? 0);
|
|
1201
|
-
});
|
|
1202
|
-
} catch (error) {
|
|
1203
|
-
console.log(error);
|
|
1204
|
-
process.exit(1);
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
|
|
1208
|
-
// src/index.ts
|
|
1209
|
-
var packageJson = JSON.parse(
|
|
1210
|
-
await fs10.readFile(
|
|
1211
|
-
path12.resolve(import.meta.dirname, "../package.json"),
|
|
1212
|
-
"utf8"
|
|
1213
|
-
)
|
|
1214
|
-
);
|
|
1215
|
-
var PACKAGE_NAME = "react-email";
|
|
1216
|
-
program.name(PACKAGE_NAME).description("A live preview of your emails right in your browser").version(packageJson.version);
|
|
1217
|
-
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);
|
|
1218
|
-
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(
|
|
1219
|
-
"-p --packageManager <name>",
|
|
1220
|
-
"Package name to use on installation on `.react-email`",
|
|
1221
|
-
"npm"
|
|
1222
|
-
).action(build);
|
|
1223
|
-
program.command("start").description('Runs the built preview app that is inside of ".react-email"').action(start);
|
|
1224
|
-
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(
|
|
1225
|
-
"-s, --silent",
|
|
1226
|
-
"To, or not to show a spinner with process information",
|
|
1227
|
-
false
|
|
1228
|
-
).action(
|
|
1229
|
-
({ outDir, pretty, plainText, silent, dir: srcDir }) => exportTemplates(outDir, srcDir, { silent, plainText, pretty })
|
|
1230
|
-
);
|
|
1231
|
-
program.parse();
|
|
1232
|
-
export {
|
|
1233
|
-
packageJson
|
|
1234
|
-
};
|