From abbb2674828214be61cee5758814d297ce88447d Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Mon, 23 May 2022 08:06:18 -0700 Subject: [PATCH] Implement headless tic-tac-toe CLI Summary: Add a CLI app to play tic-tac-toe from the terminal. Reviewed By: lblasa Differential Revision: D36548528 fbshipit-source-id: 4cdfb9d8887cb0d4d0100a822f39a4f9fb25aa9b --- desktop/examples/headless-tic-tac-toe/README.md | 17 +++++++++++++++++ desktop/examples/headless-tic-tac-toe/index.js | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 desktop/examples/headless-tic-tac-toe/README.md diff --git a/desktop/examples/headless-tic-tac-toe/README.md b/desktop/examples/headless-tic-tac-toe/README.md new file mode 100644 index 000000000..44b5f3ad7 --- /dev/null +++ b/desktop/examples/headless-tic-tac-toe/README.md @@ -0,0 +1,17 @@ +# headless-tic-tac-toe + +**Experimental feature!** + +Flipper can run plugins in a headless mode - expose their API over the wire. This is an example of how it might look like. + +## Quick start + +0. Clone [Flipper repo](https://github.com/facebook/flipper) +0. Navigate to `/desktop` folder. +0. Run `yarn` +0. Run `yarn flipper-server` +0. Start you mobile device (or any other device that supports Flipper). +0. Open your app that supports "ReactNativeTicTacToe" plugin (for instance, [React Native Example app](https://github.com/facebook/flipper/tree/main/react-native/ReactNativeFlipperExample)). +0. In a different terminal window, navigate to `/desktop/examples/headless-demo` +0. Run `yarn` +0. Run `yarn start` diff --git a/desktop/examples/headless-tic-tac-toe/index.js b/desktop/examples/headless-tic-tac-toe/index.js index 86757606c..37790d5de 100644 --- a/desktop/examples/headless-tic-tac-toe/index.js +++ b/desktop/examples/headless-tic-tac-toe/index.js @@ -7,8 +7,18 @@ * @format */ +const {TicTacToeClient} = require('./ticTacToeClient'); + const main = async () => { - // TODO: Implement me + const ticTacToeClient = new TicTacToeClient(); + await ticTacToeClient.init(); + + const targetClientId = await ticTacToeClient.selectClient(); + await ticTacToeClient.startTicTacToePlugin(targetClientId); + ticTacToeClient.startGame(targetClientId); }; -main().catch(console.error); +main().catch((e) => { + console.error('main -> error', e); + process.exit(1); +});