Skip to content

Commit

Permalink
[cli] spawn xterm on linux to run the packager
Browse files Browse the repository at this point in the history
Also use ANDROID_HOME env var when running adb.
  • Loading branch information
foghina committed Sep 28, 2015
1 parent 0ff3a42 commit f6ec854
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 6 additions & 3 deletions local-cli/run-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ function buildAndRun() {
}
try {
var packageName = fs.readFileSync('app/src/main/AndroidManifest.xml', 'utf8').match(/package="(.+?)"/)[1];
var adbPath = process.env.ANDROID_HOME ? process.env.ANDROID_HOME + '/platform-tools/adb' : 'adb';
var adbArgs = ['shell', 'am', 'start', '-n', packageName + '/.MainActivity'];
console.log(chalk.bold('Starting the app (adb ' + adbArgs.join(' ') + ')...'));
child_process.spawnSync('adb', adbArgs, {
console.log(chalk.bold('Starting the app (' + adbPath + ' ' + adbArgs.join(' ') + ')...'));
child_process.spawnSync(adbPath, adbArgs, {
stdio: [process.stdin, process.stdout, process.stderr]
});
} catch (e) {
Expand Down Expand Up @@ -62,6 +63,8 @@ module.exports = function() {
console.log(chalk.yellow('[warn] JS server not recognized, continuing with build...'));
}
buildAndRun();
// make sure we don't wait around for the packager process
process.exit();
});
});
statusReq.on('error', function() {
Expand All @@ -70,4 +73,4 @@ module.exports = function() {
runPackager(true);
buildAndRun();
});
};
};
15 changes: 11 additions & 4 deletions local-cli/run-packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ var child_process = require('child_process');

module.exports = function(newWindow) {
if (newWindow) {
child_process.spawnSync('open', [
path.resolve(__dirname, '..', 'packager', 'launchPackager.command')
]);
var launchPackagerScript =
path.resolve(__dirname, '..', 'packager', 'launchPackager.command');
if (process.platform === 'darwin') {
child_process.spawnSync('open', [launchPackagerScript]);
} else if (process.platform === 'linux') {
child_process.spawn(
'xterm',
['-e', 'sh', launchPackagerScript],

This comment has been minimized.

Copy link
@mkonicek

mkonicek Oct 1, 2015

Contributor

Do we still call launchPackager.command on Linux though?

This comment has been minimized.

Copy link
@foghina

foghina Oct 1, 2015

Author Contributor

We could call node directly, but I kept launchPackager.command for consistency.

{detached: true});
}
} else {
child_process.spawn('sh', [
path.resolve(__dirname, '..', 'packager', 'packager.sh'),
'--projectRoots',
process.cwd(),
], {stdio: 'inherit'});
}
};
};

1 comment on commit f6ec854

@mkonicek
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you!

Please sign in to comment.