Skip to content

Commit f07f0ce

Browse files
authored
feat(react-email): email resend setup command (#2643)
1 parent f459e74 commit f07f0ce

File tree

7 files changed

+166
-4
lines changed

7 files changed

+166
-4
lines changed

β€Žpackages/react-email/package.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@babel/traverse": "^7.27.0",
3232
"chokidar": "^4.0.3",
3333
"commander": "^13.0.0",
34+
"conf": "^15.0.2",
3435
"debounce": "^2.0.0",
3536
"esbuild": "^0.25.0",
3637
"glob": "^11.0.0",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import logSymbols from 'log-symbols';
2+
import prompts from 'prompts';
3+
import { conf } from '../utils/conf.js';
4+
import { styleText } from '../utils/style-text.js';
5+
6+
export async function resendSetup(apiKey: string) {
7+
const previousValue = conf.get('resendApiKey');
8+
if (typeof previousValue === 'string' && previousValue.length > 0) {
9+
const response = await prompts({
10+
type: 'confirm',
11+
name: 'replaceApiKey',
12+
message: `You already have a Resend API Key configured (${styleText('grey', previousValue.slice(0, 11))}...). Do you want to replace it?`,
13+
initial: false,
14+
});
15+
if (!response.replaceApiKey) {
16+
process.exit(0);
17+
}
18+
}
19+
20+
conf.set('resendApiKey', apiKey);
21+
console.info(`${logSymbols.success} Resend integration successfully set up`);
22+
}

β€Žpackages/react-email/src/index.tsβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { program } from 'commander';
33
import { build } from './commands/build.js';
44
import { dev } from './commands/dev.js';
55
import { exportTemplates } from './commands/export.js';
6+
import { resendSetup } from './commands/resend-setup.js';
67
import { start } from './commands/start.js';
78
import { packageJson } from './utils/packageJson.js';
89

@@ -52,4 +53,13 @@ program
5253
exportTemplates(outDir, srcDir, { silent, plainText, pretty }),
5354
);
5455

56+
program
57+
.command('resend')
58+
.command('setup')
59+
.description(
60+
'Sets up the integration between the React Email CLI, and your Resend account through an API Key',
61+
)
62+
.argument('apiKey', 'API Key for use setting up the integration')
63+
.action(resendSetup);
64+
5565
program.parse();

β€Žpackages/react-email/src/utils/__snapshots__/tree.spec.ts.snapβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exports[`tree(__dirname, 2) 1`] = `
1616
β”œβ”€β”€ types
1717
β”‚ β”œβ”€β”€ hot-reload-change.ts
1818
β”‚ └── hot-reload-event.ts
19+
β”œβ”€β”€ conf.ts
1920
β”œβ”€β”€ get-emails-directory-metadata.spec.ts
2021
β”œβ”€β”€ get-emails-directory-metadata.ts
2122
β”œβ”€β”€ get-preview-server-location.ts
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Conf from 'conf';
2+
3+
// Just simple encryption. This isn't completely safe
4+
// because anyone can find this key here
5+
const encryptionKey = 'h2#x658}1#qY(@!:7,BD1J)q12$[tM25';
6+
7+
export const conf = new Conf<{
8+
resendApiKey?: string;
9+
}>({ projectName: 'react-email', encryptionKey });

β€Žpackages/react-email/src/utils/style-text.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import * as nodeUtil from 'node:util';
66

7-
type StyleTextFunction = (style: string, text: string) => string;
7+
type StyleTextFunction = typeof nodeUtil.styleText;
88

99
export const styleText: StyleTextFunction = (nodeUtil as any).styleText
1010
? (nodeUtil as any).styleText

0 commit comments

Comments
Β (0)