-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from cardano-scaling/react-refactor
React refactor
- Loading branch information
Showing
157 changed files
with
4,376 additions
and
7,346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"*/**/*.{js,jsx,ts,tsx}": ["eslint --fix", "eslint"], | ||
"*/**/*.{json,css,md}": ["prettier --write"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
# Hydra Doom | ||
# React + TypeScript + Vite | ||
|
||
Experiment of running Doom using a [Cardano Hydra head](https://github.com/cardano-scaling/hydra). | ||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
## Manual startup | ||
Currently, two official plugins are available: | ||
|
||
This is using a forked version of [doom-wasm](https://github.com/cardano-scaling/doom-wasm), make sure to build it first and copy or symlink the build results: | ||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
``` shell | ||
cp ../doom-wasm/src/websockets-doom.js assets/websockets-doom.js | ||
cp ../doom-wasm/src/websockets-doom.wasm assets/websockets-doom.wasm | ||
cp ../doom-wasm/src/websockets-doom.wasm.map assets/websockets-doom.wasm.map | ||
``` | ||
|
||
Also, you need to copy the shareware version of [doom1.wad](https://doomwiki.org/wiki/DOOM1.WAD) to `./assets`: | ||
|
||
```shell | ||
curl https://distro.ibiblio.org/slitaz/sources/packages/d/doom1.wad -o assets/doom1.wad | ||
``` | ||
|
||
The application requires connection to a [hydra-control-plane](https://github.com/cardano-scaling/hydra-control-plane) which provides managed Hydra head instances provided as `SERVER_URL` in the `.env` file. | ||
|
||
Then to build & run: | ||
|
||
```shell | ||
npm install | ||
npm start | ||
``` | ||
## Expanding the ESLint configuration | ||
|
||
## Integrated startup | ||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
There is a way to start all required processes using `nix` and `process-compose`: | ||
- Configure the top-level `parserOptions` property like this: | ||
|
||
``` shell | ||
nix run | ||
```js | ||
export default tseslint.config({ | ||
languageOptions: { | ||
// other options... | ||
parserOptions: { | ||
project: ['./tsconfig.node.json', './tsconfig.app.json'], | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
## Persistent sessions | ||
|
||
If we want to keep using the same key and remote node configuration between runs, set the `PERSISTENT_SESSION=true` variable in the `.env` file before starting the dev web server. | ||
|
||
|
||
|
||
### Local Development | ||
|
||
To run the project locally (using the POO integration), you need to set a `CABINET_KEY` in the `.env` file. For example: | ||
|
||
```sh | ||
CABIENT_KEY=A610911D628D5475EFFBA5E80ED09D1260B49E6935C40E4195C4D4AA17963CBF | ||
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` | ||
- Optionally add `...tseslint.configs.stylisticTypeChecked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: | ||
|
||
```js | ||
// eslint.config.js | ||
import react from 'eslint-plugin-react' | ||
|
||
export default tseslint.config({ | ||
// Set the react version | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
// Add the react plugin | ||
react, | ||
}, | ||
rules: { | ||
// other rules... | ||
// Enable its recommended rules | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
}, | ||
}) | ||
``` |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import js from "@eslint/js"; | ||
import globals from "globals"; | ||
import reactHooks from "eslint-plugin-react-hooks"; | ||
import reactRefresh from "eslint-plugin-react-refresh"; | ||
import tseslint from "typescript-eslint"; | ||
import eslintConfigPrettier from "eslint-config-prettier"; | ||
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"; | ||
|
||
export default tseslint.config( | ||
{ ignores: ["dist"] }, | ||
{ | ||
extends: [ | ||
js.configs.recommended, | ||
...tseslint.configs.recommended, | ||
eslintPluginPrettierRecommended, | ||
], | ||
files: ["**/*.{ts,tsx}"], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
}, | ||
plugins: { | ||
"react-hooks": reactHooks, | ||
"react-refresh": reactRefresh, | ||
}, | ||
rules: { | ||
...reactHooks.configs.recommended.rules, | ||
...eslintConfigPrettier.rules, | ||
"react-refresh/only-export-components": [ | ||
"warn", | ||
{ allowConstantExport: true }, | ||
], | ||
"@typescript-eslint/no-explicit-any": "off", | ||
}, | ||
} | ||
); |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.