2015-10-20 18:46:37 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
'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)),
|
|
|
|
{stdio: 'inherit'}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.log(chalk.red('Android project not found. Maybe run react-native android first?'));
|
|
|
|
}
|
2015-10-20 18:46:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-09 11:25:27 +00:00
|
|
|
if (!args.packager) {
|
|
|
|
return buildAndRun(args);
|
|
|
|
}
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
return isPackagerRunning().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') {
|
2016-07-30 15:59:16 +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...'));
|
2015-10-20 18:46:37 +00:00
|
|
|
startServerInNewWindow();
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2016-06-23 13:43:12 +00:00
|
|
|
console.log(chalk.bold(
|
|
|
|
`Running ${adbPath} ${adbArgs.join(' ')}`
|
|
|
|
));
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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'));
|
|
|
|
const cmd = process.platform.startsWith('win')
|
|
|
|
? 'gradlew.bat'
|
|
|
|
: './gradlew';
|
|
|
|
|
|
|
|
const packageName = fs.readFileSync(
|
2017-04-11 19:02:59 +00:00
|
|
|
`${args.appFolder}/src/main/AndroidManifest.xml`,
|
2016-12-16 03:38:36 +00:00
|
|
|
'utf8'
|
|
|
|
).match(/package="(.+?)"/)[1];
|
|
|
|
|
2017-04-04 23:37:44 +00:00
|
|
|
const packageNameWithSuffix = args.appIdSuffix ? packageName + '.' + args.appIdSuffix : packageName;
|
|
|
|
|
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)) {
|
2017-04-04 23:37:44 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 23:37:44 +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);
|
2017-04-04 23:37:44 +00:00
|
|
|
installAndLaunchOnDevice(args, args.deviceId, packageNameWithSuffix, packageName, adbPath);
|
2016-12-16 03:38:36 +00:00
|
|
|
} 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) {
|
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) {
|
2017-01-02 19:06:37 +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 {
|
2017-04-11 19:02:59 +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];
|
|
|
|
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'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 23:37:44 +00:00
|
|
|
function tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPath, mainActivity) {
|
2016-12-16 03:38:36 +00:00
|
|
|
try {
|
2017-04-04 23:37:44 +00:00
|
|
|
const adbArgs = ['-s', device, 'shell', 'am', 'start', '-n', packageNameWithSuffix + '/' + packageName + '.' + mainActivity];
|
2016-12-16 03:38:36 +00:00
|
|
|
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?'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 23:37:44 +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);
|
2017-04-04 23:37:44 +00:00
|
|
|
tryLaunchAppOnDevice(selectedDevice, packageNameWithSuffix, packageName, adbPath, args.mainActivity);
|
2016-12-16 03:38:36 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 23:37:44 +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) {
|
|
|
|
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)
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
console.log(chalk.bold(
|
2017-02-06 20:21:13 +00:00
|
|
|
`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) {
|
|
|
|
console.log(chalk.red(
|
2015-11-03 11:46:08 +00:00
|
|
|
'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' +
|
2016-11-14 02:49:49 +00:00
|
|
|
'set up your Android development environment:\n' +
|
|
|
|
'https://facebook.github.io/react-native/docs/android-setup.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
|
|
|
}
|
2016-03-08 20:07:59 +00:00
|
|
|
const devices = adb.getDevices();
|
|
|
|
if (devices && devices.length > 0) {
|
|
|
|
devices.forEach((device) => {
|
2017-08-08 13:41:14 +00:00
|
|
|
tryRunAdbReverse(args.port, device);
|
2017-04-04 23:37:44 +00:00
|
|
|
tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPath, args.mainActivity);
|
2016-04-06 16:20:39 +00:00
|
|
|
});
|
2016-03-08 20:07:59 +00:00
|
|
|
} else {
|
2016-12-16 03:38:36 +00:00
|
|
|
try {
|
|
|
|
// If we cannot execute based on adb devices output, fall back to
|
|
|
|
// shell am start
|
|
|
|
const fallbackAdbArgs = [
|
2017-04-04 23:37:44 +00:00
|
|
|
'shell', 'am', 'start', '-n', packageNameWithSuffix + '/' + packageName + '.MainActivity'
|
2016-12-16 03:38:36 +00:00
|
|
|
];
|
|
|
|
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
|
|
|
}
|
2015-10-20 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function startServerInNewWindow() {
|
2016-04-29 11:13:30 +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
|
|
|
|
|
|
|
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);
|
2016-03-05 05:54:47 +00:00
|
|
|
}
|
2016-05-04 09:44:42 +00:00
|
|
|
return child_process.spawnSync('open', [launchPackagerScript], procConfig);
|
2016-03-05 05:54:47 +00:00
|
|
|
|
2015-10-20 18:46:37 +00:00
|
|
|
} else if (process.platform === 'linux') {
|
2016-05-04 09:44:42 +00:00
|
|
|
procConfig.detached = true;
|
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.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);
|
2016-03-05 05:54:47 +00:00
|
|
|
|
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';
|
2017-03-24 01:11:30 +00:00
|
|
|
return child_process.spawn('cmd.exe', ['/C', launchPackagerScript], procConfig);
|
2015-10-20 18:46:37 +00:00
|
|
|
} else {
|
2016-03-08 20:07:59 +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',
|
|
|
|
description: 'builds your app and starts it on a connected Android emulator or device',
|
|
|
|
func: runAndroid,
|
|
|
|
options: [{
|
2016-12-16 03:38:36 +00:00
|
|
|
command: '--install-debug',
|
|
|
|
}, {
|
2016-07-30 15:59:16 +00:00
|
|
|
command: '--root [string]',
|
2016-12-16 03:38:36 +00:00
|
|
|
description: 'Override the root directory for the android build (which contains the android directory)',
|
2016-07-30 15:59:16 +00:00
|
|
|
default: '',
|
|
|
|
}, {
|
|
|
|
command: '--flavor [string]',
|
|
|
|
description: '--flavor has been deprecated. Use --variant instead',
|
|
|
|
}, {
|
|
|
|
command: '--variant [string]',
|
2017-04-11 19:02:59 +00:00
|
|
|
}, {
|
|
|
|
command: '--appFolder [string]',
|
|
|
|
description: 'Specify a different application folder name for the android source.',
|
|
|
|
default: 'app',
|
2017-04-04 23:37:44 +00:00
|
|
|
}, {
|
|
|
|
command: '--appIdSuffix [string]',
|
|
|
|
description: 'Specify an applicationIdSuffix to launch after build.',
|
|
|
|
default: '',
|
2017-01-09 12:00:54 +00:00
|
|
|
}, {
|
|
|
|
command: '--main-activity [string]',
|
|
|
|
description: 'Name of the activity to start',
|
|
|
|
default: 'MainActivity',
|
2016-11-23 14:32:58 +00:00
|
|
|
}, {
|
2016-12-16 03:38:36 +00:00
|
|
|
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).',
|
2017-01-09 11:25:27 +00:00
|
|
|
}, {
|
|
|
|
command: '--no-packager',
|
|
|
|
description: 'Do not launch packager while building',
|
2017-08-08 13:41:14 +00:00
|
|
|
}, {
|
|
|
|
command: '--port [number]',
|
|
|
|
default: 8081,
|
|
|
|
parse: (val: string) => Number(val),
|
2016-07-30 15:59:16 +00:00
|
|
|
}],
|
2017-01-02 19:06:37 +00:00
|
|
|
};
|