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

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