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
+
10
9
const displayNotification = require ( 'display-notification' ) ;
11
10
const getPort = require ( 'get-port' ) ;
12
11
const nodemailer = require ( 'nodemailer' ) ;
@@ -123,11 +122,11 @@ const previewEmail = async (message, options) => {
123
122
return booted ;
124
123
} ) ;
125
124
126
- let done = false ;
125
+ // let done = false;
127
126
const server = http . createServer ( ( req , res ) => {
128
127
pEvent ( res , 'close' ) . then ( ( ) => {
129
128
debug ( 'end' ) ;
130
- done = true ;
129
+ // done = true;
131
130
} ) ;
132
131
debug ( 'request made' ) ;
133
132
res . writeHead ( 200 , { 'Content-Type' : 'text/html' } ) ;
@@ -144,6 +143,29 @@ const previewEmail = async (message, options) => {
144
143
} ) ;
145
144
} ) ;
146
145
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
+ /*
147
169
const v = await cryptoRandomString({ length: 10, type: 'alphanumeric' });
148
170
149
171
const xcrun = childProcess.spawn('xcrun', [
@@ -166,6 +188,7 @@ const previewEmail = async (message, options) => {
166
188
});
167
189
168
190
await pWaitFor(() => done);
191
+ */
169
192
170
193
// display notification
171
194
await displayNotification ( {
0 commit comments