CodeMirror & PresetSelect fix (#413)

* yarn upgrade

* update eslint no-multiple-empty-lines rule

* update Next.js & React

Resolves #358.

* use CodeMirror in scratch editor

* use codemirror on new page

* move extensions out of CodeMirror component

* grow scratch codemirror

* fix state bug

* initial theming

* fix scratch page SSR

* fix credits page rendering

* max width for AsyncButton error popup

* word wrap

* bye monaco

* cleanup

* style scrollbars everywhere

* tab stuff

* updates

* more

* update codemirror theme

* new react, backend deps, preset on scratch, bugfixes

* improve monospace areas

* store preset name on scratch

* stylelint

* mypy

* mypy 2

* monospace

* fix monospace

* add padding to editor

* fix saving

* fix selection colours

* Highlight assembly line on source selected line change (#416)

Co-authored-by: Alex Bates <hi@imalex.xyz>

* mypy & black

* font stuff

* remove courier new

* make diff style consistent with editor

* fix codemirror exception when editing eof

* attempt to reduce layout thrashing

* /new: store presetName in localStorage

* use react-window for diff

* link diff column scroll position

* hide double scrollbar

* increase overscan

* pointer-events:none on diff header

* fix diff header thing

* make diff columns non-draggable

* dont shrink tabs

* add draggable bar between diff columns

* remove log

* fix 2-col mode

* fix diff align

* DiffCell support cell=undefined

* drag better

* style .cm-search

* eth style changes

* reduce rerenders when dragging diff bar

Co-authored-by: Alex Bates <hi@imalex.xyz>
Co-authored-by: hatal175 <hatal175@users.noreply.github.com>
Co-authored-by: Alex Bates <alex@nanaian.town>
This commit is contained in:
Ethan Roseman
2022-03-31 09:22:39 -04:00
committed by GitHub
parent 8ddf59b570
commit 8ea10ca286
61 changed files with 4770 additions and 5638 deletions
+119
View File
@@ -0,0 +1,119 @@
# Contributing
## Directory structure
```
frontend/
public/ ; Static files
src/ ; React/Typescript sourcecode
backend/
compilers/ ; Compiler binaries and configuration
coreapp/ ; API Django app
migrations/ ; Database migrations (generated by Django)
decompme/ ; Main Django app
.env ; Default configuration
.env.local ; Local configuration overrides (not checked-in)
```
## Setup
See [DOCKER.md](DOCKER.md) for instructions on how to run the project in a Docker container. Otherwise, continue reading this guide.
Dependencies:
- Python >=3.9
- Node.js
- [Yarn](https://yarnpkg.com/getting-started/install)
- [Poetry](https://python-poetry.org/docs/master/#installing-with-the-official-installer)
---
Create a file to hold environment variables:
```shell
touch .env.local
```
### Backend
```shell
cd backend
```
* Install Python dependencies with [poetry](https://python-poetry.org/docs/master/#installing-with-the-official-installer)
```shell
poetry install
```
- Install compilers
```shell
poetry run python compilers/download.py
```
- Set up the database
```shell
poetry run python manage.py migrate
```
- Start the API server
```shell
poetry run python manage.py runserver
```
---
### Frontend
```shell
cd frontend
```
- Install dependencies
```shell
yarn
```
- Start the development webserver
```shell
yarn dev
```
- Access the site via [http://localhost:8080](http://localhost:8080)
### Optional steps
- [Configure wine for Windows compiler on Linux](WINE.md)
- [Set up GitHub authentication](GITHUB.md)
- [Install nsjail to run the compiler sandbox](SANDBOX.md)
- [Configure an nginx reverse proxy](NGINX.md)
## Notes
### Updating the database
If you modify any database models (`models.py`), you'll need to run the following to update the database:
```shell
poetry run python manage.py makemigrations
poetry run python manage.py migrate
```
## Linting
- Check frontend
```shell
cd frontend
yarn lint
```
- Autofix frontend
```shell
cd frontend
yarn lint --fix
```
- Check backend
```shell
cd backend
mypy
```
### Storybook
Use `yarn storybook` to run a Storybook instance on [http://localhost:6006](http://localhost:6006). This is useful for testing UI components in isolation.
+44
View File
@@ -0,0 +1,44 @@
# Docker
There is a `docker-compose.yaml` file to help you spin up an instance quickly.
## Prerequisites:
### Docker
You will need [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/). Follow the instructions for your distro.
### Directories
You will need to create a directory for the `postgres` data in the base of the repo:
```sh
mkdir -p postgres
```
**Note:** This directory will get owned by `postgres` user when postgres first starts up!
## Quickstart
**Run in foreground:**
```sh
docker-compose up --build
```
The processes will run in the foreground until you CTRL+C to trigger a shutdown.
**Run daemonised:**
```sh
docker-compose up -d && docker-compose logs -f
```
You can CTRL+C to stop tailing logs. If you want to stop the processes then running `docker-compose down` will shut everything down.
**Note:** The first time you bring up the containers can take a minute or so - Docker has to pull/build images, grab Node dependencies, apply database migrations etc. Subsequent runs will be significantly faster to spin up.
## Configuration
By default the Docker `backend` image is built without PS1 and/or GC/Wii support. They can be enabled by changing the `ENABLE_PS1_SUPPORT` and/or `ENABLE_GC_WII_SUPPORT` variables to `"YES"` in the `docker-compose.yaml` and re-running the `docker-compose up --build` command.
+9
View File
@@ -0,0 +1,9 @@
### GitHub authentication
- [Register a new OAuth application](https://github.com/settings/applications/new)
- "Homepage URL" should be the URL you access the frontend on (e.g. `http://localhost:8080`)
- "Authorization callback URL" should be the same as the homepage URL, but with `/login` appended
- Edit `.env.local`:
- Set `GITHUB_CLIENT_ID` to the application client ID
- Set `GITHUB_CLIENT_SECRET` to the application client secret (do **not** share this)
+76
View File
@@ -0,0 +1,76 @@
### Running inside an nginx proxy
Running decomp.me using nginx as a proxy better emulates the production environment and can avoid cookie-related issues.
- Install nginx
- Create an nginx site configuration (typically `/etc/nginx/sites-available/decomp.local`)
```nginx
server {
listen 80;
listen [::]:80;
client_max_body_size 5M;
server_name decomp.local www.decomp.local;
location / {
try_files $uri @proxy_frontend;
}
location /api {
try_files $uri @proxy_api;
}
location /admin {
try_files $uri @proxy_api;
}
location /static {
try_files $uri @proxy_api;
}
location @proxy_api {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8000;
}
location @proxy_frontend {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8080;
}
location /_next/webpack-hmr {
proxy_pass http://127.0.0.1:8080/_next/webpack-hmr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
```
- Enable the site
```shell
ln -s /etc/nginx/sites-available/decomp.local /etc/nginx/sites-enabled/decomp.local
```
- Add the following lines to `/etc/hosts`:
```
127.0.0.1 decomp.local
127.0.0.1 www.decomp.local
```
- Edit `.env.local`:
- Set `API_BASE=/api`
- Set `ALLOWED_HOSTS=decomp.local`
- If you set up GitHub authentication, change the application URLs to `http://decomp.local` and `http://decomp.local/login`
- Restart nginx, the frontend, and the backend
- Access the site via [http://decomp.local](http://decomp.local)
+19
View File
@@ -0,0 +1,19 @@
### Sandbox jail
There is support for running subprocesses within [`nsjail`](https://github.com/google/nsjail).
This is controlled by the `SANDBOX` settings, and is disabled by default in the development `.env` but is enabled inside the `backend` Docker container.
To enable it locally outside of the Docker container:
- Build or install `nsjail` locally. Example instructions for Ubuntu:
- `apt-get install autoconf bison flex gcc g++ git libprotobuf-dev libnl-route-3-dev libtool make pkg-config protobuf-compiler`
- `git clone --recursive --branch=3.0 https://github.com/google/nsjail`
- `cd nsjail && make`
- Enable `unprivileged_userns_clone`
- Temporary: `sudo sysctl -w kernel.unprivileged_userns_clone=1`
- Permanent: `echo 'kernel.unprivileged_userns_clone=1' | sudo tee -a /etc/sysctl.d/00-local-userns.conf && sudo service procps restart`
- Edit `.env.local`:
- Set `USE_SANDBOX_JAIL=on`
- Set `SANDBOX_NSJAIL_BIN_PATH` to the absolute path of the `nsjail` binary built above
+10
View File
@@ -0,0 +1,10 @@
### Wine setup (for local development, running Windows compilers)
- Create a wineprefix dir
```shell
WINEPREFIX=$HOME/.wine WINEARCH=win32 wineboot --init
```
- Add the WINEPREFIX setting to your .local.env file in the root of the repo
```shell
echo "WINEPREFIX=$HOME/.wine" >> .local.env
```