add command line options
Summary: Adding options for the CLI Reviewed By: passy Differential Revision: D13864405 fbshipit-source-id: 1900c32833c7d18a4806f2a839215b5b536cb44f
This commit is contained in:
committed by
Facebook Github Bot
parent
db9bc985eb
commit
45d1a7b35c
@@ -12,43 +12,88 @@ 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';
|
||||
import yargs from 'yargs';
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
||||
yargs
|
||||
.usage('$0 [args]')
|
||||
.command(
|
||||
'*',
|
||||
'Start a headless Flipper instance',
|
||||
yargs => {
|
||||
yargs.option('secure-port', {
|
||||
default: '8088',
|
||||
describe: 'Secure port the Flipper server should run on.',
|
||||
type: 'string',
|
||||
});
|
||||
yargs.option('insecure-port', {
|
||||
default: '8089',
|
||||
describe: 'Insecure port the Flipper server should run on.',
|
||||
type: 'string',
|
||||
});
|
||||
yargs.option('dev', {
|
||||
default: false,
|
||||
describe:
|
||||
'Enable redux-devtools. Tries to connect to devtools running on port 8181',
|
||||
type: 'boolean',
|
||||
});
|
||||
yargs.option('v', {
|
||||
alias: 'verbose',
|
||||
default: false,
|
||||
describe: 'Enable verbose logging',
|
||||
type: 'boolean',
|
||||
});
|
||||
},
|
||||
startFlipper,
|
||||
)
|
||||
.version(global.__VERSION__)
|
||||
.help().argv;
|
||||
|
||||
// Polyfills
|
||||
global.WebSocket = require('ws'); // used for redux devtools
|
||||
global.fetch = require('node-fetch/lib/index');
|
||||
function startFlipper({
|
||||
dev,
|
||||
verbose,
|
||||
'insecure-port': insecurePort,
|
||||
'secure-port': securePort,
|
||||
}) {
|
||||
console.error(`
|
||||
_____ _ _
|
||||
| __| |_|___ ___ ___ ___
|
||||
| __| | | . | . | -_| _|
|
||||
|__| |_|_| _| _|___|_| v${global.__VERSION__}
|
||||
|_| |_|
|
||||
`);
|
||||
// redirect all logging to stderr
|
||||
const originalConsole = global.console;
|
||||
global.console = new Proxy(console, {
|
||||
get: function(obj, prop) {
|
||||
return (...args) => {
|
||||
if (prop === 'error' || verbose) {
|
||||
originalConsole.error(`[${prop}] `, ...args);
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
process.env.BUNDLED_PLUGIN_PATH =
|
||||
process.env.BUNDLED_PLUGIN_PATH ||
|
||||
path.join(path.dirname(process.execPath), 'plugins');
|
||||
// Polyfills
|
||||
global.WebSocket = require('ws'); // used for redux devtools
|
||||
global.fetch = require('node-fetch/lib/index');
|
||||
|
||||
// needs to be required after WebSocket polyfill is loaded
|
||||
const devToolsEnhancer = require('remote-redux-devtools').default;
|
||||
process.env.BUNDLED_PLUGIN_PATH =
|
||||
process.env.BUNDLED_PLUGIN_PATH ||
|
||||
path.join(path.dirname(process.execPath), 'plugins');
|
||||
|
||||
setup();
|
||||
const store = createStore(
|
||||
reducers,
|
||||
devToolsEnhancer({realtime: true, hostname: 'localhost', port: 8181}),
|
||||
);
|
||||
const logger = new Logger(store);
|
||||
init(store);
|
||||
dispatcher(store, logger);
|
||||
process.env.FLIPPER_PORTS = `${insecurePort},${securePort}`;
|
||||
|
||||
// needs to be required after WebSocket polyfill is loaded
|
||||
const devToolsEnhancer = require('remote-redux-devtools').default;
|
||||
|
||||
setup();
|
||||
const store = dev
|
||||
? createStore(
|
||||
reducers,
|
||||
devToolsEnhancer({realtime: true, hostname: 'localhost', port: 8181}),
|
||||
)
|
||||
: createStore(reducers);
|
||||
const logger = new Logger(store);
|
||||
init(store);
|
||||
dispatcher(store, logger);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user