Summary:
Adds an argument to the headless Flipper to print the list of available plugins. Added `--list-plugins`.
Currently the startFlipper function is not scalable enough to add new arguments and its implementation. I am planning to tackle this with the list of Actions which will be closure. So adding a new argument with its implementation will be just appending a closure at the correct location in an array. Will work on that in the later diff stacked on the current one.
Reviewed By: jknoxville
Differential Revision: D15789778
fbshipit-source-id: 91ba472617d593c3490bb932590a06d83597cba7
Summary:
When running in headless mode, if SIGINT is received, but there's a failure to export the state the process doesn't exit. Repeated SIGINTs do the same thing.
This changes it to exit whether the export succeeds or not.
Reviewed By: passy
Differential Revision: D15806412
fbshipit-source-id: 1f6a5b4ea1cd65dacb201f8a1cd020531b3976e6
Summary:
Using `process.exit()` stops the node process without waiting for the event loop to finish, so when using async i/o, which is what happens when piped, if the output is buffered, the process can terminate before it finishes flushing the buffer.
This means you only get some of the output and the JSON is malformed.
This fixes it by calling `process.exit()` inside the flushed callback.
Reviewed By: passy
Differential Revision: D15624806
fbshipit-source-id: ea540ed5a40fb1811e5b705b190da96c8e54730d
Summary:
1. Yargs doesn't like having the same option name as the given alias and will just silently skip those (like --metrics).
2. Having multiple ways of specifying the same argument is not a good practise.
I think we've been misusing `alias` as a way to have more JavaScript-y accessors, but ignoring that yargs already
converts `my-long-argument` to `myLongArgument` without having to expose this.
We haven't rolled out a version with the previous long arguments, so we should
still be able to change this without breaking stuff.
Reviewed By: jknoxville
Differential Revision: D15620636
fbshipit-source-id: 84a8046cf06d696e947719032c4f9c34ac9c0474
Summary:
This diff fetches the additional data by calling the hook added in each plugins when the headless tries to export metrics directly out of the store rather than from the trace.
I added `fetchMetadata` function which will be called while exporting the state as well as exporting the metrics. We do not need to fetch metadata in the case when the metrics are exported from the given trace.
Reviewed By: passy
Differential Revision: D15560129
fbshipit-source-id: 9b14340e565ce17d1825bc2d32520d7b0c2b2219
Summary:
Refactors `startFlipper` function in headless flipper into three different functions.
`earlyExitActions`: Before the dispatcher is called on the store and will exit if the user arguments are one which are meant to terminate the process.
`exitActions`: This function will be called after the dispatcher is called and will exit if the user arguments are one which are meant to terminate the process.
`storeModifyngActions`: It involves business logic which updates the store based on the user arguments.
Reviewed By: passy
Differential Revision: D15556130
fbshipit-source-id: 9d1b035525e613bb2b75454fa4fd6c193993b530
Summary: Adds an argument to select a device in headless. I will refactor the function the headless function in the next diff
Reviewed By: danielbuechele
Differential Revision: D15536774
fbshipit-source-id: 2e3f01c6bc6094d925aebd20ba0bf15b17168cd1
Summary: This diff adds an option of `--list-devices` which will list the currently active devices on the machine. It will be later used to select a device by passing an `id` as an argument.
Reviewed By: danielbuechele
Differential Revision: D15524250
fbshipit-source-id: 7a79ceb1e431a25adcb4e05bc0cb68407c527806
Summary: This diff adds support to pass a path to the trace file to the headless Flipper. The headless Flipper then exports the metrics out of it.
Reviewed By: passy
Differential Revision: D15337067
fbshipit-source-id: 61aca1ffd58e879dafe6aa176f058f7b11460952
Summary:
This diff makes headless flipper accept `metrics` argument. Once this is passed. The headless flipper will terminate to export the metrics of the plugins, the type of the export looks like the following.
```
export type MetricType = {[metricName: string]: number};
type MetricPluginType = {[pluginID: string]: MetricType};
export type ExportMetricType = {[clientID: string]: MetricPluginType};
```
This diff, uses the store to export the metrics. I will modify the logic to accept the data which gets exported through `exportData`
Reviewed By: passy
Differential Revision: D14933499
fbshipit-source-id: dade5b7bc59ea4beb6d16c5ef471737e8597358a
Summary:
Added a promiseTimeout util so that we limit the time taken to export flipper plugin. I had received a feedback from the user stating that that the loader for the export stays for ages and never finishes. So this diff adds a timeout to the promise which is returned by `exportPersistedState` function. This function is currently implemented just by Layout inspector to fetch the entire view hierarchy. I suspect the the former mentioned bug may be due to the unresponsive client.
This diff also shows the plugin and the client information for which `exportPersistedState` timed out. Also this will hopefully solve the problem surfaced recently stating that the bug report gets stuck, the reason for which I suspect would be the same as the above mentioned reason, because we export flipper data when we create a bug report.
Reviewed By: danielbuechele
Differential Revision: D14712633
fbshipit-source-id: 35f8cfa722ec3b7ff94ebda943d618834ac3207d
Summary:
This adds an optional exit strategy that reacts to the client disconnecting rather than a `SIGINT` which can be used for integration tests.
`MiddlewareAPI` is a subset of `Store` and required to work here.
Annoyingly, it's not quite clear to me why this does not work as part of an event loop cycle and requires a `setTimeout`. This doesn't have any negative effects and works in the same way that the SIGINT interruption works, but it's a bit of an eyesore.
Reviewed By: danielbuechele
Differential Revision: D14622111
fbshipit-source-id: e2caca056e478428d977565dc9bc09eefca4230c
Summary:
`exportStore` throws, when no device is connected. The error wasn't catched and `process.exit();` never called. The result is that the CLI couldn't be interrupted as long as `exportStore` thorws (e.g. no device connected).
Catching this error now.
Reviewed By: passy
Differential Revision: D14520754
fbshipit-source-id: 97b245c4de53e58bac8066a1b15874d873bf2841
Summary:
The headless version used to use `JSON.stringify` to serialize the output of `serializeStore` which basically transformed the store to a specific format which is serializable. But we have written the custom serialize function which cateres to the non serializable object types. Headless didn't use it, so thats why it exported Flipper trace in an unrecognizable format for the flipper.
I have also renamed `serializeStore` to `prepareToSerializeStore` so that the confusion doesn't occur in future. I have used an `exportStore` function in headless which exports the store to the `Promise<String>`
Reviewed By: jknoxville
Differential Revision: D14480096
fbshipit-source-id: f312d7637aa082d96c3bc1dfd00eefb19182e97f
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
Summary:
init() was being misused. This returns a Logger instance, so there's no need to create one as well.
This was a problem because different arguments were being passed to each (isHeadless in this case).
Reviewed By: passy
Differential Revision: D14083320
fbshipit-source-id: b0001a2b3cdd914609d54382575e3b0fa4b5f077
Summary:
So we can distinguish between humans and the machines.
We can redirect the traffic to different tables based on this attribute if necessary.
Reviewed By: danielbuechele
Differential Revision: D14025004
fbshipit-source-id: c3a24b5f8a30f24445eaee67843b78ddabfc9d51
Summary:
CLI was not working:
- setup now needs an object with arguments passed
- the `argv` property is needed by `yargs` to work in node: http://yargs.js.org/docs/#api-argv
Reviewed By: passy
Differential Revision: D13991958
fbshipit-source-id: a9432b27f3d4d24c1e43014b8fb87dca806a6e8a
Summary:
This seems like a better approach than ad-hoc lookup in
`electron.remove.argv`. Left a note to a task to provide
a better interface to this.
I also need this in order to ensure we're starting
Flipper through the launcher which needs to happen
before we start the Electron runtime.
Reviewed By: jknoxville
Differential Revision: D13881355
fbshipit-source-id: 69c70d71035a47084f789ddb4dc969b45ba4648b
Summary: listening on `SIGINT` events and putting the serialized store to stdout.
Reviewed By: passy
Differential Revision: D13878051
fbshipit-source-id: 19c1d857a299ed9a474605169c54e5359e0515bd
Summary:
Wrapping console to send all console.logs to stderr, as we are planning to use stdout for the actual data.
By default only console.error messages are logged. I will add a `-v` argument to show all.
Also, displaying some ASCII-art and the version number when starting flipper CLI.
Reviewed By: passy
Differential Revision: D13843675
fbshipit-source-id: acaa70d16f12965a8426abca506049dbafb7962c
Summary:
For the electron build, plugins are bundled with the app and loaded from there at launch. The headless version can't require from its binary, so plugins need to be required from another path.
This diff makes the path where bundled plugins are loaded from adjustable via an environment variable: `BUNDLED_PLUGIN_PATH`. If it's set, the plugins are loaded from this path, otherwise we default to the old behaviour of including them from `./defaultPlugins`.
For the headless version we expect the plugins to be in a folder called `plugins` next to the executable. This should later be configurable via an argument passed to the CLI.
Reviewed By: passy
Differential Revision: D13843676
fbshipit-source-id: 04237ae6631b4f2ba56887fe992a56f860724edc
Summary:
Adding `headless/index.js` This is the entry point to the headless version of Flipper.
This creates a redux store, and initializes the dispatchers. As all business logic (adb connections, etc.) are managed by dispatchers, this spins up a working version of Flipper, listening on our ports, allowing connections to devices.
For APIs not available in node.js, we are adding polyfills. `WebSocket` is used by redux-devtools, `fetch` is used in a couple of places throughout the application. These polyfills are added to the global namespace, so the app can run the same as in the browser.
Reviewed By: passy
Differential Revision: D13786573
fbshipit-source-id: 685f67e1c0d2948de7c43b8a1e2dc10dc69aa743