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 authored and Martin Konicek committed Oct 8, 2015
1 parent 6345e8c commit 68c209a
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],
{detached: true});
}
} else {
child_process.spawn('sh', [
path.resolve(__dirname, '..', 'packager', 'packager.sh'),
'--projectRoots',
process.cwd(),
], {stdio: 'inherit'});
}
};
};

0 comments on commit 68c209a

Please sign in to comment.