Skip to content

Commit 6fbb852

Browse files
feat(react-email): email-dev package for linking globally (#2258)
Co-authored-by: Bu Kinoshita <[email protected]>
1 parent 20fd2e9 commit 6fbb852

File tree

5 files changed

+77
-42
lines changed

5 files changed

+77
-42
lines changed

packages/react-email/dev/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import child_process from 'node:child_process';
2+
import path from 'node:path';
3+
import url from 'node:url';
4+
5+
const filename = url.fileURLToPath(import.meta.url);
6+
const dirname = path.dirname(filename);
7+
8+
const root = path.resolve(dirname, '../src/index.ts');
9+
10+
const tsxPath = path.resolve(dirname, './node_modules/.bin/tsx');
11+
12+
const tsx = child_process.spawn(tsxPath, [root, ...process.argv.slice(2)], {
13+
shell: true,
14+
cwd: process.cwd(),
15+
stdio: 'inherit',
16+
});
17+
18+
process.on('uncaughtExceptionMonitor', () => {
19+
tsx.kill();
20+
});
21+
22+
process.on('exit', (code) => {
23+
tsx.kill(code);
24+
});
25+
26+
process.on('SIGINT', () => {
27+
tsx.kill('SIGINT');
28+
});
29+
30+
process.on('SIGTERM', () => {
31+
tsx.kill('SIGTERM');
32+
});
33+
34+
process.on('SIGUSR1', () => {
35+
tsx.kill('SIGUSR1');
36+
});
37+
38+
process.on('SIGUSR2', () => {
39+
tsx.kill('SIGUSR2');
40+
});

packages/react-email/dev/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "email-dev",
3+
"version": "0.0.0",
4+
"bin": "index.js",
5+
"private": true,
6+
"type": "module",
7+
"scripts": {
8+
"start": "node ."
9+
},
10+
"dependencies": {
11+
"tsx": "4.19.3"
12+
}
13+
}

packages/react-email/readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ Generates the plain HTML files of your emails into a `out` directory.
3939
npx react-email export
4040
```
4141

42+
## Setting Up the Environment
43+
44+
When working in the CLI, a lot of friction can get introduced with installing it and rebuilding for every change. To avoid that, we have a script that can be linked globally to directly run the source code of the CLI. You can use it the same as you would the standard CLI.
45+
46+
### 1. Link `react-email` globally
47+
48+
```sh
49+
pnpm link ./dev -g
50+
```
51+
52+
### 2. Run the CLI
53+
54+
```sh
55+
email-dev [command] [flags]
56+
```
57+
4258
## License
4359

4460
MIT License

pnpm-lock.yaml

Lines changed: 7 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
packages:
22
- "apps/*"
33
- "packages/*"
4+
- "packages/react-email/dev"
45
- "benchmarks/*"

0 commit comments

Comments
 (0)