From b9ed72a043a67401a43b91f1d55c72d5f7e82bc1 Mon Sep 17 00:00:00 2001 From: djhi Date: Sun, 21 Feb 2016 16:52:58 -0800 Subject: [PATCH] Added a `root` option to the `run-android` command Summary:Added a `root` option to the `run-android` command allowing to run it from a parent directory. Use case: project is organized like this ``` - api - apps ---- web ---- react-native - package.json ``` You can use the root option on `react-native start` but not on `run-android`. This pr fixes that. Closes https://github.com/facebook/react-native/pull/5597 Differential Revision: D2959523 Pulled By: mkonicek fb-gh-sync-id: 03fb74b201fe9e89bf6fab80c9a98ca708464261 shipit-source-id: 03fb74b201fe9e89bf6fab80c9a98ca708464261 --- local-cli/runAndroid/runAndroid.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index fa2836998..8cd14884a 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -30,9 +30,15 @@ function _runAndroid(argv, config, resolve, reject) { command: 'install-debug', type: 'string', required: false, + }, { + command: 'root', + type: 'string', + description: 'Override the root directory for the android build (which contains the android directory)', }], argv); - if (!checkAndroid()) { + args.root = args.root || ''; + + if (!checkAndroid(args)) { console.log(chalk.red('Android project not found. Maybe run react-native android first?')); return; } @@ -52,13 +58,13 @@ function _runAndroid(argv, config, resolve, reject) { } // Verifies this is an Android project -function checkAndroid() { - return fs.existsSync('android/gradlew'); +function checkAndroid(args) { + return fs.existsSync(path.join(args.root, 'android/gradlew')); } // Builds the app and runs it on a connected emulator / device. function buildAndRun(args, reject) { - process.chdir('android'); + process.chdir(path.join(args.root, 'android')); try { const cmd = process.platform.startsWith('win') ? 'gradlew.bat'