From 078cedc9ef93a70dc3f77dfb80373fa28fea04d8 Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Mon, 24 Jul 2017 20:07:56 +0300 Subject: [PATCH 01/11] Implement interactive mode with keyboard commands --- react-native-scripts/src/scripts/android.js | 2 - react-native-scripts/src/scripts/start.js | 97 +++++++++++++++++-- react-native-scripts/src/util/clearConsole.js | 3 + react-native-scripts/src/util/packager.js | 5 - 4 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 react-native-scripts/src/util/clearConsole.js diff --git a/react-native-scripts/src/scripts/android.js b/react-native-scripts/src/scripts/android.js index f9b29e25..b9864949 100644 --- a/react-native-scripts/src/scripts/android.js +++ b/react-native-scripts/src/scripts/android.js @@ -15,8 +15,6 @@ Config.validation.reactNativeVersionWarnings = false; Config.developerTool = 'crna'; Config.offline = true; -const command: string = pathExists.sync(path.join(process.cwd(), 'yarn.lock')) ? 'yarnpkg' : 'npm'; - packager.run(startAndroidAndPrintInfo); // print a nicely formatted message with setup information diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index d99e4f63..8e635f4b 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -1,11 +1,13 @@ // @flow -import { Config, ProjectSettings, UrlUtils } from 'xdl'; +import { Android, Config, Project, ProjectSettings, Simulator, UrlUtils } from 'xdl'; import chalk from 'chalk'; import indent from 'indent-string'; import qr from 'qrcode-terminal'; +import minimist from 'minimist'; import log from '../util/log'; +import clearConsole from '../util/clearConsole'; import packager from '../util/packager'; @@ -13,7 +15,9 @@ Config.validation.reactNativeVersionWarnings = false; Config.developerTool = 'crna'; Config.offline = true; -const args = require('minimist')(process.argv.slice(2), { boolean: ['--reset-cache'] }); +const args = minimist(process.argv.slice(2), { boolean: ['--reset-cache'] }); + +let dev = true; const options = {}; if (args['reset-cache']) { @@ -21,7 +25,20 @@ if (args['reset-cache']) { log('Asking packager to reset its cache...'); } -packager.run(printServerInfo, options); +const { stdin } = process; +if (typeof stdin.setRawMode === 'function') { + stdin.setRawMode(true); + stdin.resume(); + stdin.setEncoding('utf8'); + stdin.on('data', handleKeypress); +} + +packager.run(onReady, options); + +function onReady() { + log(chalk.green('Packager started!\n')); + printServerInfo(); +} // print a nicely formatted message with setup information async function printServerInfo() { @@ -30,9 +47,7 @@ async function printServerInfo() { const address = await UrlUtils.constructManifestUrlAsync(process.cwd()); qr.generate(address, qrCode => { log( - `${chalk.green('Packager started!')} - -To view your app with live reloading, point the Expo app to this QR code. + `To view your app with live reloading, point the Expo app to this QR code. You'll find the QR scanner on the Projects tab of the app. ${indent(qrCode, 2)} @@ -48,5 +63,75 @@ For links to install the Expo app, please visit ${chalk.underline(chalk.cyan('ht Logs from serving your app will appear here. Press Ctrl+C at any time to stop. ` ); + printUsage(); }); } + +function printUsage() { + const devMode = chalk.bold(dev ? 'development' : 'production'); + log( + `${chalk.bold('Usage')} + ${chalk.dim('\u203A Press')} a ${chalk.dim('to open Android device or emulator.')} + ${chalk.dim('\u203A Press')} i ${chalk.dim('to open iOS emulator.')} + ${chalk.dim('\u203A Press')} q ${chalk.dim('to display QR code.')} + ${chalk.dim('\u203A Press')} r ${chalk.dim('to restart packager.')} + ${chalk.dim('\u203A Press')} R ${chalk.dim('to restart packager and clear cache.')} + ${chalk.dim('\u203A Press')} d ${chalk.dim('to toggle development mode. (current mode: ' + devMode)})` + ); +} + +const CTRL_C = '\u0003'; +const CTRL_D = '\u0004'; + +async function handleKeypress(key) { + switch (key) { + case CTRL_C: + case CTRL_D: + process.exit(); + case 'a': { + clearConsole(); + log.withTimestamp('Starting Android...'); + const { success, error } = await Android.openProjectAsync(process.cwd()); + if (!success) { + log(chalk.red(error.message)); + } + printUsage(); + return; + } + case 'i': { + clearConsole(); + log.withTimestamp('Starting iOS...'); + const localAddress = await UrlUtils.constructManifestUrlAsync(process.cwd(), { + hostType: 'localhost', + }); + const { success, msg } = await Simulator.openUrlInSimulatorSafeAsync(localAddress); + if (!success) { + log(chalk.red(msg)); + } + printUsage(); + return; + } + case 'q': + clearConsole(); + await printServerInfo(); + return; + case 'r': + case 'R': { + clearConsole(); + const reset = key === 'R'; + if (reset) { + log.withTimestamp('Asking packager to reset its cache...'); + } + log.withTimestamp('Restarting packager...'); + Project.startAsync(process.cwd(), { reset }); + return; + } + case 'd': + clearConsole(); + dev = !dev; + await ProjectSettings.setAsync(process.cwd(), { dev }); + log(`Packager now running in ${chalk.bold(dev ? 'development' : 'production')} mode.`); + printUsage(); + return; + } +} diff --git a/react-native-scripts/src/util/clearConsole.js b/react-native-scripts/src/util/clearConsole.js new file mode 100644 index 00000000..691707b3 --- /dev/null +++ b/react-native-scripts/src/util/clearConsole.js @@ -0,0 +1,3 @@ +export default function clearConsole() { + process.stdout.write(process.platform === 'win32' ? '\x1Bc' : '\x1B[2J\x1B[3J\x1B[H'); +} diff --git a/react-native-scripts/src/util/packager.js b/react-native-scripts/src/util/packager.js index b03c4f5f..ffa6e43c 100644 --- a/react-native-scripts/src/util/packager.js +++ b/react-native-scripts/src/util/packager.js @@ -8,11 +8,6 @@ import chalk from 'chalk'; import log from './log'; -// TODO get babel output that's nice enough to let it take over the console -function clearConsole() { - process.stdout.write(process.platform === 'win32' ? '\x1Bc' : '\x1B[2J\x1B[3J\x1B[H'); -} - function installExitHooks(projectDir) { if (process.platform === 'win32') { require('readline') From 1f4ede57a0609e7dbbe6054895cd545c49f032e9 Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Tue, 25 Jul 2017 12:07:28 +0300 Subject: [PATCH 02/11] Ask people to reopen the app when toggling dev mode This is currently required for the change to take effect, see: https://github.com/expo/expo/issues/413 --- react-native-scripts/src/scripts/start.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index 8e635f4b..aef3262a 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -60,8 +60,7 @@ Your phone will need to be on the same local network as this computer. For links to install the Expo app, please visit ${chalk.underline(chalk.cyan('https://expo.io'))}. -Logs from serving your app will appear here. Press Ctrl+C at any time to stop. -` +Logs from serving your app will appear here. Press Ctrl+C at any time to stop.` ); printUsage(); }); @@ -69,8 +68,8 @@ Logs from serving your app will appear here. Press Ctrl+C at any time to stop. function printUsage() { const devMode = chalk.bold(dev ? 'development' : 'production'); - log( - `${chalk.bold('Usage')} + log(` +${chalk.bold('Usage')} ${chalk.dim('\u203A Press')} a ${chalk.dim('to open Android device or emulator.')} ${chalk.dim('\u203A Press')} i ${chalk.dim('to open iOS emulator.')} ${chalk.dim('\u203A Press')} q ${chalk.dim('to display QR code.')} @@ -88,6 +87,7 @@ async function handleKeypress(key) { case CTRL_C: case CTRL_D: process.exit(); + return; case 'a': { clearConsole(); log.withTimestamp('Starting Android...'); @@ -130,7 +130,12 @@ async function handleKeypress(key) { clearConsole(); dev = !dev; await ProjectSettings.setAsync(process.cwd(), { dev }); - log(`Packager now running in ${chalk.bold(dev ? 'development' : 'production')} mode.`); + log( + `Packager now running in ${chalk.bold(dev ? 'development' : 'production')} mode. + +Please close and reopen the project in the Expo app for the +change to take effect.` + ); printUsage(); return; } From e8bb7104021c013e77dbbde50d0b583271317775 Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Tue, 25 Jul 2017 12:58:09 +0300 Subject: [PATCH 03/11] Condense instructions to take less vertical space --- react-native-scripts/src/scripts/android.js | 1 - react-native-scripts/src/scripts/ios.js | 1 - react-native-scripts/src/scripts/start.js | 14 ++++++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/react-native-scripts/src/scripts/android.js b/react-native-scripts/src/scripts/android.js index b9864949..aae2d657 100644 --- a/react-native-scripts/src/scripts/android.js +++ b/react-native-scripts/src/scripts/android.js @@ -38,7 +38,6 @@ Or enter this address in the Expo app's search bar: ${chalk.underline(chalk.cyan(address))} Your phone will need to be on the same local network as this computer. - For links to install the Expo app, please visit ${chalk.underline(chalk.cyan('https://expo.io'))}. Logs from serving your app will appear here. Press Ctrl+C at any time to stop. diff --git a/react-native-scripts/src/scripts/ios.js b/react-native-scripts/src/scripts/ios.js index f353dc7a..b172beef 100644 --- a/react-native-scripts/src/scripts/ios.js +++ b/react-native-scripts/src/scripts/ios.js @@ -58,7 +58,6 @@ Or enter this address in the Expo app's search bar: ${chalk.underline(chalk.cyan(address))} Your phone will need to be on the same local network as this computer. - For links to install the Expo app, please visit ${chalk.underline(chalk.cyan('https://expo.io'))}. Logs from serving your app will appear here. Press Ctrl+C at any time to stop. diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index aef3262a..f1f1111e 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -57,7 +57,6 @@ Or enter this address in the Expo app's search bar: ${chalk.underline(chalk.cyan(address))} Your phone will need to be on the same local network as this computer. - For links to install the Expo app, please visit ${chalk.underline(chalk.cyan('https://expo.io'))}. Logs from serving your app will appear here. Press Ctrl+C at any time to stop.` @@ -67,15 +66,14 @@ Logs from serving your app will appear here. Press Ctrl+C at any time to stop.` } function printUsage() { + const { dim } = chalk; const devMode = chalk.bold(dev ? 'development' : 'production'); log(` -${chalk.bold('Usage')} - ${chalk.dim('\u203A Press')} a ${chalk.dim('to open Android device or emulator.')} - ${chalk.dim('\u203A Press')} i ${chalk.dim('to open iOS emulator.')} - ${chalk.dim('\u203A Press')} q ${chalk.dim('to display QR code.')} - ${chalk.dim('\u203A Press')} r ${chalk.dim('to restart packager.')} - ${chalk.dim('\u203A Press')} R ${chalk.dim('to restart packager and clear cache.')} - ${chalk.dim('\u203A Press')} d ${chalk.dim('to toggle development mode. (current mode: ' + devMode)})` + ${dim(`\u203A Press`)} a ${dim(`to open Android device or emulator, or`)} i ${dim(`to open iOS emulator.`)} + ${dim(`\u203A Press`)} q ${dim(`to display QR code.`)} + ${dim(`\u203A Press`)} r ${dim(`to restart packager, or R to restart packager and clear cache.`)} + ${dim(`\u203A Press`)} d ${dim(`to toggle development mode. (current mode: ${devMode})`)} +` ); } From c1eb74a053ae95f1c3d9b798839ff3a81e1b480b Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Tue, 25 Jul 2017 13:15:10 +0300 Subject: [PATCH 04/11] Hide the iOS emulator option on Windows --- react-native-scripts/src/scripts/start.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index f1f1111e..dee1df1c 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -68,8 +68,11 @@ Logs from serving your app will appear here. Press Ctrl+C at any time to stop.` function printUsage() { const { dim } = chalk; const devMode = chalk.bold(dev ? 'development' : 'production'); + const iosInfo = process.platform === 'win32' ? + dim('.') : + `${dim(`, or`)} i ${dim(`to open iOS emulator.`)}`; log(` - ${dim(`\u203A Press`)} a ${dim(`to open Android device or emulator, or`)} i ${dim(`to open iOS emulator.`)} + ${dim(`\u203A Press`)} a ${dim(`to open Android device or emulator`)}${iosInfo} ${dim(`\u203A Press`)} q ${dim(`to display QR code.`)} ${dim(`\u203A Press`)} r ${dim(`to restart packager, or R to restart packager and clear cache.`)} ${dim(`\u203A Press`)} d ${dim(`to toggle development mode. (current mode: ${devMode})`)} From b672abaaa4b715228fad015edb0ab59cc457892e Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Tue, 25 Jul 2017 22:16:39 +0300 Subject: [PATCH 05/11] Highlight the 'R' keyboard shortcut --- react-native-scripts/src/scripts/start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index dee1df1c..b3a47b6e 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -74,7 +74,7 @@ function printUsage() { log(` ${dim(`\u203A Press`)} a ${dim(`to open Android device or emulator`)}${iosInfo} ${dim(`\u203A Press`)} q ${dim(`to display QR code.`)} - ${dim(`\u203A Press`)} r ${dim(`to restart packager, or R to restart packager and clear cache.`)} + ${dim(`\u203A Press`)} r ${dim(`to restart packager, or`)} R ${dim(`to restart packager and clear cache.`)} ${dim(`\u203A Press`)} d ${dim(`to toggle development mode. (current mode: ${devMode})`)} ` ); From 644c8ebd05148163a1540ba62b2888dbb0bee359 Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Thu, 27 Jul 2017 19:31:15 +0300 Subject: [PATCH 06/11] Add `--no-interactive` CLI argument to disable the interactive mode `npm start -- --no-interactive` runs the server without interactivity. --- react-native-scripts/src/scripts/start.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index b3a47b6e..85be16f8 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -15,8 +15,10 @@ Config.validation.reactNativeVersionWarnings = false; Config.developerTool = 'crna'; Config.offline = true; -const args = minimist(process.argv.slice(2), { boolean: ['--reset-cache'] }); - +const args = minimist(process.argv.slice(2), { + boolean: ['reset-cache', 'interactive'], + default: { interactive: true }, +}); let dev = true; const options = {}; @@ -25,12 +27,14 @@ if (args['reset-cache']) { log('Asking packager to reset its cache...'); } +let isInteractive = false; const { stdin } = process; -if (typeof stdin.setRawMode === 'function') { +if (args.interactive && typeof stdin.setRawMode === 'function') { stdin.setRawMode(true); stdin.resume(); stdin.setEncoding('utf8'); stdin.on('data', handleKeypress); + isInteractive = true; } packager.run(onReady, options); @@ -66,6 +70,9 @@ Logs from serving your app will appear here. Press Ctrl+C at any time to stop.` } function printUsage() { + if (!isInteractive) { + return; + } const { dim } = chalk; const devMode = chalk.bold(dev ? 'development' : 'production'); const iosInfo = process.platform === 'win32' ? From 587e5b83304a1edeffb918a0f457956d57d7a82a Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Fri, 28 Jul 2017 14:49:11 +0300 Subject: [PATCH 07/11] Fix interactive mode input on Windows The `readline` setup on Windows that nicely suppresses the annoying "Terminate batch job (Y/N)" prompt when pressing Ctrl+c also caused the keyboard commands on interactive mode to be printed to stdout. Fix this by piping the `readline` output to a MuteStream. --- react-native-scripts/package.json | 1 + react-native-scripts/src/util/packager.js | 13 ++++++++----- react-native-scripts/yarn.lock | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/react-native-scripts/package.json b/react-native-scripts/package.json index 3ffc2b77..8f6e76f1 100644 --- a/react-native-scripts/package.json +++ b/react-native-scripts/package.json @@ -32,6 +32,7 @@ "inquirer": "^3.0.1", "match-require": "^2.0.0", "minimist": "^1.2.0", + "mute-stream": "^0.0.7", "path-exists": "^3.0.0", "progress": "^2.0.0", "qrcode-terminal": "^0.11.0", diff --git a/react-native-scripts/src/util/packager.js b/react-native-scripts/src/util/packager.js index ffa6e43c..f2731050 100644 --- a/react-native-scripts/src/util/packager.js +++ b/react-native-scripts/src/util/packager.js @@ -5,15 +5,20 @@ import { PackagerLogsStream, Project, ProjectSettings, ProjectUtils } from 'xdl' import ProgressBar from 'progress'; import bunyan from '@expo/bunyan'; import chalk from 'chalk'; +import MuteStream from 'mute-stream'; import log from './log'; function installExitHooks(projectDir) { if (process.platform === 'win32') { + const output = new MuteStream(); + output.pipe(process.stdout); + // Hide the command prompt and entered characters. + output.mute(); require('readline') .createInterface({ input: process.stdin, - output: process.stdout, + output, }) .on('SIGINT', () => { process.emit('SIGINT'); @@ -48,12 +53,10 @@ async function cleanUpPackager(projectDir) { } function shouldIgnoreMsg(msg) { - return ( - msg.indexOf('Duplicate module name: bser') >= 0 || + return msg.indexOf('Duplicate module name: bser') >= 0 || msg.indexOf('Duplicate module name: fb-watchman') >= 0 || msg.indexOf('Warning: React.createClass is no longer supported') >= 0 || - msg.indexOf('Warning: PropTypes has been moved to a separate package') >= 0 - ); + msg.indexOf('Warning: PropTypes has been moved to a separate package') >= 0; } function run(onReady: () => ?any, options: Object = {}) { diff --git a/react-native-scripts/yarn.lock b/react-native-scripts/yarn.lock index f3c68091..910a4645 100644 --- a/react-native-scripts/yarn.lock +++ b/react-native-scripts/yarn.lock @@ -2138,7 +2138,7 @@ ms@2.0.0, ms@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" -mute-stream@0.0.7: +mute-stream@0.0.7, mute-stream@^0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" From c7251dfe8f209f614499143bd5f1b660c79d966a Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Fri, 28 Jul 2017 14:50:04 +0300 Subject: [PATCH 08/11] Stop the packager gracefully when exiting interactive mode --- react-native-scripts/src/scripts/start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index 85be16f8..8cc56526 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -94,7 +94,7 @@ async function handleKeypress(key) { switch (key) { case CTRL_C: case CTRL_D: - process.exit(); + process.emit('SIGINT'); return; case 'a': { clearConsole(); From 113769d519495382c1ee174930936b88ab964900 Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Fri, 28 Jul 2017 14:51:06 +0300 Subject: [PATCH 09/11] Format new code with Prettier --- react-native-scripts/src/scripts/start.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index 8cc56526..a0827f07 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -75,10 +75,11 @@ function printUsage() { } const { dim } = chalk; const devMode = chalk.bold(dev ? 'development' : 'production'); - const iosInfo = process.platform === 'win32' ? - dim('.') : - `${dim(`, or`)} i ${dim(`to open iOS emulator.`)}`; - log(` + const iosInfo = process.platform === 'win32' + ? dim('.') + : `${dim(`, or`)} i ${dim(`to open iOS emulator.`)}`; + log( + ` ${dim(`\u203A Press`)} a ${dim(`to open Android device or emulator`)}${iosInfo} ${dim(`\u203A Press`)} q ${dim(`to display QR code.`)} ${dim(`\u203A Press`)} r ${dim(`to restart packager, or`)} R ${dim(`to restart packager and clear cache.`)} From 38b5126b2ac0978dcab793f775977adfce3753ad Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Fri, 28 Jul 2017 15:13:31 +0300 Subject: [PATCH 10/11] Do not create a readline interface in the interactive mode Creating the readline interface on Windows to listen for Ctrl+c caused the text "Stopping packager" to be printed twice. In the interactive mode stopping the packager is handled by the keypress listener set by the interactive mode, so the readline interface is not necessary. --- react-native-scripts/package.json | 1 - react-native-scripts/src/scripts/start.js | 2 +- react-native-scripts/src/util/packager.js | 15 +++++---------- react-native-scripts/yarn.lock | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/react-native-scripts/package.json b/react-native-scripts/package.json index 8f6e76f1..3ffc2b77 100644 --- a/react-native-scripts/package.json +++ b/react-native-scripts/package.json @@ -32,7 +32,6 @@ "inquirer": "^3.0.1", "match-require": "^2.0.0", "minimist": "^1.2.0", - "mute-stream": "^0.0.7", "path-exists": "^3.0.0", "progress": "^2.0.0", "qrcode-terminal": "^0.11.0", diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index a0827f07..efa67ac5 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -37,7 +37,7 @@ if (args.interactive && typeof stdin.setRawMode === 'function') { isInteractive = true; } -packager.run(onReady, options); +packager.run(onReady, options, isInteractive); function onReady() { log(chalk.green('Packager started!\n')); diff --git a/react-native-scripts/src/util/packager.js b/react-native-scripts/src/util/packager.js index f2731050..ac9bad2c 100644 --- a/react-native-scripts/src/util/packager.js +++ b/react-native-scripts/src/util/packager.js @@ -5,20 +5,15 @@ import { PackagerLogsStream, Project, ProjectSettings, ProjectUtils } from 'xdl' import ProgressBar from 'progress'; import bunyan from '@expo/bunyan'; import chalk from 'chalk'; -import MuteStream from 'mute-stream'; import log from './log'; -function installExitHooks(projectDir) { - if (process.platform === 'win32') { - const output = new MuteStream(); - output.pipe(process.stdout); - // Hide the command prompt and entered characters. - output.mute(); +function installExitHooks(projectDir, isInteractive) { + if (!isInteractive && process.platform === 'win32') { require('readline') .createInterface({ input: process.stdin, - output, + output: process.stdout, }) .on('SIGINT', () => { process.emit('SIGINT'); @@ -59,7 +54,7 @@ function shouldIgnoreMsg(msg) { msg.indexOf('Warning: PropTypes has been moved to a separate package') >= 0; } -function run(onReady: () => ?any, options: Object = {}) { +function run(onReady: () => ?any, options: Object = {}, isInteractive = false) { let packagerReady = false; let needsClear = false; let logBuffer = ''; @@ -184,7 +179,7 @@ function run(onReady: () => ?any, options: Object = {}) { type: 'raw', }); - installExitHooks(projectDir); + installExitHooks(projectDir, isInteractive); log.withTimestamp('Starting packager...'); Project.startAsync(projectDir, options).then( diff --git a/react-native-scripts/yarn.lock b/react-native-scripts/yarn.lock index 910a4645..f3c68091 100644 --- a/react-native-scripts/yarn.lock +++ b/react-native-scripts/yarn.lock @@ -2138,7 +2138,7 @@ ms@2.0.0, ms@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" -mute-stream@0.0.7, mute-stream@^0.0.7: +mute-stream@0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" From 6ab50e883640538faf9ec9192794ea4918575902 Mon Sep 17 00:00:00 2001 From: Ville Immonen Date: Fri, 28 Jul 2017 16:17:29 +0300 Subject: [PATCH 11/11] Fix bold text style bleeding outside the bold text part on Windows Work around the bold style not being closed on Windows by adding reset styles after each bold style. --- react-native-scripts/src/scripts/start.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/react-native-scripts/src/scripts/start.js b/react-native-scripts/src/scripts/start.js index efa67ac5..17acf4aa 100644 --- a/react-native-scripts/src/scripts/start.js +++ b/react-native-scripts/src/scripts/start.js @@ -73,8 +73,8 @@ function printUsage() { if (!isInteractive) { return; } - const { dim } = chalk; - const devMode = chalk.bold(dev ? 'development' : 'production'); + const { dim, bold } = chalk; + const devMode = dev ? 'development' : 'production'; const iosInfo = process.platform === 'win32' ? dim('.') : `${dim(`, or`)} i ${dim(`to open iOS emulator.`)}`; @@ -83,7 +83,7 @@ function printUsage() { ${dim(`\u203A Press`)} a ${dim(`to open Android device or emulator`)}${iosInfo} ${dim(`\u203A Press`)} q ${dim(`to display QR code.`)} ${dim(`\u203A Press`)} r ${dim(`to restart packager, or`)} R ${dim(`to restart packager and clear cache.`)} - ${dim(`\u203A Press`)} d ${dim(`to toggle development mode. (current mode: ${devMode})`)} + ${dim(`\u203A Press`)} d ${dim(`to toggle development mode. (current mode: ${bold(devMode)}${chalk.reset.dim(')')}`)} ` ); } @@ -140,7 +140,7 @@ async function handleKeypress(key) { dev = !dev; await ProjectSettings.setAsync(process.cwd(), { dev }); log( - `Packager now running in ${chalk.bold(dev ? 'development' : 'production')} mode. + `Packager now running in ${chalk.bold(dev ? 'development' : 'production')}${chalk.reset(` mode.`)} Please close and reopen the project in the Expo app for the change to take effect.`