Skip to content

Commit

Permalink
Launch the packager with react-native run-android on Windows
Browse files Browse the repository at this point in the history
Summary:
Adds support for launching the packager in a new window on Windows.

**Test plan (required)**

Tested that the packager is launched in a completely independent process. This means that exiting the `react-native run-android` command should not close the packager window and it should exit properly when completed even if the packager window is still opened. Pretty much made sure it behaves exactly like on mac.

Also tested that an error in the packager will not close the window immediately to show the error stack trace.
Closes facebook#7129

Differential Revision: D3240628

Pulled By: mkonicek

fb-gh-sync-id: 007582250536481d2b2376f9a201f8f415fc1080
fbshipit-source-id: 007582250536481d2b2376f9a201f8f415fc1080
  • Loading branch information
janicduplessis authored and Facebook Github Bot 0 committed Apr 29, 2016
1 parent 3a5457c commit 891b87e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 8 additions & 8 deletions local-cli/runAndroid/runAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ function buildAndRun(args, reject) {
function startServerInNewWindow() {
var yargV = require('yargs').argv;

const scriptFile = /^win/.test(process.platform) ?
'launchPackager.bat' :
'launchPackager.command';

const launchPackagerScript = path.resolve(
__dirname, '..', '..', 'packager', 'launchPackager.command'
__dirname, '..', '..', 'packager', scriptFile
);

if (process.platform === 'darwin') {
Expand All @@ -176,13 +180,9 @@ function startServerInNewWindow() {
return child_process.spawn('sh', [launchPackagerScript],{detached: true});

} else if (/^win/.test(process.platform)) {
console.log(chalk.yellow('Starting the packager in a new window ' +
'is not supported on Windows yet.\nPlease start it manually using ' +
'\'react-native start\'.'));
console.log('We believe the best Windows ' +
'support will come from a community of people\nusing React Native on ' +
'Windows on a daily basis.\n' +
'Would you be up for sending a pull request?');
return child_process.spawn(
'cmd.exe', ['/C', 'start', launchPackagerScript], {detached: true, stdio: 'ignore'}
);
} else {
console.log(chalk.red(`Cannot start the packager. Unknown platform ${process.platform}`));
}
Expand Down
12 changes: 12 additions & 0 deletions packager/launchPackager.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
:: Copyright (c) 2015-present, Facebook, Inc.
:: All rights reserved.
::
:: This source code is licensed under the BSD-style license found in the
:: LICENSE file in the root directory of this source tree. An additional grant
:: of patent rights can be found in the PATENTS file in the same directory.

@echo off
title React Packager
node "%~dp0..\local-cli\cli.js" start
pause
exit

0 comments on commit 891b87e

Please sign in to comment.