1- const childProcess = require ( 'child_process' ) ;
2- const fs = require ( 'fs' ) ;
3- const http = require ( 'http' ) ;
4- const os = require ( 'os' ) ;
5- const path = require ( 'path' ) ;
6- const process = require ( 'process' ) ;
7- const util = require ( 'util' ) ;
8-
9- const cryptoRandomString = require ( 'crypto-random-string' ) ;
1+ const childProcess = require ( 'node:child_process' ) ;
2+ const fs = require ( 'node:fs' ) ;
3+ const http = require ( 'node:http' ) ;
4+ const os = require ( 'node:os' ) ;
5+ const path = require ( 'node:path' ) ;
6+ const process = require ( 'node:process' ) ;
7+ const util = require ( 'node:util' ) ;
8+
109const displayNotification = require ( 'display-notification' ) ;
1110const getPort = require ( 'get-port' ) ;
1211const nodemailer = require ( 'nodemailer' ) ;
@@ -123,11 +122,11 @@ const previewEmail = async (message, options) => {
123122 return booted ;
124123 } ) ;
125124
126- let done = false ;
125+ // let done = false;
127126 const server = http . createServer ( ( req , res ) => {
128127 pEvent ( res , 'close' ) . then ( ( ) => {
129128 debug ( 'end' ) ;
130- done = true ;
129+ // done = true;
131130 } ) ;
132131 debug ( 'request made' ) ;
133132 res . writeHead ( 200 , { 'Content-Type' : 'text/html' } ) ;
@@ -144,6 +143,29 @@ const previewEmail = async (message, options) => {
144143 } ) ;
145144 } ) ;
146145
146+ const emlFilePath = `${ options . dir } /${ options . id } .eml` ;
147+ await writeFile ( emlFilePath , response . message ) ;
148+ console . log ( 'emlFilePath' , emlFilePath ) ;
149+ const xcrun = childProcess . spawn ( 'xcrun' , [
150+ 'simctl' ,
151+ 'openurl' ,
152+ 'booted' ,
153+ emlFilePath
154+ ] ) ;
155+ await new Promise ( ( resolve , reject ) => {
156+ xcrun . once ( 'error' , reject ) ;
157+ xcrun . once ( 'close' , ( exitCode ) => {
158+ if ( exitCode === 72 )
159+ return reject (
160+ new Error (
161+ `Could not open URL in booted Simulator; make sure Simulator is running.`
162+ )
163+ ) ;
164+ resolve ( xcrun ) ;
165+ } ) ;
166+ } ) ;
167+
168+ /*
147169 const v = await cryptoRandomString({ length: 10, type: 'alphanumeric' });
148170
149171 const xcrun = childProcess.spawn('xcrun', [
@@ -166,6 +188,7 @@ const previewEmail = async (message, options) => {
166188 });
167189
168190 await pWaitFor(() => done);
191+ */
169192
170193 // display notification
171194 await displayNotification ( {
0 commit comments