Browse Source

Improve documentation (#392)

Improve documentation and installation process.
Jérémie Pardou-Piquemal 2 years ago
parent
commit
61707b0673

+ 1 - 1
.github/workflows/cypress.yml

@@ -11,7 +11,7 @@ jobs:
       - name: Setup Node
         uses: actions/setup-node@v2
         with:
-          node-version: 14
+          node-version: 16
 
       - name: Checkout
         uses: actions/checkout@v2

+ 1 - 1
.github/workflows/lint-deploy.yml

@@ -12,7 +12,7 @@ jobs:
         
       - uses: actions/setup-node@v2
         with:
-          node-version: 14
+          node-version: 16
 
       - run: npm ci
       - run: npm run lint  

+ 1 - 1
.nvmrc

@@ -1 +1 @@
-14
+16

+ 0 - 0
Licence.md → LICENSE.md


+ 13 - 95
README.md

@@ -24,7 +24,7 @@ do with a real table. You share a common space with other players like if you we
 If you move something or if you flip a card, other players see
 this action and can respond in real time.
 
-Hint: you really should use an audio conference application to speak with other players.
+Hint: you really should use an audio conference application to speak with other players.
 
 Airboardgame doesn't force you, you make the rules.
 Airboardgame is just a game table simulator : what you would do with a real
@@ -61,14 +61,14 @@ Airboardgame is not only designed to play games but also to create them.
 In just few minutes you can create simple games without any
 development skills and play with your friends.
 
-Wants to test a concept? Play a Print & Play game? Use airboardgame without
-the need for more hardware.
+You want to test a concept? Try a print & play game? You can use Airboardgame
+without the need for more hardware.
 
 The only limit is your imagination.
 
-To access this features, login then click on the « create new game » button on home page.
+To access this features, login then click on the « Create new game » button on home page.
 
-We want Airboardgame to be simple, intuitive and a consistent web application.
+We want Airboardgame to be simple, intuitive web application.
 Just give a try and if you like it share it and contribute.
 
 You can create a game with simple actions :
@@ -80,6 +80,7 @@ You can create a game with simple actions :
   * Note,
   * Counter,
   * Image that can represent cards, board, token, perks, …
+  * Pre-made items
   * …
 * Choose board size
 * Add available items not on the board but in the "game box" like extension or material for more user.
@@ -90,95 +91,12 @@ You can drag'n'drop image from your desktop to the board to use them in Airboard
 
 * Open source web application,
 * Made with React and Socket.io,
-* Use recoiljs as state management,
-* Client to client driven architecture.
-  
-## Installation instructions
+* Use Recoiljs as state management,
+* Client to client driven architecture,
+* Use Ricochet.js as backend framework.
 
-This is the procedure to install AirBoarGame application from scratch for
-development purpose.
-You need a recent node version. You can (and should) use [nvm](https://github.com/nvm-sh/nvm)
-to initialize your environment.
+## Developper documentation
 
-### Backend
-
-First you need to install and start the server part of the application.
-The server code use [Ricochet.js](https://github.com/jrmi/ricochet.js). A local
-instance is installed and can be started but you can use your own instance.
-
-To proceed, execute:
-
-```sh
-cd backend
-npm ci
-cp .env.dist .env
-```
-
-You have the opportunity to modify Ricochet.js configuration now by editing this
-file. Default values should be fine for test but remember that data are only kept in
-memory so you loose all your changes each time you restart the ricochet server
-with this default. You also must to register again your site.
-See [Ricochet.js](https://github.com/jrmi/ricochet.js) documentation for more
-options and how to make data to persist.
-
-Now you can start the ricochet server:
-
-```sh
-npm run ricochet
-```
-
-Then you must create the Airboardgame ricochet site by visiting your ricochet
-server URL with a browser and fill the site creation form. Default Ricochet
-server URL if you didn't modify configuration should be `http://localhost:4050/`.
-
-The only important value here is `site Id` that should have the `airboardgame`
-value.
-
-Since the form is submitted, save the key from the server response and customize
-`.env` file using this key to set the `RICOCHET_SITE_KEY`.
-
-Remember to confirm the site creation by clicking the link displayed in Ricochet.js
-sever logs if you use the default configuration for SMTP.
-
-Now, you should start backend code modifications monitoring to generate
-code executed by Ricochet.js in another terminal:
-
-```sh
-npm run watch
-```
-
-you also need an instance of `wire.io` so in another terminal, execute:
-
-```sh
-# /!\ Need npm >= v7
-PORT=4051 npx wire.io
-```
-
-See [wire.io](https://github.com/jrmi/wire.io) documentation for more information
-on how to configure it.
-
-### Client
-
-In another terminal, go back to project root and execute:
-
-```sh
-cd <project_root>/
-npm ci
-cp .env.dist .env
-```
-
-Edit the `.env` file to fit your needs. Default should be fine if you didn't
-modify server configuration.
-
-Then you can start the client:
-
-```sh
-npm start
-```
-
-Now you should have four terminals:
-
-* the one with Ricochet.js server instance. Backend logs can be found here
-* one terminal with auto build on change for backend files
-* another with `wire.io` server running
-* and a last one with React frontend server
+* [Installation instructions](docs/dev.md)
+* [Deploy your own instance](docs/dev.md)
+* [Contributing guide](docs/dev.md)

+ 42 - 20
backend/.env.dist

@@ -1,39 +1,61 @@
-# Secret key generated by Ricochet.js. This is the key issued when you created the site.
-RICOCHET_SITE_KEY=
-
-# --- Ricochet configuration start here
+# --- Ricochet configuration start here
 
+# Ricochet server port and host
+# Change this if you need external access
 SERVER_PORT=4050
 SERVER_HOST=localhost
 
-# memory, disk or s3 storage are available
-FILE_STORAGE=memory
+# Configure the JSON store backend
+# Available backends: memory, nedb, mongodb
+# Use nedb or mongodb for persistent storage
+# Memory store is lost when the server is stopped
+JSON_STORE_BACKEND=memory
 
-# S3 storage configuration
-S3_ACCESS_KEY=
-S3_SECRET_KEY=
-S3_ENDPOINT=
-S3_BUCKET=
+# Uncomment if you use the nedb store backend
+#NEDB_DIRNAME=/path/to/data # Any path where Nedb databases will be stored
 
-# Only for testing purpose
-S3_BUCKET_TEST=test-bucket-001
+# Uncomment if you use the mongodb JSON store backend
+#MONGODB_URI=
+#MONGODB_DATABASE=
 
-# memory or nedb store backend
-STORE_BACKEND=memory
+# Configure the file store backend
+# Available backend: memory, disk or s3
+# Memory store is lost when the server is stopped
+FILE_STORE_BACKEND=memory
 
-NEDB_BACKEND_DIRNAME=/path/to/data # Any path where nedb databases will be kept
+# Disk file storage configuration
+# Uncomment for 'disk' file storage
+#DISK_DESTINATION=/path/to/dir/
 
+# S3 storage configuration
+# Uncomment the following lines if you want to use 's3' backend storage
+#S3_ACCESS_KEY=
+#S3_SECRET_KEY=
+#S3_ENDPOINT=
+#S3_BUCKET=
+#S3_REGION=
+#S3_PROXY=
+#S3_CDN=
+#S3_SIGNED_URL=
+
+# Should be a unique long key here
 RICOCHET_SECRET=YourSuperSecretHere
 
 # Smtp server configuration
+# If you let the fake host, sent mails are displayed in the console.
 EMAIL_HOST=fake
 EMAIL_PORT=
 EMAIL_USER=
 EMAIL_PASSWORD=
 EMAIL_FROM=
 
-# Webconference Openvidu configuration
-# See https://docs.openvidu.io for more information
+# --- Ricochet configuration ends here
+
+# Wire.io port configuration
+WIREIO_PORT=4051
+
+# Secret key generated by Ricochet.js when you've registered the site.
+RICOCHET_SITE_KEY=
 
-OPENVIDU_URL=
-OPENVIDU_SECRET=
+# To show better logs set to 1 (then use npm run ricochetjs:pino)
+USE_PINO=0

File diff suppressed because it is too large
+ 9722 - 1
backend/package-lock.json


+ 9 - 3
backend/package.json

@@ -10,7 +10,11 @@
     "dev": "npm run serve",
     "tunnel": "webpack serve --config webpack.tunnel.js",
     "build": "webpack --config webpack.production.js",
-    "ricochet": "USE_PINO=1 ricochetjs | pino-tiny"
+    "all": "concurrently \"npm:ricochetjs\" \"npm:wire.io\" \"npm:watch\"",
+    "wire.io": "npx wire.io@latest",
+    "ricochetjs:pino": "ricochetjs | pino-tiny",
+    "ricochetjs": "ricochetjs",
+    "ricochet": "npm run ricochetjs"
   },
   "author": "",
   "license": "ISC",
@@ -19,19 +23,21 @@
     "@babel/preset-env": "^7.14.4",
     "babel-loader": "^8.2.2",
     "clean-webpack-plugin": "^3.0.0",
-    "copy-webpack-plugin": "^7.0.0",
+    "concurrently": "^7.0.0",
     "dotenv-webpack": "^7.0.2",
     "localtunnel-webpack-plugin": "^1.0.0",
     "pino-tiny": "^1.1.2",
-    "ricochetjs": "^1.3.1",
+    "ricochetjs": "^1.3.2",
     "transform-loader": "^0.2.4",
     "webpack": "^5.38.1",
     "webpack-cli": "^4.7.0",
     "webpack-dev-server": "^3.11.2"
   },
   "dependencies": {
+    "@seald-io/nedb": "^2.2.0",
     "btoa": "^1.2.1",
     "dotenv": "^8.2.0",
+    "mongodb": "^3.7.3",
     "node-fetch": "^2.6.1"
   }
 }

+ 0 - 4
backend/public/config.json

@@ -1,4 +0,0 @@
-{
-  "siteId": "airboardgame",
-  "scriptBase": "/"
-}

+ 4 - 10
backend/webpack.common.js

@@ -4,12 +4,14 @@ require("dotenv").config({
 });
 const EncryptPlugin = require("ricochetjs").EncryptPlugin;
 const Dotenv = require("dotenv-webpack");
-const CopyPlugin = require("copy-webpack-plugin");
 
 const SECRET_KEY = process.env.RICOCHET_SITE_KEY;
 
 if (!SECRET_KEY) {
-  console.log("You must define a RICOCHET_SITE_KEY env variable");
+  console.log(
+    "You must define a RICOCHET_SITE_KEY env variable.\n" +
+      "If you don't have any key, please visit the Ricochet.js admin panel to create one."
+  );
   process.exit(-1);
 }
 
@@ -26,14 +28,6 @@ module.exports = {
   },
   plugins: [
     new Dotenv(),
-    new CopyPlugin({
-      patterns: [
-        {
-          from: "**/*",
-          context: path.resolve(__dirname, "public"),
-        },
-      ],
-    }),
     new EncryptPlugin({
       key: SECRET_KEY,
     }),

+ 243 - 0
docs/dev.md

@@ -0,0 +1,243 @@
+# Developper documentation
+
+Developper documentation is currently poor but don't hesitate to help writing it.
+
+# Installation instructions
+
+This is the procedure to install AirBoarGame application from scratch for
+to initialize your development environment, or simply to have the system in
+your own machine / server and host games or play.
+
+AirBoarGame application contains two parts:
+
+- a **server part (named Backend)**
+- and a **client part**.
+
+## Prerequisite
+
+1. You need **Node.js** >= v16 with **npm** >= v7. For that, you can (and should)
+  use [nvm](https://github.com/nvm-sh/nvm) to install and manage your Node.js environment.
+  Execute `nvm use` in project root folder to start the right environment.
+
+2. You need to download the last version of AirBoardGame [source code](https://github.com/jrmi/airboardgame)
+  into a local folder. You can get it:
+
+- By downloading the source [zip file](https://github.com/jrmi/airboardgame/archive/refs/heads/master.zip) and decompress it into a local folder.
+- By cloning it with git : `git clone git@github.com:jrmi/airboardgame.git`. You may need to create a github account to proceed this way.
+
+## Backend 1/2 - start and configure Ricochet.js server
+
+First, you need an up and running instance of [Ricochet.js](https://github.com/jrmi/ricochet.js)
+server. You can create yours by following the instructions in this section or you can
+use any existing instance.
+
+To start a local instance, execute:
+
+```sh
+cd backend
+npm ci # install dependencies
+cp .env.dist .env
+```
+
+Now, you have the opportunity to customize Ricochet.js configuration by editing the
+`.env` file. Default values should be fine for quick testing purpose but remember
+that data are only stored in memory so you'll loose
+all your changes each time you stop the ricochet.js server with these defaults.
+
+Don't try to fill the `RICOCHET_SITE_KEY` already because you need to register the
+Airboardgame site before, but you might want to change the `STORE_BACKEND`
+and `FILE_STORE` here to persist data.
+
+Here's an example configuration to persist data locally:
+
+```sh
+FILE_STORE_BACKEND=disk
+DISK_DESTINATION=/path/to/directory/
+
+JSON_STORE_BACKEND=nedb
+NEDB_DIRNAME=/path/to/nedb/database
+```
+
+The two configured paths should be existing and have write permissions for current user.
+
+See [Ricochet.js](https://github.com/jrmi/ricochet.js) documentation for more
+options.
+
+Now you can start the ricochet.js server:
+
+```sh
+npm run ricochetjs
+```
+
+Then create the Airboardgame Ricochet site by visiting your ricochet.js
+server URL with a browser and fill the site creation form. Default Ricochet
+server URL, if you haven't modified the configuration should be `http://localhost:4050/`.
+
+This is a 3 step process:
+
+1) Fill the site creation form with valid data
+2) Validate the form and save the secret site key for later use
+3) Visit the confirmation link to activate the site
+
+### Step 1 - Fill the site creation form
+
+The only important value here is `Site id` that should have the `airboardgame`
+value.
+
+Here's an example:
+
+![form](./siteCreation.png)
+
+### Step 2 - Validate the form and save the site secret key
+
+Submit the form by clicking the *create site* button.
+
+![form](./siteCreationSuccess.png)
+
+Since the form is submitted, save the displayed key and customize
+`.env` file using this key to set the `RICOCHET_SITE_KEY`.
+
+### Step 3 - Activate the site by clicking the confirmation link
+
+Remember to confirm the site creation by clicking the link sent by Ricochet.js to
+the owner email. If your are using a local instance of ricochet with the `fake`
+server email (should be the default configuration) the mail is displayed in the
+ricochet.js console.
+
+![email](./siteCreationEmail.png)
+
+Otherwise ensure you have given a valid email address and
+check the spam if you don't receive the email.
+
+Now you can stop the ricochet.js server (we are going to start it with the rest
+of the stack in the next step) by using `ctrl+c` in the server shell.
+
+## Backend 2/2 - Start the backend stack
+
+To start the stack just execute:
+
+```sh
+npm run all
+```
+
+Actually, this command launch 3 other commands:
+
+- `npm run ricochejs` for the Ricochet.js server
+- `npx wire.io@latest` for the realtime [wire.io](https://github.com/jrmi/wire.io) websocket relay
+- `npm run watch` that watch for backend code modifications to build the backend `ricochet.json` file.
+
+If you need more informations or more flexibility you might want to visit *More details on server* section.
+
+In the next section your going to start the web client that connect to this server part.
+
+## Client
+
+In another terminal, go back to project root and execute:
+
+```sh
+cd <project_root>/
+npm ci
+cp .env.dist .env
+```
+
+Customize the `.env` file. Default should be fine if you haven't modified
+server configuration host and port.
+
+Then you can start the client:
+
+```sh
+npm start
+```
+
+The last command should open the frontend URL in your browser.
+
+Now you should have two terminals:
+
+- first with:
+  - the Ricochet.js server. Backend logs can be found here.
+  - a `wire.io` server running
+  - and the auto build on change for airboardgame backend files
+- and another with web-frontend server
+
+# (Optionnal) More details on server
+
+When you start the backend part of Airboardgame, you need to start 3 commands.
+You can start all by using the `npm run all` command but sometimes you may want
+more control over how everything is working, for deployment or debugging. In this
+section you'll find a quick explanation of each command.
+
+## Ricochet.js server
+
+You can start the `Ricochet.js` server by executing:
+
+```sh
+npm run ricochetjs
+```
+
+If you need more details on `Ricochet.js` please visit the
+[project page](https://github.com/jrmi/ricochet.js).
+
+## Watch & build the backend Airboargame code
+
+You can start backend code modifications monitoring to generate
+code executed by Ricochet.js from the `backend/` directory:
+
+```sh
+npm run watch
+```
+
+You also can generate the backend code once by executing:
+
+```sh
+npm run build
+```
+
+These two commands generate the `public/ricochet.json` file that is executed
+on Ricochet.js server. This is the actual Airboardgame specific backend code.
+
+## Start wire.io socket.io server relay
+
+To allow real time communication between clients, you need to start an
+instance of [wire.io](https://github.com/jrmi/wire.io) server.
+
+To proceed, execute in the `backend/` directory:
+
+```sh
+# /!\ Need npm >= v7
+npx wire.io@latest
+```
+
+See [wire.io](https://github.com/jrmi/wire.io) documentation for more information
+on how to configure it if you need more options.
+
+# Launch e2e tests
+
+Execute the following command:
+
+```sh
+npm run cypress:open
+```
+
+This open the [Cypress](https://www.cypress.io/) console.
+
+# Deploy a production instance
+
+Section in progress...
+
+To deploy an instance in production you need to deploy the same stack as in dev.
+
+- You need a Ricochet.js instance.
+- You need a Wire.io instance.
+- Build the backend `ricochet.json` file.
+- Build the frontend and deploy it to a CDN.
+
+# Contributing guide
+
+Section in progress...
+
+## Z-index stack
+
+- 250 -> 299 : Top UI element like modals, Color selector, ...
+- 200 -> 249 : over items like navbar, side panels, selector, cookie notice, bottom button bar...
+- 100 -> 199 : items zone. All items on the board have these values
+- 0 -> 99 : underlay like board, background, ...

BIN
docs/siteCreation.png


BIN
docs/siteCreationEmail.png


BIN
docs/siteCreationSuccess.png


File diff suppressed because it is too large
+ 13690 - 1
package-lock.json


+ 3 - 2
package.json

@@ -49,8 +49,8 @@
     "prettier": "prettier --write src/",
     "server": "echo 'This command is deprecated. Please, see Readme for more information.'",
     "i18n:scanner": "i18next-scanner --config i18next-scanner.config.js 'src/**/*.{js,jsx}'",
-    "cypress:open": "VITE_CI=1 LANGUAGE=en cypress open",
-    "cypress:run": "VITE_CI=1 LANGUAGE=en cypress run"
+    "cypress:open": "cross-env VITE_CI=1 LANGUAGE=en cypress open",
+    "cypress:run": "cross-env VITE_CI=1 LANGUAGE=en cypress run"
   },
   "browserslist": {
     "production": [
@@ -74,6 +74,7 @@
     "@testing-library/user-event": "^13.1.9",
     "@vitejs/plugin-react-refresh": "^1.3.3",
     "@welldone-software/why-did-you-render": "^6.1.4",
+    "cross-env": "^7.0.3",
     "cypress": "^7.1.0",
     "dotenv": "^10.0.0",
     "eslint": "^7.27.0",

+ 7 - 0
vite.config.js

@@ -38,6 +38,13 @@ const checkDeprecatedVars = () => {
 
 checkDeprecatedVars();
 
+if (!siteId) {
+  console.log(
+    "ERR! You must define a VITE_RICOCHET_SITEID environment variable."
+  );
+  process.exit(1);
+}
+
 let proxy = {};
 
 if (useProxy) {

Some files were not shown because too many files changed in this diff