2015-10-20 18:46:37 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-11 19:43:49 +00:00
|
|
|
*
|
|
|
|
* @format
|
2015-10-20 18:46:37 +00:00
|
|
|
*/
|
2018-05-11 19:43:49 +00:00
|
|
|
|
2015-10-20 18:46:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-01-02 19:06:37 +00:00
|
|
|
const adb = require('./adb');
|
2015-10-20 18:46:37 +00:00
|
|
|
const chalk = require('chalk');
|
|
|
|
const child_process = require('child_process');
|
|
|
|
const fs = require('fs');
|
2016-12-16 03:38:36 +00:00
|
|
|
const isPackagerRunning = require('../util/isPackagerRunning');
|
2017-08-03 18:55:40 +00:00
|
|
|
const findReactNativeScripts = require('../util/findReactNativeScripts');
|
2017-01-02 19:06:37 +00:00
|
|
|
const isString = require('lodash/isString');
|
|
|
|
const path = require('path');
|
2016-12-16 03:38:36 +00:00
|
|
|
const Promise = require('promise');
|
2015-10-20 18:46:37 +00:00
|
|
|
|
2016-08-18 00:33:29 +00:00
|
|
|
// Verifies this is an Android project
|
|
|
|
function checkAndroid(root) {
|
|
|
|
return fs.existsSync(path.join(root, 'android/gradlew'));
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:46:37 +00:00
|
|
|
/**
|
2015-10-21 16:37:44 +00:00
|
|
|
* Starts the app on a connected Android emulator or device.
|
2015-10-20 18:46:37 +00:00
|
|
|
*/
|
2016-07-30 15:59:16 +00:00
|
|
|
function runAndroid(argv, config, args) {
|
|
|
|
if (!checkAndroid(args.root)) {
|
2017-08-03 18:55:40 +00:00
|
|
|
const reactNativeScriptsPath = findReactNativeScripts();
|
|
|
|
if (reactNativeScriptsPath) {
|
|
|
|
child_process.spawnSync(
|
|
|
|
reactNativeScriptsPath,
|
|
|
|
['android'].concat(process.argv.slice(1)),
|
2018-05-11 19:43:49 +00:00
|
|
|
{stdio: 'inherit'},
|
2017-08-03 18:55:40 +00:00
|
|
|
);
|
|
|
|
} else {
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(
|
|
|
|
chalk.red(
|
|
|
|
'Android project not found. Maybe run react-native android first?',
|
|
|
|
),
|
|
|
|
);
|
2017-08-03 18:55:40 +00:00
|
|
|
}
|
2015-10-20 18:46:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-09 11:25:27 +00:00
|
|
|
if (!args.packager) {
|
|
|
|
return buildAndRun(args);
|
|
|
|
}
|
|
|
|
|
2018-01-05 04:02:37 +00:00
|
|
|
return isPackagerRunning(args.port).then(result => {
|
2015-10-20 18:46:37 +00:00
|
|
|
if (result === 'running') {
|
2016-07-30 15:59:16 +00:00
|
|
|
console.log(chalk.bold('JS server already running.'));
|
2015-10-20 18:46:37 +00:00
|
|
|
} else if (result === 'unrecognized') {
|
2018-05-11 19:43:49 +00:00
|
|
|
console.warn(
|
|
|
|
chalk.yellow('JS server not recognized, continuing with build...'),
|
|
|
|
);
|
2015-10-20 18:46:37 +00:00
|
|
|
} else {
|
|
|
|
// result == 'not_running'
|
2016-07-30 15:59:16 +00:00
|
|
|
console.log(chalk.bold('Starting JS server...'));
|
2018-01-05 04:02:37 +00:00
|
|
|
startServerInNewWindow(args.port);
|
2015-10-20 18:46:37 +00:00
|
|
|
}
|
2016-07-30 15:59:16 +00:00
|
|
|
return buildAndRun(args);
|
|
|
|
});
|
2015-10-20 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 13:43:12 +00:00
|
|
|
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
|
2017-08-08 13:41:14 +00:00
|
|
|
function tryRunAdbReverse(packagerPort, device) {
|
2016-06-23 13:43:12 +00:00
|
|
|
try {
|
|
|
|
const adbPath = getAdbPath();
|
2017-08-08 13:41:14 +00:00
|
|
|
const adbArgs = ['reverse', `tcp:${packagerPort}`, `tcp:${packagerPort}`];
|
2016-06-23 13:43:12 +00:00
|
|
|
|
2016-08-16 07:44:32 +00:00
|
|
|
// If a device is specified then tell adb to use it
|
|
|
|
if (device) {
|
|
|
|
adbArgs.unshift('-s', device);
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(chalk.bold(`Running ${adbPath} ${adbArgs.join(' ')}`));
|
2016-06-23 13:43:12 +00:00
|
|
|
|
|
|
|
child_process.execFileSync(adbPath, adbArgs, {
|
|
|
|
stdio: [process.stdin, process.stdout, process.stderr],
|
|
|
|
});
|
2016-08-16 07:44:32 +00:00
|
|
|
} catch (e) {
|
2017-01-02 19:06:37 +00:00
|
|
|
console.log(chalk.yellow(`Could not run adb reverse: ${e.message}`));
|
2016-06-23 13:43:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 07:02:58 +00:00
|
|
|
function getPackageNameWithSuffix(appId, appIdSuffix, packageName) {
|
|
|
|
if (appId) {
|
|
|
|
return appId;
|
|
|
|
} else if (appIdSuffix) {
|
|
|
|
return packageName + '.' + appIdSuffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
return packageName;
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:46:37 +00:00
|
|
|
// Builds the app and runs it on a connected emulator / device.
|
2016-07-30 15:59:16 +00:00
|
|
|
function buildAndRun(args) {
|
2016-12-16 03:38:36 +00:00
|
|
|
process.chdir(path.join(args.root, 'android'));
|
2018-05-11 19:43:49 +00:00
|
|
|
const cmd = process.platform.startsWith('win') ? 'gradlew.bat' : './gradlew';
|
2016-12-16 03:38:36 +00:00
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
const packageName = fs
|
|
|
|
.readFileSync(`${args.appFolder}/src/main/AndroidManifest.xml`, 'utf8')
|
|
|
|
.match(/package="(.+?)"/)[1];
|
2016-12-16 03:38:36 +00:00
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
const packageNameWithSuffix = getPackageNameWithSuffix(
|
|
|
|
args.appId,
|
|
|
|
args.appIdSuffix,
|
|
|
|
packageName,
|
|
|
|
);
|
2017-04-04 23:37:44 +00:00
|
|
|
|
2016-12-16 03:38:36 +00:00
|
|
|
const adbPath = getAdbPath();
|
|
|
|
if (args.deviceId) {
|
2017-01-02 19:06:37 +00:00
|
|
|
if (isString(args.deviceId)) {
|
2018-05-11 19:43:49 +00:00
|
|
|
runOnSpecificDevice(
|
|
|
|
args,
|
|
|
|
cmd,
|
|
|
|
packageNameWithSuffix,
|
|
|
|
packageName,
|
|
|
|
adbPath,
|
|
|
|
);
|
2017-01-02 19:06:37 +00:00
|
|
|
} else {
|
|
|
|
console.log(chalk.red('Argument missing for parameter --deviceId'));
|
|
|
|
}
|
2016-12-16 03:38:36 +00:00
|
|
|
} else {
|
2017-04-04 23:37:44 +00:00
|
|
|
runOnAllDevices(args, cmd, packageNameWithSuffix, packageName, adbPath);
|
2016-12-16 03:38:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
function runOnSpecificDevice(
|
|
|
|
args,
|
|
|
|
gradlew,
|
|
|
|
packageNameWithSuffix,
|
|
|
|
packageName,
|
|
|
|
adbPath,
|
|
|
|
) {
|
2016-12-16 03:38:36 +00:00
|
|
|
let devices = adb.getDevices();
|
|
|
|
if (devices && devices.length > 0) {
|
|
|
|
if (devices.indexOf(args.deviceId) !== -1) {
|
|
|
|
buildApk(gradlew);
|
2018-05-11 19:43:49 +00:00
|
|
|
installAndLaunchOnDevice(
|
|
|
|
args,
|
|
|
|
args.deviceId,
|
|
|
|
packageNameWithSuffix,
|
|
|
|
packageName,
|
|
|
|
adbPath,
|
|
|
|
);
|
2016-12-16 03:38:36 +00:00
|
|
|
} else {
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(
|
|
|
|
'Could not find device with the id: "' + args.deviceId + '".',
|
|
|
|
);
|
2016-12-16 03:38:36 +00:00
|
|
|
console.log('Choose one of the following:');
|
|
|
|
console.log(devices);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log('No Android devices connected.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildApk(gradlew) {
|
2015-10-20 18:46:37 +00:00
|
|
|
try {
|
2017-01-02 19:06:37 +00:00
|
|
|
console.log(chalk.bold('Building the app...'));
|
2016-06-23 13:43:12 +00:00
|
|
|
|
2016-12-16 03:38:36 +00:00
|
|
|
// 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) {
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(
|
|
|
|
chalk.red('Could not build the app, read the error above for details.\n'),
|
|
|
|
);
|
2016-12-16 03:38:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function tryInstallAppOnDevice(args, device) {
|
|
|
|
try {
|
2018-05-11 19:43:49 +00:00
|
|
|
const pathToApk = `${args.appFolder}/build/outputs/apk/${
|
|
|
|
args.appFolder
|
|
|
|
}-debug.apk`;
|
2016-12-16 03:38:36 +00:00
|
|
|
const adbPath = getAdbPath();
|
|
|
|
const adbArgs = ['-s', device, 'install', pathToApk];
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(
|
|
|
|
chalk.bold(
|
|
|
|
`Installing the app on the device (cd android && adb -s ${device} install ${pathToApk}`,
|
|
|
|
),
|
|
|
|
);
|
2016-12-16 03:38:36 +00:00
|
|
|
child_process.execFileSync(adbPath, adbArgs, {
|
|
|
|
stdio: [process.stdin, process.stdout, process.stderr],
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e.message);
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(
|
|
|
|
chalk.red(
|
|
|
|
'Could not install the app on the device, read the error above for details.\n',
|
|
|
|
),
|
|
|
|
);
|
2016-12-16 03:38:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
function tryLaunchAppOnDevice(
|
|
|
|
device,
|
|
|
|
packageNameWithSuffix,
|
|
|
|
packageName,
|
|
|
|
adbPath,
|
|
|
|
mainActivity,
|
|
|
|
) {
|
2016-12-16 03:38:36 +00:00
|
|
|
try {
|
2018-05-11 19:43:49 +00:00
|
|
|
const adbArgs = [
|
|
|
|
'-s',
|
|
|
|
device,
|
|
|
|
'shell',
|
|
|
|
'am',
|
|
|
|
'start',
|
|
|
|
'-n',
|
|
|
|
packageNameWithSuffix + '/' + packageName + '.' + mainActivity,
|
|
|
|
];
|
|
|
|
console.log(
|
|
|
|
chalk.bold(
|
|
|
|
`Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...`,
|
|
|
|
),
|
|
|
|
);
|
2016-12-16 03:38:36 +00:00
|
|
|
child_process.spawnSync(adbPath, adbArgs, {stdio: 'inherit'});
|
|
|
|
} catch (e) {
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(
|
|
|
|
chalk.red('adb invocation failed. Do you have adb in your PATH?'),
|
|
|
|
);
|
2016-12-16 03:38:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
function installAndLaunchOnDevice(
|
|
|
|
args,
|
|
|
|
selectedDevice,
|
|
|
|
packageNameWithSuffix,
|
|
|
|
packageName,
|
|
|
|
adbPath,
|
|
|
|
) {
|
2017-08-08 13:41:14 +00:00
|
|
|
tryRunAdbReverse(args.port, selectedDevice);
|
2016-12-16 03:38:36 +00:00
|
|
|
tryInstallAppOnDevice(args, selectedDevice);
|
2018-05-11 19:43:49 +00:00
|
|
|
tryLaunchAppOnDevice(
|
|
|
|
selectedDevice,
|
|
|
|
packageNameWithSuffix,
|
|
|
|
packageName,
|
|
|
|
adbPath,
|
|
|
|
args.mainActivity,
|
|
|
|
);
|
2016-12-16 03:38:36 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
function runOnAllDevices(
|
|
|
|
args,
|
|
|
|
cmd,
|
|
|
|
packageNameWithSuffix,
|
|
|
|
packageName,
|
|
|
|
adbPath,
|
|
|
|
) {
|
2016-12-16 03:38:36 +00:00
|
|
|
try {
|
2016-03-05 04:26:31 +00:00
|
|
|
const gradleArgs = [];
|
2016-07-30 15:59:16 +00:00
|
|
|
if (args.variant) {
|
2018-05-11 19:43:49 +00:00
|
|
|
gradleArgs.push(
|
|
|
|
'install' + args.variant[0].toUpperCase() + args.variant.slice(1),
|
2016-07-30 15:59:16 +00:00
|
|
|
);
|
|
|
|
} else if (args.flavor) {
|
2018-05-11 19:43:49 +00:00
|
|
|
console.warn(
|
|
|
|
chalk.yellow('--flavor has been deprecated. Use --variant instead'),
|
|
|
|
);
|
|
|
|
gradleArgs.push(
|
|
|
|
'install' + args.flavor[0].toUpperCase() + args.flavor.slice(1),
|
2016-07-30 15:59:16 +00:00
|
|
|
);
|
2016-03-05 04:26:31 +00:00
|
|
|
} else {
|
2016-12-16 03:38:36 +00:00
|
|
|
gradleArgs.push('installDebug');
|
2016-03-05 04:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 03:38:36 +00:00
|
|
|
if (args.installDebug) {
|
|
|
|
gradleArgs.push(args.installDebug);
|
2015-10-20 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(
|
|
|
|
chalk.bold(
|
|
|
|
`Building and installing the app on the device (cd android && ${cmd} ${gradleArgs.join(
|
|
|
|
' ',
|
|
|
|
)})...`,
|
|
|
|
),
|
|
|
|
);
|
2015-10-20 18:46:37 +00:00
|
|
|
|
|
|
|
child_process.execFileSync(cmd, gradleArgs, {
|
|
|
|
stdio: [process.stdin, process.stdout, process.stderr],
|
|
|
|
});
|
|
|
|
} catch (e) {
|
2018-05-11 19:43:49 +00:00
|
|
|
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',
|
|
|
|
),
|
|
|
|
);
|
2015-10-20 18:46:37 +00:00
|
|
|
// 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)`
|
2016-07-30 15:59:16 +00:00
|
|
|
return Promise.reject();
|
2015-10-20 18:46:37 +00:00
|
|
|
}
|
2018-05-11 19:43:49 +00:00
|
|
|
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();
|
2016-03-08 20:07:59 +00:00
|
|
|
}
|
2018-05-11 19:43:49 +00:00
|
|
|
}
|
2015-10-20 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 04:02:37 +00:00
|
|
|
function startServerInNewWindow(port) {
|
2018-05-11 19:43:49 +00:00
|
|
|
const scriptFile = /^win/.test(process.platform)
|
|
|
|
? 'launchPackager.bat'
|
|
|
|
: 'launchPackager.command';
|
2017-05-23 23:05:52 +00:00
|
|
|
const scriptsDir = path.resolve(__dirname, '..', '..', 'scripts');
|
|
|
|
const launchPackagerScript = path.resolve(scriptsDir, scriptFile);
|
|
|
|
const procConfig = {cwd: scriptsDir};
|
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
|
|
|
const terminal = process.env.REACT_TERMINAL;
|
2015-10-20 18:46:37 +00:00
|
|
|
|
2018-01-05 04:02:37 +00:00
|
|
|
// setup the .packager.env file to ensure the packager starts on the right port
|
2018-05-11 19:43:49 +00:00
|
|
|
const packagerEnvFile = path.join(
|
|
|
|
__dirname,
|
|
|
|
'..',
|
|
|
|
'..',
|
|
|
|
'scripts',
|
|
|
|
'.packager.env',
|
|
|
|
);
|
2018-01-05 04:02:37 +00:00
|
|
|
const content = `export RCT_METRO_PORT=${port}`;
|
|
|
|
// ensure we overwrite file by passing the 'w' flag
|
|
|
|
fs.writeFileSync(packagerEnvFile, content, {encoding: 'utf8', flag: 'w'});
|
|
|
|
|
2015-10-20 18:46:37 +00:00
|
|
|
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) {
|
2018-05-11 19:43:49 +00:00
|
|
|
return child_process.spawnSync(
|
|
|
|
'open',
|
|
|
|
['-a', terminal, launchPackagerScript],
|
|
|
|
procConfig,
|
|
|
|
);
|
2016-03-05 05:54:47 +00:00
|
|
|
}
|
2016-05-04 09:44:42 +00:00
|
|
|
return child_process.spawnSync('open', [launchPackagerScript], procConfig);
|
2015-10-20 18:46:37 +00:00
|
|
|
} else if (process.platform === 'linux') {
|
2016-05-04 09:44:42 +00:00
|
|
|
procConfig.detached = true;
|
2018-05-11 19:43:49 +00:00
|
|
|
if (terminal) {
|
|
|
|
return child_process.spawn(
|
|
|
|
terminal,
|
|
|
|
['-e', 'sh ' + launchPackagerScript],
|
|
|
|
procConfig,
|
|
|
|
);
|
2016-03-05 05:54:47 +00:00
|
|
|
}
|
2016-05-04 09:44:42 +00:00
|
|
|
return child_process.spawn('sh', [launchPackagerScript], procConfig);
|
2015-10-22 14:08:51 +00:00
|
|
|
} else if (/^win/.test(process.platform)) {
|
2016-05-04 09:44:42 +00:00
|
|
|
procConfig.detached = true;
|
|
|
|
procConfig.stdio = 'ignore';
|
2018-05-11 19:43:49 +00:00
|
|
|
return child_process.spawn(
|
|
|
|
'cmd.exe',
|
|
|
|
['/C', launchPackagerScript],
|
|
|
|
procConfig,
|
|
|
|
);
|
2015-10-20 18:46:37 +00:00
|
|
|
} else {
|
2018-05-11 19:43:49 +00:00
|
|
|
console.log(
|
|
|
|
chalk.red(
|
|
|
|
`Cannot start the packager. Unknown platform ${process.platform}`,
|
|
|
|
),
|
|
|
|
);
|
2015-10-20 18:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
module.exports = {
|
|
|
|
name: 'run-android',
|
2018-05-11 19:43:49 +00:00
|
|
|
description:
|
|
|
|
'builds your app and starts it on a connected Android emulator or device',
|
2016-07-30 15:59:16 +00:00
|
|
|
func: runAndroid,
|
2018-05-11 19:43:49 +00:00
|
|
|
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),
|
|
|
|
},
|
|
|
|
],
|
2017-01-02 19:06:37 +00:00
|
|
|
};
|