output data on stdout

Summary: listening on `SIGINT` events and putting the serialized store to stdout.

Reviewed By: passy

Differential Revision: D13878051

fbshipit-source-id: 19c1d857a299ed9a474605169c54e5359e0515bd
This commit is contained in:
Daniel Büchele
2019-02-04 07:21:56 -08:00
committed by Facebook Github Bot
parent 45d1a7b35c
commit 3b75fb092b
3 changed files with 25 additions and 13 deletions

View File

@@ -13,6 +13,7 @@ import path from 'path';
// $FlowFixMe this file exist, trust me, flow! // $FlowFixMe this file exist, trust me, flow!
import setup from '../static/setup.js'; import setup from '../static/setup.js';
import yargs from 'yargs'; import yargs from 'yargs';
import {serializeStore} from '../src/utils/exportData.js';
yargs yargs
.usage('$0 [args]') .usage('$0 [args]')
@@ -96,4 +97,11 @@ function startFlipper({
const logger = new Logger(store); const logger = new Logger(store);
init(store); init(store);
dispatcher(store, logger); dispatcher(store, logger);
process.on('SIGINT', () => {
originalConsole.log(
JSON.stringify(serializeStore(store.getState()), null, 2),
);
process.exit();
});
} }

View File

@@ -45,16 +45,16 @@ type Actions =
| PluginsAction | PluginsAction
| {|type: 'INIT'|}; | {|type: 'INIT'|};
export type Store = ReduxStore< export type State = {|
{| application: ApplicationState,
application: ApplicationState, connections: DevicesState,
connections: DevicesState, pluginStates: PluginStatesState,
pluginStates: PluginStatesState, notifications: NotificationsState,
notifications: NotificationsState, plugins: PluginsState,
plugins: PluginsState, |};
|},
Actions, // $FlowFixMe introduced when removing $Subtype/$Supertype
>; export type Store = ReduxStore<State, Actions>;
export default combineReducers<_, Actions>({ export default combineReducers<_, Actions>({
application, application,

View File

@@ -10,6 +10,7 @@ import type {State as PluginStates} from '../reducers/pluginStates';
import type {PluginNotification} from '../reducers/notifications.js'; import type {PluginNotification} from '../reducers/notifications.js';
import type {ClientExport} from '../Client.js'; import type {ClientExport} from '../Client.js';
import type {State as PluginStatesState} from '../reducers/pluginStates'; import type {State as PluginStatesState} from '../reducers/pluginStates';
import type {State} from '../reducers/index';
import {FlipperDevicePlugin} from '../plugin.js'; import {FlipperDevicePlugin} from '../plugin.js';
import {default as BaseDevice} from '../devices/BaseDevice'; import {default as BaseDevice} from '../devices/BaseDevice';
@@ -118,21 +119,24 @@ export const processStore = (
return null; return null;
}; };
export const exportStoreToFile = (data: Store): Promise<void> => { export function serializeStore(state: State): ?ExportType {
const state = data.getState();
const {activeNotifications} = state.notifications; const {activeNotifications} = state.notifications;
const {selectedDevice, clients} = state.connections; const {selectedDevice, clients} = state.connections;
const {pluginStates} = state; const {pluginStates} = state;
const {devicePlugins} = state.plugins; const {devicePlugins} = state.plugins;
// TODO: T39612653 Make Client mockable. Currently rsocket logic is tightly coupled. // TODO: T39612653 Make Client mockable. Currently rsocket logic is tightly coupled.
// Not passing the entire state as currently Client is not mockable. // Not passing the entire state as currently Client is not mockable.
const json = processStore( return processStore(
activeNotifications, activeNotifications,
selectedDevice, selectedDevice,
pluginStates, pluginStates,
clients.map(client => client.toJSON()), clients.map(client => client.toJSON()),
devicePlugins, devicePlugins,
); );
}
export const exportStoreToFile = (store: Store): Promise<void> => {
const json = serializeStore(store.getState());
if (json) { if (json) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fs.writeFile(exportFilePath, JSON.stringify(json), err => { fs.writeFile(exportFilePath, JSON.stringify(json), err => {