mirror of https://github.com/status-im/metro.git
[ReactNative] Fix launchEditor script
This commit is contained in:
parent
2115b67bd9
commit
04da81d4d5
|
@ -8,23 +8,21 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fs = require('fs');
|
||||
var spawn = require('child_process').spawn;
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var firstLaunch = true;
|
||||
|
||||
function guessEditor() {
|
||||
if (firstLaunch) {
|
||||
console.log('When you see Red Box with stack trace, you can click any ' +
|
||||
'stack frame to jump to the source file. The packager will launch your ' +
|
||||
'editor of choice. It will first look at REACT_EDITOR environment ' +
|
||||
'variable, then at EDITOR. To set it up, you can add something like ' +
|
||||
'REACT_EDITOR=atom to your .bashrc.');
|
||||
firstLaunch = false;
|
||||
}
|
||||
|
||||
var editor = process.env.REACT_EDITOR || process.env.EDITOR || 'subl';
|
||||
return editor;
|
||||
function printInstructions(title) {
|
||||
console.log([
|
||||
'',
|
||||
chalk.bgBlue.white.bold(' ' + title + ' '),
|
||||
' When you see Red Box with stack trace, you can click any ',
|
||||
' stack frame to jump to the source file. The packager will launch your ',
|
||||
' editor of choice. It will first look at REACT_EDITOR environment ',
|
||||
' variable, then at EDITOR. To set it up, you can add something like ',
|
||||
' REACT_EDITOR=atom to your .bashrc.',
|
||||
''
|
||||
].join('\n'));
|
||||
}
|
||||
|
||||
function launchEditor(fileName, lineNumber) {
|
||||
|
@ -37,9 +35,18 @@ function launchEditor(fileName, lineNumber) {
|
|||
argument += ':' + lineNumber;
|
||||
}
|
||||
|
||||
var editor = guessEditor();
|
||||
console.log('Opening ' + fileName + ' with ' + editor);
|
||||
spawn(editor, [argument], { stdio: ['pipe', 'pipe', process.stderr] });
|
||||
var editor = process.env.REACT_EDITOR || process.env.EDITOR;
|
||||
if (editor) {
|
||||
console.log('Opening ' + chalk.underline(fileName) + ' with ' + chalk.bold(editor));
|
||||
exec(editor + ' ' + argument, function(error) {
|
||||
if (error) {
|
||||
console.log(chalk.red(error.message));
|
||||
printInstructions('How to fix');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
printInstructions('PRO TIP');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = launchEditor;
|
||||
|
|
Loading…
Reference in New Issue