Files
flipper/headless/index.js
Daniel Büchele db9bc985eb redirecting console to stderr
Summary:
Wrapping console to send all console.logs to stderr, as we are planning to use stdout for the actual data.
By default only console.error messages are logged. I will add a `-v` argument to show all.

Also, displaying some ASCII-art and the version number when starting flipper CLI.

Reviewed By: passy

Differential Revision: D13843675

fbshipit-source-id: acaa70d16f12965a8426abca506049dbafb7962c
2019-02-04 07:29:13 -08:00

55 lines
1.5 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {createStore} from 'redux';
import reducers from '../src/reducers/index.js';
import dispatcher from '../src/dispatcher/index.js';
import Logger, {init} from '../src/fb-stubs/Logger.js';
import path from 'path';
// $FlowFixMe this file exist, trust me, flow!
import setup from '../static/setup.js';
console.error(`
_____ _ _
| __| |_|___ ___ ___ ___
| __| | | . | . | -_| _|
|__| |_|_| _| _|___|_| v${global.__VERSION__}
|_| |_|
`);
// redirect all logging to stderr
const verboseMode = false;
const originalConsole = global.console;
global.console = new Proxy(console, {
get: function(obj, prop) {
return (...args) => {
if (prop === 'error' || verboseMode) {
originalConsole.error(`[${prop}] `, ...args);
}
};
},
});
// Polyfills
global.WebSocket = require('ws'); // used for redux devtools
global.fetch = require('node-fetch/lib/index');
process.env.BUNDLED_PLUGIN_PATH =
process.env.BUNDLED_PLUGIN_PATH ||
path.join(path.dirname(process.execPath), 'plugins');
// needs to be required after WebSocket polyfill is loaded
const devToolsEnhancer = require('remote-redux-devtools').default;
setup();
const store = createStore(
reducers,
devToolsEnhancer({realtime: true, hostname: 'localhost', port: 8181}),
);
const logger = new Logger(store);
init(store);
dispatcher(store, logger);