@@ -6,9 +6,11 @@ import chalk from 'chalk';
6
6
import indent from 'indent-string' ;
7
7
import qr from 'qrcode-terminal' ;
8
8
import minimist from 'minimist' ;
9
- import log from '../util/log ' ;
10
- import clearConsole from '../util/clearConsole ' ;
9
+ import readline from 'readline ' ;
10
+ import { Exp } from 'xdl ' ;
11
11
12
+ import clearConsole from '../util/clearConsole' ;
13
+ import log from '../util/log' ;
12
14
import packager from '../util/packager' ;
13
15
14
16
Config . validation . reactNativeVersionWarnings = false ;
@@ -27,13 +29,23 @@ if (args['reset-cache']) {
27
29
log ( 'Asking packager to reset its cache...' ) ;
28
30
}
29
31
30
- let isInteractive = false ;
31
32
const { stdin } = process ;
32
- if ( args . interactive && typeof stdin . setRawMode === 'function' ) {
33
+ const startWaitingForCommand = ( ) => {
33
34
stdin . setRawMode ( true ) ;
34
35
stdin . resume ( ) ;
35
36
stdin . setEncoding ( 'utf8' ) ;
36
37
stdin . on ( 'data' , handleKeypress ) ;
38
+ }
39
+
40
+ const stopWaitingForCommand = ( ) => {
41
+ stdin . removeListener ( 'data' , handleKeypress ) ;
42
+ stdin . setRawMode ( false ) ;
43
+ stdin . resume ( ) ;
44
+ }
45
+
46
+ let isInteractive = false ;
47
+ if ( args . interactive && typeof stdin . setRawMode === 'function' ) {
48
+ startWaitingForCommand ( ) ;
37
49
isInteractive = true ;
38
50
}
39
51
@@ -81,6 +93,7 @@ function printUsage() {
81
93
log (
82
94
`
83
95
${ dim ( `\u203A Press` ) } a ${ dim ( `to open Android device or emulator` ) } ${ iosInfo }
96
+ ${ dim ( `\u203A Press` ) } s ${ dim ( `to send the packager URL to your phone number or email address` ) }
84
97
${ dim ( `\u203A Press` ) } q ${ dim ( `to display QR code.` ) }
85
98
${ dim ( `\u203A Press` ) } r ${ dim ( `to restart packager, or` ) } R ${ dim ( `to restart packager and clear cache.` ) }
86
99
${ dim ( `\u203A Press` ) } d ${ dim ( `to toggle development mode. (current mode: ${ bold ( devMode ) } ${ chalk . reset . dim ( ')' ) } ` ) }
@@ -120,6 +133,41 @@ async function handleKeypress(key) {
120
133
printUsage ( ) ;
121
134
return ;
122
135
}
136
+ case 's' : {
137
+ stopWaitingForCommand ( ) ;
138
+ const lanAddress = await UrlUtils . constructManifestUrlAsync ( process . cwd ( ) , {
139
+ hostType : 'lan' ,
140
+ } ) ;
141
+
142
+ const rl = readline . createInterface ( {
143
+ input : process . stdin ,
144
+ output : process . stdout
145
+ } ) ;
146
+
147
+ clearConsole ( ) ;
148
+ log . withTimestamp ( 'Please enter your phone number or email address (empty to cancel):' )
149
+ rl . question ( '> ' , async ( sendTo ) => {
150
+ rl . close ( ) ;
151
+ startWaitingForCommand ( ) ;
152
+ if ( ! sendTo ) {
153
+ clearConsole ( ) ;
154
+ printUsage ( ) ;
155
+ return ;
156
+ }
157
+
158
+ log . withTimestamp ( `Sending ${ lanAddress } to ${ sendTo } ...` ) ;
159
+
160
+ try {
161
+ await Exp . sendAsync ( sendTo , lanAddress , true ) ;
162
+ log . withTimestamp ( `Sent link successfully.` ) ;
163
+ } catch ( err ) {
164
+ log . withTimestamp ( `Could not send link. ${ err } ` ) ;
165
+ }
166
+ printUsage ( ) ;
167
+ } ) ;
168
+
169
+ return ;
170
+ }
123
171
case 'q' :
124
172
clearConsole ( ) ;
125
173
await printServerInfo ( ) ;
0 commit comments