react-native/local-cli/server/util/launchChrome.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const opn = require('opn');
added chromium support for devTools on linux Summary: <details> 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. Please read the [Contribution Guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md) to learn more about contributing to React Native. </details> _What existing problem does the pull request solve?_ On Linux, the packager caught an "Google Chrome exited with error: { Error: spawn google-chrome ENOENT}" when trying to launch the devTools because google-chrome is not installed but chromium is. Thus, this pull request maps the platform Linux with chromium for launching the debugger automatically in the packager _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._ - enter on terminal > react-native start - launch the app in dev mode with "Debug JS remotely" enabled - the packager prints "Launching Dev Tools..." and launch chromium with the debugger ![screenshot](https://user-images.githubusercontent.com/13065528/27481217-ceaf5e58-581b-11e7-976f-75c107596ad3.png) Closes https://github.com/facebook/react-native/pull/14696 Differential Revision: D5398564 Pulled By: hramos fbshipit-source-id: 151f83b549492c8716a248eb16f7e24c5658b32e
2017-07-11 19:22:55 +00:00
const execSync = require('child_process').execSync;
function commandExistsUnixSync(commandName, callback) {
added chromium support for devTools on linux Summary: <details> 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. Please read the [Contribution Guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md) to learn more about contributing to React Native. </details> _What existing problem does the pull request solve?_ On Linux, the packager caught an "Google Chrome exited with error: { Error: spawn google-chrome ENOENT}" when trying to launch the devTools because google-chrome is not installed but chromium is. Thus, this pull request maps the platform Linux with chromium for launching the debugger automatically in the packager _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._ - enter on terminal > react-native start - launch the app in dev mode with "Debug JS remotely" enabled - the packager prints "Launching Dev Tools..." and launch chromium with the debugger ![screenshot](https://user-images.githubusercontent.com/13065528/27481217-ceaf5e58-581b-11e7-976f-75c107596ad3.png) Closes https://github.com/facebook/react-native/pull/14696 Differential Revision: D5398564 Pulled By: hramos fbshipit-source-id: 151f83b549492c8716a248eb16f7e24c5658b32e
2017-07-11 19:22:55 +00:00
try {
var stdout = execSync(
'command -v ' +
commandName +
' 2>/dev/null' +
" && { echo >&1 '" +
commandName +
" found'; exit 0; }",
);
added chromium support for devTools on linux Summary: <details> 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. Please read the [Contribution Guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md) to learn more about contributing to React Native. </details> _What existing problem does the pull request solve?_ On Linux, the packager caught an "Google Chrome exited with error: { Error: spawn google-chrome ENOENT}" when trying to launch the devTools because google-chrome is not installed but chromium is. Thus, this pull request maps the platform Linux with chromium for launching the debugger automatically in the packager _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._ - enter on terminal > react-native start - launch the app in dev mode with "Debug JS remotely" enabled - the packager prints "Launching Dev Tools..." and launch chromium with the debugger ![screenshot](https://user-images.githubusercontent.com/13065528/27481217-ceaf5e58-581b-11e7-976f-75c107596ad3.png) Closes https://github.com/facebook/react-native/pull/14696 Differential Revision: D5398564 Pulled By: hramos fbshipit-source-id: 151f83b549492c8716a248eb16f7e24c5658b32e
2017-07-11 19:22:55 +00:00
return !!stdout;
} catch (error) {
return false;
}
}
function getChromeAppName(): string {
switch (process.platform) {
case 'darwin':
return 'google chrome';
case 'win32':
return 'chrome';
case 'linux':
if (commandExistsUnixSync('google-chrome')) {
return 'google-chrome';
} else if (commandExistsUnixSync('chromium-browser')) {
return 'chromium-browser';
} else {
return 'chromium';
}
default:
added chromium support for devTools on linux Summary: <details> 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. Please read the [Contribution Guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md) to learn more about contributing to React Native. </details> _What existing problem does the pull request solve?_ On Linux, the packager caught an "Google Chrome exited with error: { Error: spawn google-chrome ENOENT}" when trying to launch the devTools because google-chrome is not installed but chromium is. Thus, this pull request maps the platform Linux with chromium for launching the debugger automatically in the packager _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._ - enter on terminal > react-native start - launch the app in dev mode with "Debug JS remotely" enabled - the packager prints "Launching Dev Tools..." and launch chromium with the debugger ![screenshot](https://user-images.githubusercontent.com/13065528/27481217-ceaf5e58-581b-11e7-976f-75c107596ad3.png) Closes https://github.com/facebook/react-native/pull/14696 Differential Revision: D5398564 Pulled By: hramos fbshipit-source-id: 151f83b549492c8716a248eb16f7e24c5658b32e
2017-07-11 19:22:55 +00:00
return 'google-chrome';
}
}
function launchChrome(url: string) {
opn(url, {app: [getChromeAppName()]}, function(err) {
if (err) {
console.error('Google Chrome exited with error:', err);
}
});
}
module.exports = launchChrome;