Commit Graph

49 Commits

Author SHA1 Message Date
John Knox
ff5a1b72fd Fix infinite console proxy bug in headless
Summary:
Headless flipper is getting an infinite recursion problem after the console proxy was changed to an in-place method swap.

This uses an in-place method swap in headless too, so they don't conflict with each other.

Reviewed By: passy, priteshrnandgaonkar

Differential Revision: D18007638

fbshipit-source-id: 62dce7fa94f4ce6b90da4f3c6ec6e8d9ed15fbe7
2019-10-18 10:09:02 -07:00
Andres Suarez
0675dd924d Tidy up Flipper license headers [1/2]
Reviewed By: passy

Differential Revision: D17863711

fbshipit-source-id: 259dc77826fb803ff1b88c88529d7f679d3b74d8
2019-10-11 13:46:45 -07:00
John Knox
729e74f2fc Switch to using settings for android sdk location
Summary: A settings screen has been added where android home can be set. This changes the downstream code to use this value rather than the `env.PATH` variable.

Reviewed By: passy

Differential Revision: D17713288

fbshipit-source-id: 51551652c9c2f468e1117c18785123348e4b4576
2019-10-07 08:51:06 -07:00
Daniel Büchele
bb70b53c7c headless
Summary: _typescript_

Reviewed By: passy

Differential Revision: D17284499

fbshipit-source-id: 7306e36772911044a1d8b36c4a38f79b861eb2e6
2019-09-11 03:04:55 -07:00
Daniel Büchele
853d80f182 headless
Summary: _typescript_

Reviewed By: passy

Differential Revision: D16962733

fbshipit-source-id: 6583c5a4471b12f91895f6449ed9c510265a63e2
2019-08-23 09:33:56 -07:00
John Knox
ce3f69c249 Convert serialization.js to TS
Summary:
Convert serialization to typescript.

I tried to type the deserialize function but don't know enough about the expected format to be able to tell what the types should be.

Reviewed By: passy

Differential Revision: D16785945

fbshipit-source-id: 45de7ee1c8972314a52abcf20d428ba44f031a00
2019-08-15 07:32:53 -07:00
Pascal Hartig
6a0da24eb2 Migrate utils/index
Summary: _typescript_

Reviewed By: danielbuechele

Differential Revision: D16805609

fbshipit-source-id: 57eda17f45fc2dfe94a0d34948be5b673591a8ee
2019-08-14 10:06:03 -07:00
Pascal Hartig
5c6ec866d6 Migrate listDevices
Summary: _typescript_

Reviewed By: danielbuechele

Differential Revision: D16764089

fbshipit-source-id: 03d980c354f8c03d7091fe01f82655e61c5854ff
2019-08-13 08:26:55 -07:00
Pascal Hartig
6c7aeef7ed Migrate exportMetrics
Summary: _typescript_

Reviewed By: jknoxville

Differential Revision: D16712087

fbshipit-source-id: 63dc45a26eb8112aef2b1bfa0d67bf57aa9ec72a
2019-08-12 03:53:16 -07:00
Pascal Hartig
99ca6aa7e8 Migrate exportData
Summary: _typescript_

Reviewed By: jknoxville

Differential Revision: D16711940

fbshipit-source-id: 2e0e5cd0440fe1cdb7bd29af94e22c7f6b9137f8
2019-08-12 03:53:15 -07:00
John Knox
ce34c20506 Convert utils/pluginUtils to TS
Reviewed By: danielbuechele

Differential Revision: D16710689

fbshipit-source-id: 8da309810f633af27759286521c784ac665531b9
2019-08-12 03:11:16 -07:00
Pascal Hartig
b42abcbb59 Migrate logger
Summary:
Removed defunct log filtering functionality, but we probably want to rebuild that.
Funny that tsc caught this as non functioning but Flow happily accepted it.

Reviewed By: danielbuechele

Differential Revision: D16690959

fbshipit-source-id: b079dd6faba83ca0c443d00cbb69c8ff95c4fa69
2019-08-09 10:47:12 -07:00
Pritesh Nandgaonkar
c43beb53d1 Migrate dispatcher index to tsx
Summary: As per the title

Reviewed By: jknoxville, passy

Differential Revision: D16690303

