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';
|
'use strict';
|
||||||
|
|
||||||
|
var chalk = require('chalk');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var spawn = require('child_process').spawn;
|
var exec = require('child_process').exec;
|
||||||
|
|
||||||
var firstLaunch = true;
|
function printInstructions(title) {
|
||||||
|
console.log([
|
||||||
function guessEditor() {
|
'',
|
||||||
if (firstLaunch) {
|
chalk.bgBlue.white.bold(' ' + title + ' '),
|
||||||
console.log('When you see Red Box with stack trace, you can click any ' +
|
' 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 ' +
|
' stack frame to jump to the source file. The packager will launch your ',
|
||||||
'editor of choice. It will first look at REACT_EDITOR environment ' +
|
' editor of choice. It will first look at REACT_EDITOR environment ',
|
||||||
'variable, then at EDITOR. To set it up, you can add something like ' +
|
' variable, then at EDITOR. To set it up, you can add something like ',
|
||||||
'REACT_EDITOR=atom to your .bashrc.');
|
' REACT_EDITOR=atom to your .bashrc.',
|
||||||
firstLaunch = false;
|
''
|
||||||
}
|
].join('\n'));
|
||||||
|
|
||||||
var editor = process.env.REACT_EDITOR || process.env.EDITOR || 'subl';
|
|
||||||
return editor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function launchEditor(fileName, lineNumber) {
|
function launchEditor(fileName, lineNumber) {
|
||||||
|
@ -37,9 +35,18 @@ function launchEditor(fileName, lineNumber) {
|
||||||
argument += ':' + lineNumber;
|
argument += ':' + lineNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
var editor = guessEditor();
|
var editor = process.env.REACT_EDITOR || process.env.EDITOR;
|
||||||
console.log('Opening ' + fileName + ' with ' + editor);
|
if (editor) {
|
||||||
spawn(editor, [argument], { stdio: ['pipe', 'pipe', process.stderr] });
|
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;
|
module.exports = launchEditor;
|
||||||
|
|
Loading…
Reference in New Issue