Summary: This diff does the following - Support to export the entire view hierarchy for iOS - Android is not supported yet - This diff adds a call `getAllNodes` to the client side of iOS, which returns the entire view hierarchy - Currently the search doesn't work on the imported layout plugin data. Also the imported layout plugin data doesn't expand the way it does when component is mounted, reason being the client passed to the plugin is not functional for the archived case I will work on fixing the last points in the next diffs stacked on the current one. For Android: - Currently the export function will export whatever is currently displayed on the Flipper app, not the entire view hierarchy Support for Android will also come up in later diffs. Reviewed By: jknoxville Differential Revision: D14209157 fbshipit-source-id: 3ad3e39edfd994913dc19cc239bfbbe011a9757c
105 lines
2.9 KiB
JavaScript
105 lines
2.9 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 {init as initLogger} 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';
|
|
import {serializeStore} from '../src/utils/exportData.js';
|
|
|
|
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; // http://yargs.js.org/docs/#api-argv
|
|
|
|
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);
|
|
}
|
|
};
|
|
},
|
|
});
|
|
|
|
// 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');
|
|
|
|
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 = initLogger(store, {isHeadless: true});
|
|
dispatcher(store, logger);
|
|
|
|
process.on('SIGINT', async () => {
|
|
originalConsole.log(JSON.stringify(await serializeStore(store), null, 2));
|
|
process.exit();
|
|
});
|
|
}
|