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:
committed by
Facebook Github Bot
parent
45d1a7b35c
commit
3b75fb092b
@@ -13,6 +13,7 @@ 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]')
|
||||
@@ -96,4 +97,11 @@ function startFlipper({
|
||||
const logger = new Logger(store);
|
||||
init(store);
|
||||
dispatcher(store, logger);
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
originalConsole.log(
|
||||
JSON.stringify(serializeStore(store.getState()), null, 2),
|
||||
);
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,16 +45,16 @@ type Actions =
|
||||
| PluginsAction
|
||||
| {|type: 'INIT'|};
|
||||
|
||||
export type Store = ReduxStore<
|
||||
{|
|
||||
export type State = {|
|
||||
application: ApplicationState,
|
||||
connections: DevicesState,
|
||||
pluginStates: PluginStatesState,
|
||||
notifications: NotificationsState,
|
||||
plugins: PluginsState,
|
||||
|},
|
||||
Actions,
|
||||
>;
|
||||
|};
|
||||
|
||||
// $FlowFixMe introduced when removing $Subtype/$Supertype
|
||||
export type Store = ReduxStore<State, Actions>;
|
||||
|
||||
export default combineReducers<_, Actions>({
|
||||
application,
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user