react-native/local-cli/runAndroid/runAndroid.js

486 lines
13 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const adb = require('./adb');
const chalk = require('chalk');
const child_process = require('child_process');
const fs = require('fs');
const isPackagerRunning = require('../util/isPackagerRunning');
Make the CLI recognize CRNA projects Summary: 1. Make running `react-native run-ios` or `react-native run-android` inside a project created with Create React Native App run the corresponding react-native-scripts command instead of failing. **Before**: <img width="762" alt="screen shot 2017-07-21 at 16 55 32" src="https://user-images.githubusercontent.com/497214/28467425-86b309c8-6e38-11e7-8946-139bda927d93.png"><img width="762" alt="screen shot 2017-07-21 at 16 55 52" src="https://user-images.githubusercontent.com/497214/28467436-8df02482-6e38-11e7-8a03-3fa664944cac.png"> **After**: <img width="762" alt="screen shot 2017-07-21 at 16 52 15" src="https://user-images.githubusercontent.com/497214/28467522-e4bb6cae-6e38-11e7-97bb-9cfa9cb4dc67.png"> 2. Make running `react-native link` inside a CRNA project display a helpful error message. **Before**: <img width="762" alt="screen shot 2017-07-21 at 16 55 10" src="https://user-images.githubusercontent.com/497214/28467608-1d1781fa-6e39-11e7-9620-cc16c8b1b40f.png"> **After**: <img width="762" alt="screen shot 2017-07-21 at 16 53 10" src="https://user-images.githubusercontent.com/497214/28467637-2cd6ed1a-6e39-11e7-8947-6df69b3f321e.png"> Fixes #14828. * Run `react-native run-ios`, `react-native run-android` and `react-native link` in: * A CRNA project (screenshot above) * A traditional RN project (existing behaviour) * A folder that contains neither (existing behaviour) Closes https://github.com/facebook/react-native/pull/15139 Differential Revision: D5498914 Pulled By: hramos fbshipit-source-id: 94b6196e3451857bbaa45335a01643c89bed19a0
2017-08-03 18:55:40 +00:00
const findReactNativeScripts = require('../util/findReactNativeScripts');
const isString = require('lodash/isString');
const path = require('path');
const Promise = require('promise');
// Verifies this is an Android project
function checkAndroid(root) {
return fs.existsSync(path.join(root, 'android/gradlew'));
}
/**
* Starts the app on a connected Android emulator or device.
*/
function runAndroid(argv, config, args) {
if (!checkAndroid(args.root)) {
Make the CLI recognize CRNA projects Summary: 1. Make running `react-native run-ios` or `react-native run-android` inside a project created with Create React Native App run the corresponding react-native-scripts command instead of failing. **Before**: <img width="762" alt="screen shot 2017-07-21 at 16 55 32" src="https://user-images.githubusercontent.com/497214/28467425-86b309c8-6e38-11e7-8946-139bda927d93.png"><img width="762" alt="screen shot 2017-07-21 at 16 55 52" src="https://user-images.githubusercontent.com/497214/28467436-8df02482-6e38-11e7-8a03-3fa664944cac.png"> **After**: <img width="762" alt="screen shot 2017-07-21 at 16 52 15" src="https://user-images.githubusercontent.com/497214/28467522-e4bb6cae-6e38-11e7-97bb-9cfa9cb4dc67.png"> 2. Make running `react-native link` inside a CRNA project display a helpful error message. **Before**: <img width="762" alt="screen shot 2017-07-21 at 16 55 10" src="https://user-images.githubusercontent.com/497214/28467608-1d1781fa-6e39-11e7-9620-cc16c8b1b40f.png"> **After**: <img width="762" alt="screen shot 2017-07-21 at 16 53 10" src="https://user-images.githubusercontent.com/497214/28467637-2cd6ed1a-6e39-11e7-8947-6df69b3f321e.png"> Fixes #14828. * Run `react-native run-ios`, `react-native run-android` and `react-native link` in: * A CRNA project (screenshot above) * A traditional RN project (existing behaviour) * A folder that contains neither (existing behaviour) Closes https://github.com/facebook/react-native/pull/15139 Differential Revision: D5498914 Pulled By: hramos fbshipit-source-id: 94b6196e3451857bbaa45335a01643c89bed19a0
2017-08-03 18:55:40 +00:00
const reactNativeScriptsPath = findReactNativeScripts();
if (reactNativeScriptsPath) {
child_process.spawnSync(
reactNativeScriptsPath,
['android'].concat(process.argv.slice(1)),
{stdio: 'inherit'},
Make the CLI recognize CRNA projects Summary: 1. Make running `react-native run-ios` or `react-native run-android` inside a project created with Create React Native App run the corresponding react-native-scripts command instead of failing. **Before**: <img width="762" alt="screen shot 2017-07-21 at 16 55 32" src="https://user-images.githubusercontent.com/497214/28467425-86b309c8-6e38-11e7-8946-139bda927d93.png"><img width="762" alt="screen shot 2017-07-21 at 16 55 52" src="https://user-images.githubusercontent.com/497214/28467436-8df02482-6e38-11e7-8a03-3fa664944cac.png"> **After**: <img width="762" alt="screen shot 2017-07-21 at 16 52 15" src="https://user-images.githubusercontent.com/497214/28467522-e4bb6cae-6e38-11e7-97bb-9cfa9cb4dc67.png"> 2. Make running `react-native link` inside a CRNA project display a helpful error message. **Before**: <img width="762" alt="screen shot 2017-07-21 at 16 55 10" src="https://user-images.githubusercontent.com/497214/28467608-1d1781fa-6e39-11e7-9620-cc16c8b1b40f.png"> **After**: <img width="762" alt="screen shot 2017-07-21 at 16 53 10" src="https://user-images.githubusercontent.com/497214/28467637-2cd6ed1a-6e39-11e7-8947-6df69b3f321e.png"> Fixes #14828. * Run `react-native run-ios`, `react-native run-android` and `react-native link` in: * A CRNA project (screenshot above) * A traditional RN project (existing behaviour) * A folder that contains neither (existing behaviour) Closes https://github.com/facebook/react-native/pull/15139 Differential Revision: D5498914 Pulled By: hramos fbshipit-source-id: 94b6196e3451857bbaa45335a01643c89bed19a0
2017-08-03 18:55:40 +00:00
);
} else {
console.log(
chalk.red(
'Android project not found. Maybe run react-native android first?',
),
);
Make the CLI recognize CRNA projects Summary: 1. Make running `react-native run-ios` or `react-native run-android` inside a project created with Create React Native App run the corresponding react-native-scripts command instead of failing. **Before**: <img width="762" alt="screen shot 2017-07-21 at 16 55 32" src="https://user-images.githubusercontent.com/497214/28467425-86b309c8-6e38-11e7-8946-139bda927d93.png"><img width="762" alt="screen shot 2017-07-21 at 16 55 52" src="https://user-images.githubusercontent.com/497214/28467436-8df02482-6e38-11e7-8a03-3fa664944cac.png"> **After**: <img width="762" alt="screen shot 2017-07-21 at 16 52 15" src="https://user-images.githubusercontent.com/497214/28467522-e4bb6cae-6e38-11e7-97bb-9cfa9cb4dc67.png"> 2. Make running `react-native link` inside a CRNA project display a helpful error message. **Before**: <img width="762" alt="screen shot 2017-07-21 at 16 55 10" src="https://user-images.githubusercontent.com/497214/28467608-1d1781fa-6e39-11e7-9620-cc16c8b1b40f.png"> **After**: <img width="762" alt="screen shot 2017-07-21 at 16 53 10" src="https://user-images.githubusercontent.com/497214/28467637-2cd6ed1a-6e39-11e7-8947-6df69b3f321e.png"> Fixes #14828. * Run `react-native run-ios`, `react-native run-android` and `react-native link` in: * A CRNA project (screenshot above) * A traditional RN project (existing behaviour) * A folder that contains neither (existing behaviour) Closes https://github.com/facebook/react-native/pull/15139 Differential Revision: D5498914 Pulled By: hramos fbshipit-source-id: 94b6196e3451857bbaa45335a01643c89bed19a0
2017-08-03 18:55:40 +00:00
}
return;
}
if (!args.packager) {
return buildAndRun(args);
}
return isPackagerRunning(args.port).then(result => {
if (result === 'running') {
console.log(chalk.bold('JS server already running.'));
} else if (result === 'unrecognized') {
console.warn(
chalk.yellow('JS server not recognized, continuing with build...'),
);
} else {
// result == 'not_running'
console.log(chalk.bold('Starting JS server...'));
startServerInNewWindow(args.port, args.terminal);
}
return buildAndRun(args);
});
}
function getAdbPath() {
return process.env.ANDROID_HOME
? process.env.ANDROID_HOME + '/platform-tools/adb'
: 'adb';
}
// Runs ADB reverse tcp:8081 tcp:8081 to allow loading the jsbundle from the packager
function tryRunAdbReverse(packagerPort, device) {
try {
const adbPath = getAdbPath();
const adbArgs = ['reverse', `tcp:${packagerPort}`, `tcp:${packagerPort}`];
// If a device is specified then tell adb to use it
if (device) {
adbArgs.unshift('-s', device);
}
console.log(chalk.bold(`Running ${adbPath} ${adbArgs.join(' ')}`));
child_process.execFileSync(adbPath, adbArgs, {
stdio: [process.stdin, process.stdout, process.stderr],
});
} catch (e) {
console.log(chalk.yellow(`Could not run adb reverse: ${e.message}`));
}
}
function getPackageNameWithSuffix(appId, appIdSuffix, packageName) {
if (appId) {
return appId;
} else if (appIdSuffix) {
return packageName + '.' + appIdSuffix;
}
return packageName;
}
// Builds the app and runs it on a connected emulator / device.
function buildAndRun(args) {
process.chdir(path.join(args.root, 'android'));
const cmd = process.platform.startsWith('win') ? 'gradlew.bat' : './gradlew';
const packageName = fs
.readFileSync(`${args.appFolder}/src/main/AndroidManifest.xml`, 'utf8')
.match(/package="(.+?)"/)[1];
const packageNameWithSuffix = getPackageNameWithSuffix(
args.appId,
args.appIdSuffix,
packageName,
);
const adbPath = getAdbPath();
if (args.deviceId) {
if (isString(args.deviceId)) {
runOnSpecificDevice(
args,
cmd,
packageNameWithSuffix,
packageName,
adbPath,
);
} else {
console.log(chalk.red('Argument missing for parameter --deviceId'));
}
} else {
runOnAllDevices(args, cmd, packageNameWithSuffix, packageName, adbPath);
}
}
function runOnSpecificDevice(
args,
gradlew,
packageNameWithSuffix,
packageName,
adbPath,
) {
let devices = adb.getDevices();
if (devices && devices.length > 0) {
if (devices.indexOf(args.deviceId) !== -1) {
buildApk(gradlew);
installAndLaunchOnDevice(
args,
args.deviceId,
packageNameWithSuffix,
packageName,
adbPath,
);
} else {
console.log(
'Could not find device with the id: "' + args.deviceId + '".',
);
console.log('Choose one of the following:');
console.log(devices);
}
} else {
console.log('No Android devices connected.');
}
}
function buildApk(gradlew) {
try {
console.log(chalk.bold('Building the app...'));
// using '-x lint' in order to ignore linting errors while building the apk
child_process.execFileSync(gradlew, ['build', '-x', 'lint'], {
stdio: [process.stdin, process.stdout, process.stderr],
});
} catch (e) {
console.log(
chalk.red('Could not build the app, read the error above for details.\n'),
);
}
}
function tryInstallAppOnDevice(args, device) {
try {
const pathToApk = `${args.appFolder}/build/outputs/apk/${
args.appFolder
}-debug.apk`;
const adbPath = getAdbPath();
const adbArgs = ['-s', device, 'install', pathToApk];
console.log(
chalk.bold(
`Installing the app on the device (cd android && adb -s ${device} install ${pathToApk}`,
),
);
child_process.execFileSync(adbPath, adbArgs, {
stdio: [process.stdin, process.stdout, process.stderr],
});
} catch (e) {
console.log(e.message);
console.log(
chalk.red(
'Could not install the app on the device, read the error above for details.\n',
),
);
}
}
function tryLaunchAppOnDevice(
device,
packageNameWithSuffix,
packageName,
adbPath,
mainActivity,
) {
try {
const adbArgs = [
'-s',
device,
'shell',
'am',
'start',
'-n',
packageNameWithSuffix + '/' + packageName + '.' + mainActivity,
];
console.log(
chalk.bold(
`Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...`,
),
);
child_process.spawnSync(adbPath, adbArgs, {stdio: 'inherit'});
} catch (e) {
console.log(
chalk.red('adb invocation failed. Do you have adb in your PATH?'),
);
}
}
function installAndLaunchOnDevice(
args,
selectedDevice,
packageNameWithSuffix,
packageName,
adbPath,
) {
tryRunAdbReverse(args.port, selectedDevice);
tryInstallAppOnDevice(args, selectedDevice);
tryLaunchAppOnDevice(
selectedDevice,
packageNameWithSuffix,
packageName,
adbPath,
args.mainActivity,
);
}
function runOnAllDevices(
args,
cmd,
packageNameWithSuffix,
packageName,
adbPath,
) {
try {
const gradleArgs = [];
if (args.variant) {
gradleArgs.push(
'install' + args.variant[0].toUpperCase() + args.variant.slice(1),
);
} else if (args.flavor) {
console.warn(
chalk.yellow('--flavor has been deprecated. Use --variant instead'),
);
gradleArgs.push(
'install' + args.flavor[0].toUpperCase() + args.flavor.slice(1),
);
} else {
gradleArgs.push('installDebug');
}
if (args.installDebug) {
gradleArgs.push(args.installDebug);
}
console.log(
chalk.bold(
`Building and installing the app on the device (cd android && ${cmd} ${gradleArgs.join(
' ',
)})...`,
),
);
child_process.execFileSync(cmd, gradleArgs, {
stdio: [process.stdin, process.stdout, process.stderr],
});
} catch (e) {
console.log(
chalk.red(
'Could not install the app on the device, read the error above for details.\n' +
'Make sure you have an Android emulator running or a device connected and have\n' +
'set up your Android development environment:\n' +
'https://facebook.github.io/react-native/docs/getting-started.html',
),
);
// stderr is automatically piped from the gradle process, so the user
// should see the error already, there is no need to do
// `console.log(e.stderr)`
return Promise.reject();
}
const devices = adb.getDevices();
if (devices && devices.length > 0) {
devices.forEach(device => {
tryRunAdbReverse(args.port, device);
tryLaunchAppOnDevice(
device,
packageNameWithSuffix,
packageName,
adbPath,
args.mainActivity,
);
});
} else {
try {
// If we cannot execute based on adb devices output, fall back to
// shell am start
const fallbackAdbArgs = [
'shell',
'am',
'start',
'-n',
packageNameWithSuffix + '/' + packageName + '.MainActivity',
];
console.log(
chalk.bold(
`Starting the app (${adbPath} ${fallbackAdbArgs.join(' ')}...`,
),
);
child_process.spawnSync(adbPath, fallbackAdbArgs, {stdio: 'inherit'});
} catch (e) {
console.log(
chalk.red('adb invocation failed. Do you have adb in your PATH?'),
);
// stderr is automatically piped from the gradle process, so the user
// should see the error already, there is no need to do
// `console.log(e.stderr)`
return Promise.reject();
}
}
}
function startServerInNewWindow(port, terminal = process.env.REACT_TERMINAL) {
Fix for 17497 (#17498) Summary: Changed runAndroid.js to generate .packager.bat and launchPackager.ba…t to call it to setup the environment variable <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> Trying to use react-native on a Windows box with a virus killer that runs on port 8081... (Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!) 1) Start an android emulator 2) on a react-native project (with the changes), run `react-native run-android --port 9988`. 3) When the packager starts, verify that it states the correct port in the terminal window. 4) verify that the application correctly starts in the Emulator. (If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/react-native-website, and link to your PR here.) <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [INTERNAL] [BUGFIX] [./scripts] - Fixed runAndroid to enable the use of a package on port <> 8081 for Windows. Closes https://github.com/facebook/react-native/pull/17498 Differential Revision: D8682067 Pulled By: hramos fbshipit-source-id: 6604b827077b3a6a2da9914c1fd36dad6ef30e43
2018-06-28 21:02:34 +00:00
// 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';
Fix for 17497 (#17498) Summary: Changed runAndroid.js to generate .packager.bat and launchPackager.ba…t to call it to setup the environment variable <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> Trying to use react-native on a Windows box with a virus killer that runs on port 8081... (Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!) 1) Start an android emulator 2) on a react-native project (with the changes), run `react-native run-android --port 9988`. 3) When the packager starts, verify that it states the correct port in the terminal window. 4) verify that the application correctly starts in the Emulator. (If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/react-native-website, and link to your PR here.) <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [INTERNAL] [BUGFIX] [./scripts] - Fixed runAndroid to enable the use of a package on port <> 8081 for Windows. Closes https://github.com/facebook/react-native/pull/17498 Differential Revision: D8682067 Pulled By: hramos fbshipit-source-id: 6604b827077b3a6a2da9914c1fd36dad6ef30e43
2018-06-28 21:02:34 +00:00
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};
Fix for 17497 (#17498) Summary: Changed runAndroid.js to generate .packager.bat and launchPackager.ba…t to call it to setup the environment variable <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> Trying to use react-native on a Windows box with a virus killer that runs on port 8081... (Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!) 1) Start an android emulator 2) on a react-native project (with the changes), run `react-native run-android --port 9988`. 3) When the packager starts, verify that it states the correct port in the terminal window. 4) verify that the application correctly starts in the Emulator. (If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/react-native-website, and link to your PR here.) <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [INTERNAL] [BUGFIX] [./scripts] - Fixed runAndroid to enable the use of a package on port <> 8081 for Windows. Closes https://github.com/facebook/react-native/pull/17498 Differential Revision: D8682067 Pulled By: hramos fbshipit-source-id: 6604b827077b3a6a2da9914c1fd36dad6ef30e43
2018-06-28 21:02:34 +00:00
// set up the .packager.(env|bat) file to ensure the packager starts on the right port
const packagerEnvFile = path.join(
__dirname,
'..',
'..',
'scripts',
packagerEnvFilename,
);
// ensure we overwrite file by passing the 'w' flag
fs.writeFileSync(packagerEnvFile, portExportContent, {
encoding: 'utf8',
flag: 'w',
});
if (process.platform === 'darwin') {
Allow packager to be opened in specific terminal on Linux and Mac OS X Summary: Thanks for submitting a PR! Please read these instructions carefully: - [ ] Explain the **motivation** for making this change. - [ ] Provide a **test plan** demonstrating that the code is solid. - [ ] Match the **code formatting** of the rest of the codebase. - [ ] Target the `master` branch, NOT a "stable" branch. What existing problem does the pull request solve? Currently, it is not possible to spawn the packager in a specific terminal on Linux and Mac OS X. For example, after applying this patch, starting the packager in a new xfce terminal on Linux can be done using: react-native run-android --terminal /usr/bin/xfce4-terminal When the command is ran a second time, and the terminal is still running, the command will not spawn a new terminal for the packager. The option 'open' is renamed to 'terminal' for consistency. Note that the option 'open' was never exposed to the CLI though. A good test plan has the exact commands you ran and their output, provides screenshots or videos if the pull request changes UI or updates the website. See [What is a Test Plan?][1] to learn more. If you have added code that should be tested, add tests. See command above. Sign the [CLA][2], if you haven't already. Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. Make sure all **tests pass** on both [Travis][3] and [Circle CI][4]. PRs that break tests are unlikely to be merged. For more info, see the ["Pull Requests"][5] section of our "Contributing" guidelines. [1]: https://medium.com/martinkonicek/what-is-a-test-plan-8bfc840ec171#.y9lcuqqi9 [2]: https://code.facebook.com/cla [3]: https://travis-ci.org/facebook/react-native [4]: http://circleci.com/gh/facebook/react-native [5]: https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests Closes https://github.com/facebook/react-native/pull/13065 Differential Revision: D5700713 Pulled By: hramos fbshipit-source-id: d9729a484c0c0e8f95edabe4309ed7800c9a9c14
2017-08-24 21:01:50 +00:00
if (terminal) {
return child_process.spawnSync(
'open',
['-a', terminal, launchPackagerScript],
procConfig,
);
}
return child_process.spawnSync('open', [launchPackagerScript], procConfig);
} else if (process.platform === 'linux') {
if (terminal) {
procConfig.detached = true;
return child_process.spawn(
terminal,
['-e', 'sh ' + launchPackagerScript],
procConfig,
);
}
// By default, the child shell process will be attached to the parent
procConfig.detached = false;
return child_process.spawn('sh', [launchPackagerScript], procConfig);
} else if (/^win/.test(process.platform)) {
procConfig.detached = true;
procConfig.stdio = 'ignore';
return child_process.spawn(
'cmd.exe',
['/C', launchPackagerScript],
procConfig,
);
} else {
console.log(
chalk.red(
`Cannot start the packager. Unknown platform ${process.platform}`,
),
);
}
}
module.exports = {
name: 'run-android',
description:
'builds your app and starts it on a connected Android emulator or device',
func: runAndroid,
options: [
{
command: '--install-debug',
},
{
command: '--root [string]',
description:
'Override the root directory for the android build (which contains the android directory)',
default: '',
},
{
command: '--flavor [string]',
description: '--flavor has been deprecated. Use --variant instead',
},
{
command: '--variant [string]',
},
{
command: '--appFolder [string]',
description:
'Specify a different application folder name for the android source.',
default: 'app',
},
{
command: '--appId [string]',
description: 'Specify an applicationId to launch after build.',
default: '',
},
{
command: '--appIdSuffix [string]',
description: 'Specify an applicationIdSuffix to launch after build.',
default: '',
},
{
command: '--main-activity [string]',
description: 'Name of the activity to start',
default: 'MainActivity',
},
{
command: '--deviceId [string]',
description:
'builds your app and starts it on a specific device/simulator with the ' +
'given device id (listed by running "adb devices" on the command line).',
},
{
command: '--no-packager',
description: 'Do not launch packager while building',
},
{
command: '--port [number]',
default: process.env.RCT_METRO_PORT || 8081,
parse: (val: string) => Number(val),
},
{
command: '--terminal [string]',
description:
'Launches the Metro Bundler in a new window using the specified terminal path.',
default: '',
},
],
};