fbshipit-source-id: fa78ea1e3f288249676d5a6423e5d0f0a6e427a4
2019-08-09 07:56:55 -07:00
Pritesh Nandgaonkar
47a55b0f26 Migrate BaseDevice from js to tsx
Summary: As per the title

Reviewed By: passy

Differential Revision: D16687261

fbshipit-source-id: a9d85424fb0a08fada7edd0355c356907518d366
2019-08-09 06:56:54 -07:00
Daniel Büchele
64cefd0f84 migrate redux store
Summary: Migrating redux stores to TypeScript

Reviewed By: passy

Differential Revision: D16579796

fbshipit-source-id: e3e507f17f1bdd57eb45e30cb0b28aaee6c4521c
2019-08-08 08:07:21 -07:00
Pascal Hartig
6a43b0cc88 Revert D16648356: Migration of Basedevice from js to tsx
Differential Revision:
D16648356

Original commit changeset: 12954532acf9

fbshipit-source-id: 76754f427e7ccac0f0b0030c3a0af02d036c1a8b
2019-08-06 08:50:32 -07:00
Pritesh Nandgaonkar
604e6d761f Migration of Basedevice from js to tsx
Summary: Converted BaseDevice from js to tsx

Reviewed By: passy

Differential Revision: D16648356

fbshipit-source-id: 12954532acf91930ab8c5f995bb94f6f9fe44015
2019-08-06 05:12:20 -07:00
Pritesh Nandgaonkar
e7198040ea Add UI to select plugins
Summary: Adds UI to the select the plugin to export. It lists the plugins which has currently some data in the redux store and it also lists those plugins which has implemented `exportPersistedState` function, as it might happen that the redux store may not have the data for a plugin but it will still export the data by calling `exportPersistedState`, which will ping the mobile client to get the data at point while we export the flipper trace.

Reviewed By: jknoxville

Differential Revision: D16468408

fbshipit-source-id: 452a7caf7199dd2b8df330bbb10d0a90008e92ec
2019-07-26 10:53:27 -07:00
Pritesh Nandgaonkar
e8a8f87086 Adds capability to select plugins for which the data would be exported
Summary: This diff adds `selectedPlugins` property in the redux store. With this diff now you can pass the list of plugins to headless so that it exports only the selected plugin's data

Reviewed By: passy

Differential Revision: D16280167

fbshipit-source-id: b03a1c49a7f51547470e0bcfa43083e52efabdd0
2019-07-19 07:02:39 -07:00
Pritesh Nandgaonkar
7f2709e1a5 Add close button to the export share sheet
Summary: Adds close button to the dialog box which appears while exporting a flipper trace. To implement this I had to first see what is the bottle neck of the export process. The major bottle neck turned out to be the serialization step. So to make the export process interruptible, I have put in a call `await idler.idle()` which resolves when the main thread is idle. I have also added the tests for the idler.

Reviewed By: passy

Differential Revision: D16183582

fbshipit-source-id: 4ec0c985e216fd9d41e91cdcd8b4cca66d2cb04d
2019-07-15 04:01:44 -07:00
Pascal Hartig
c588b650ae Prefer const wherever possible
Summary:
Non-final identifiers make code harder to understand.
This is particularly true for JavaScript where even the *type*
can change as a value gets reassigned later.

This enforces to use `const` whereever possible, but doesn't
"outlaw" `let`. Mixed destructuring is also still allowed.

Used `eslint --fix` to change all existing cases.

Reviewed By: jknoxville

Differential Revision: D16131329

fbshipit-source-id: 2eceaca7c603b71b36e005be5d135e1849f2518d
2019-07-10 03:28:25 -07:00
Pascal Hartig
662db20948 Disallow var
Summary: We're ES6 and `var`s scoping rules are weird. Let's block this.

Reviewed By: jknoxville

Differential Revision: D16131290

fbshipit-source-id: ba67d16bb8a185a4bb59a657a97b00230dbacafe
2019-07-10 03:28:25 -07:00
John Knox
2f5f69a2c8 Print success message to stderr after headless
Summary: Adding some verbose logging for remote debugging during integrations.

Reviewed By: passy

Differential Revision: D16039055

