1- #!/usr/bin/env -S node --experimental-vm-modules --disable-warning=ExperimentalWarning
1+ #!/usr/bin/env node
2+ import { spawn } from 'node:child_process' ;
23import { program } from 'commander' ;
34import { build } from './commands/build.js' ;
45import { dev } from './commands/dev.js' ;
@@ -8,64 +9,102 @@ import { resendSetup } from './commands/resend/setup.js';
89import { start } from './commands/start.js' ;
910import { packageJson } from './utils/packageJson.js' ;
1011
11- const PACKAGE_NAME = 'react-email' ;
12+ const requiredFlags = [
13+ '--experimental-vm-modules' ,
14+ '--disable-warning=ExperimentalWarning' ,
15+ ] ;
1216
13- program
14- . name ( PACKAGE_NAME )
15- . description ( 'A live preview of your emails right in your browser' )
16- . version ( packageJson . version ) ;
17+ const hasRequiredFlags = requiredFlags . every ( ( flag ) =>
18+ process . execArgv . includes ( flag ) ,
19+ ) ;
1720
18- program
19- . command ( 'dev' )
20- . description ( 'Starts the preview email development app' )
21- . option ( '-d, --dir <path>' , 'Directory with your email templates' , './emails' )
22- . option ( '-p --port <port>' , 'Port to run dev server on' , '3000' )
23- . action ( dev ) ;
21+ if ( ! hasRequiredFlags ) {
22+ const child = spawn (
23+ process . execPath ,
24+ [
25+ ...requiredFlags ,
26+ ...process . execArgv ,
27+ process . argv [ 1 ] ?? '' ,
28+ ...process . argv . slice ( 2 ) ,
29+ ] ,
30+ { stdio : 'inherit' } ,
31+ ) ;
2432
25- program
26- . command ( 'build' )
27- . description ( 'Copies the preview app for onto .react-email and builds it' )
28- . option ( '-d, --dir <path>' , 'Directory with your email templates' , './emails' )
29- . option (
30- '-p --packageManager <name>' ,
31- 'Package name to use on installation on `.react-email`' ,
32- 'npm' ,
33- )
34- . action ( build ) ;
33+ child . on ( 'exit' , ( code ) => {
34+ process . exit ( code ?? 0 ) ;
35+ } ) ;
36+ } else {
37+ const PACKAGE_NAME = 'react-email' ;
3538
36- program
37- . command ( 'start' )
38- . description ( 'Runs the built preview app that is inside of ".react-email" ' )
39- . action ( start ) ;
39+ program
40+ . name ( PACKAGE_NAME )
41+ . description ( 'A live preview of your emails right in your browser ' )
42+ . version ( packageJson . version ) ;
4043
41- program
42- . command ( 'export' )
43- . description ( 'Build the templates to the `out` directory' )
44- . option ( '--outDir <path>' , 'Output directory' , 'out' )
45- . option ( '-p, --pretty' , 'Pretty print the output' , false )
46- . option ( '-t, --plainText' , 'Set output format as plain text' , false )
47- . option ( '-d, --dir <path>' , 'Directory with your email templates' , './emails' )
48- . option (
49- '-s, --silent' ,
50- 'To, or not to show a spinner with process information' ,
51- false ,
52- )
53- . action ( ( { outDir, pretty, plainText, silent, dir : srcDir } ) =>
54- exportTemplates ( outDir , srcDir , { silent, plainText, pretty } ) ,
55- ) ;
44+ program
45+ . command ( 'dev' )
46+ . description ( 'Starts the preview email development app' )
47+ . option (
48+ '-d, --dir <path>' ,
49+ 'Directory with your email templates' ,
50+ './emails' ,
51+ )
52+ . option ( '-p --port <port>' , 'Port to run dev server on' , '3000' )
53+ . action ( dev ) ;
54+
55+ program
56+ . command ( 'build' )
57+ . description ( 'Copies the preview app for onto .react-email and builds it' )
58+ . option (
59+ '-d, --dir <path>' ,
60+ 'Directory with your email templates' ,
61+ './emails' ,
62+ )
63+ . option (
64+ '-p --packageManager <name>' ,
65+ 'Package name to use on installation on `.react-email`' ,
66+ 'npm' ,
67+ )
68+ . action ( build ) ;
69+
70+ program
71+ . command ( 'start' )
72+ . description ( 'Runs the built preview app that is inside of ".react-email"' )
73+ . action ( start ) ;
74+
75+ program
76+ . command ( 'export' )
77+ . description ( 'Build the templates to the `out` directory' )
78+ . option ( '--outDir <path>' , 'Output directory' , 'out' )
79+ . option ( '-p, --pretty' , 'Pretty print the output' , false )
80+ . option ( '-t, --plainText' , 'Set output format as plain text' , false )
81+ . option (
82+ '-d, --dir <path>' ,
83+ 'Directory with your email templates' ,
84+ './emails' ,
85+ )
86+ . option (
87+ '-s, --silent' ,
88+ 'To, or not to show a spinner with process information' ,
89+ false ,
90+ )
91+ . action ( ( { outDir, pretty, plainText, silent, dir : srcDir } ) =>
92+ exportTemplates ( outDir , srcDir , { silent, plainText, pretty } ) ,
93+ ) ;
5694
57- const resend = program . command ( 'resend' ) ;
95+ const resend = program . command ( 'resend' ) ;
5896
59- resend
60- . command ( 'setup' )
61- . description (
62- 'Sets up the integration between the React Email CLI, and your Resend account through an API Key' ,
63- )
64- . action ( resendSetup ) ;
97+ resend
98+ . command ( 'setup' )
99+ . description (
100+ 'Sets up the integration between the React Email CLI, and your Resend account through an API Key' ,
101+ )
102+ . action ( resendSetup ) ;
65103
66- resend
67- . command ( 'reset' )
68- . description ( 'Deletes your API Key from the React Email configuration' )
69- . action ( resendReset ) ;
104+ resend
105+ . command ( 'reset' )
106+ . description ( 'Deletes your API Key from the React Email configuration' )
107+ . action ( resendReset ) ;
70108
71- program . parse ( ) ;
109+ program . parse ( ) ;
110+ }
0 commit comments