diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index 234530c1041..cd21b6ac29c 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -349,25 +349,35 @@ function runOnAllDevices( } function startServerInNewWindow(port) { - const scriptFile = /^win/.test(process.platform) + // set up OS-specific filenames and commands + const isWindows = /^win/.test(process.platform); + const scriptFile = isWindows ? 'launchPackager.bat' : 'launchPackager.command'; + const packagerEnvFilename = isWindows + ? '.packager.bat' + : '.packager.env'; + const portExportContent = isWindows + ? `set RCT_METRO_PORT=${port}` + : `export RCT_METRO_PORT=${port}`; + + // set up the launchpackager.(command|bat) file const scriptsDir = path.resolve(__dirname, '..', '..', 'scripts'); const launchPackagerScript = path.resolve(scriptsDir, scriptFile); const procConfig = {cwd: scriptsDir}; const terminal = process.env.REACT_TERMINAL; - // setup the .packager.env file to ensure the packager starts on the right port + // set up the .packager.(env|bat) file to ensure the packager starts on the right port const packagerEnvFile = path.join( __dirname, '..', '..', 'scripts', - '.packager.env', + packagerEnvFilename ); - const content = `export RCT_METRO_PORT=${port}`; + // ensure we overwrite file by passing the 'w' flag - fs.writeFileSync(packagerEnvFile, content, {encoding: 'utf8', flag: 'w'}); + fs.writeFileSync(packagerEnvFile, portExportContent, {encoding: 'utf8', flag: 'w'}); if (process.platform === 'darwin') { if (terminal) { diff --git a/scripts/launchPackager.bat b/scripts/launchPackager.bat index 09f1de98737..b85ecc6822c 100644 --- a/scripts/launchPackager.bat +++ b/scripts/launchPackager.bat @@ -5,6 +5,7 @@ @echo off title Metro Bundler +call .packager.bat node "%~dp0..\local-cli\cli.js" start pause exit