fbshipit-source-id: 963e0be5ac1526badbd71b9ef2f4906bec2f13ed
2019-06-28 02:52:47 -07:00
John Knox
34f835ace8 More exit handling fixes
Summary:
Line 166 is missing a process.exit() causing the process to stay open forever if anything goes wrong.

Making everything use errorAndExit, and making use of the utility function so we don't need to remember when to print e, and when to print e.message.

Reviewed By: passy

Differential Revision: D15989164

fbshipit-source-id: c683fa07d98fe49283a59b5f8108ef54babc97a3
2019-06-26 09:17:56 -07:00
Pritesh Nandgaonkar
cad26c9319 Refactor headless start function
Summary: Refactors the headless to have a list of closures instead of the `if` conditions. This will make addition of new arguments easy as it will be just adding a new closure to the list. One can change the order of the execution of the closures by inserting it at whatever index the user wants.

Reviewed By: passy

Differential Revision: D15965142

fbshipit-source-id: e9f348fe9d9011adcd47d140713d6187eab3b3d3
2019-06-25 04:59:44 -07:00
Pritesh Nandgaonkar
e5294d34f0 Plugin name list
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
2019-06-17 06:18:45 -07:00
John Knox
a82934490e Fix process exit when error occurs
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
2019-06-14 05:21:01 -07:00
John Knox
92edb82e13 Exit cleanly after flushing stdout
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
2019-06-06 01:59:08 -07:00
Pascal Hartig
eba84a7e08 Reorganize CLI arguments
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
2019-06-04 07:50:35 -07:00
Pritesh Nandgaonkar
95fae7d4e8 Call exportState function before exporting metrics
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
2019-06-03 15:06:30 -07:00
Pritesh Nandgaonkar
b5bda8dfae Refactor the startFlipper function
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
2019-05-30 10:16:47 -07:00
Pritesh Nandgaonkar
bab2aaaf0e Select device in headless
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
2019-05-30 08:33:43 -07:00
Pritesh Nandgaonkar
c94c2c8455 Add list-devices option to list the available devices.
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
2019-05-29 09:54:38 -07:00
Pritesh Nandgaonkar
89ebb11520 Accept Trace file and export a metric
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
2019-05-17 03:13:48 -07:00
Pritesh Nandgaonkar
afd729deb6 Added metrics argument to headless inorder to export metrics
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
2019-04-25 07:41:34 -07:00
Pritesh Nandgaonkar
830c8067e4 Timeout promise while exporting flipper plugin
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
2019-04-04 04:20:15 -07:00
Pascal Hartig
b20d0a4c8b Add headless option to dump on disconnect
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
2019-03-28 06:53:57 -07:00
Daniel Büchele
8b91ec68a7 Catch error on export
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
2019-03-19 07:23:29 -07:00
Pritesh Nandgaonkar
e184af7f2a fix the parsing error
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
2019-03-15 09:49:31 -07:00
Pritesh Nandgaonkar
af317eed2b Export and import all the nodes
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
2019-02-28 09:40:50 -08:00
John Knox
8ff4c4f56d Remove duplicate Logger in headless/index.js
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
2019-02-14 09:23:41 -08:00
John Knox
c912dcaf48 Add isHeadless attribute to scribe messages
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
2019-02-12 08:29:20 -08:00
Daniel Büchele
cb6c7bb137 yargs add .argv to fix CLI
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
2019-02-08 09:14:45 -08:00
Pascal Hartig
74a726aaf9 Use yargs for non-headless Flipper args parsing
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
2019-02-05 04:49:38 -08:00
Daniel Büchele
3b75fb092b 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
2019-02-04 07:29:13 -08:00
Daniel Büchele
45d1a7b35c add command line options
Summary: Adding options for the CLI

Reviewed By: passy

Differential Revision: D13864405

fbshipit-source-id: 1900c32833c7d18a4806f2a839215b5b536cb44f
2019-02-04 07:29:13 -08:00
Daniel Büchele
db9bc985eb redirecting console to stderr
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
2019-02-04 07:29:13 -08:00
Daniel Büchele
5b68c59b5c package bundle
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
2019-02-04 07:29:13 -08:00
Daniel Büchele
dab50ec5c4 add headless entry point
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
2019-01-25 12:19:07 -08:00