Skip to content

Commit 2131997

Browse files
committed
Add command to send url to phone
1 parent 05a535b commit 2131997

File tree

3 files changed

+206
-139
lines changed

3 files changed

+206
-139
lines changed

react-native-scripts/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-scripts",
3-
"version": "1.2.0-alpha.5",
3+
"version": "1.4.0",
44
"description": "Configuration and scripts for Create React Native App.",
55
"license": "BSD-3-Clause",
66
"keywords": [
@@ -39,7 +39,7 @@
3939
"progress": "^2.0.0",
4040
"qrcode-terminal": "^0.11.0",
4141
"rimraf": "^2.6.1",
42-
"xdl": "48.0.2"
42+
"xdl": "48.1.0"
4343
},
4444
"devDependencies": {
4545
"@taskr/babel": "^1.0.6",

react-native-scripts/src/scripts/start.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import chalk from 'chalk';
66
import indent from 'indent-string';
77
import qr from 'qrcode-terminal';
88
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';
1111

12+
import clearConsole from '../util/clearConsole';
13+
import log from '../util/log';
1214
import packager from '../util/packager';
1315

1416
Config.validation.reactNativeVersionWarnings = false;
@@ -27,13 +29,23 @@ if (args['reset-cache']) {
2729
log('Asking packager to reset its cache...');
2830
}
2931

30-
let isInteractive = false;
3132
const { stdin } = process;
32-
if (args.interactive && typeof stdin.setRawMode === 'function') {
33+
const startWaitingForCommand = () => {
3334
stdin.setRawMode(true);
3435
stdin.resume();
3536
stdin.setEncoding('utf8');
3637
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();
3749
isInteractive = true;
3850
}
3951

@@ -81,6 +93,7 @@ function printUsage() {
8193
log(
8294
`
8395
${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`)}
8497
${dim(`\u203A Press`)} q ${dim(`to display QR code.`)}
8598
${dim(`\u203A Press`)} r ${dim(`to restart packager, or`)} R ${dim(`to restart packager and clear cache.`)}
8699
${dim(`\u203A Press`)} d ${dim(`to toggle development mode. (current mode: ${bold(devMode)}${chalk.reset.dim(')')}`)}
@@ -120,6 +133,41 @@ async function handleKeypress(key) {
120133
printUsage();
121134
return;
122135
}
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+
}
123171
case 'q':
124172
clearConsole();
125173
await printServerInfo();

0 commit comments

Comments
 (0)