From 45d1a7b35c6e98482794092d5f91c0422c8e8068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Mon, 4 Feb 2019 07:21:56 -0800 Subject: [PATCH] add command line options Summary: Adding options for the CLI Reviewed By: passy Differential Revision: D13864405 fbshipit-source-id: 1900c32833c7d18a4806f2a839215b5b536cb44f --- headless/index.js | 115 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 35 deletions(-) diff --git a/headless/index.js b/headless/index.js index 116b4852a..78231544b 100644 --- a/headless/index.js +++ b/headless/index.js @@ -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); +}