Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Playground frontend in React #352

Merged
merged 28 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on: push

jobs:
build:
setup:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -21,26 +21,50 @@ jobs:
name: tweag-topiary
authToken: "${{ secrets.CACHIX_TWEAG_TOPIARY_AUTH_TOKEN }}"

native:
needs: setup
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Clippy, test, and benchmark
run: nix -L flake check

- name: Build and test executable
run: 'echo \{ \"foo\": \"bar\" \} | nix run . -- -l json'

- name: Build web playground
run: nix build .#web-playground
website:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Build web playground Wasm app
run: nix build .#wasm-app

- name: Copy web playground Wasm app into playground frontend
run: |
mkdir -p web-playground/react-app/src/wasm-app
cp -r result/* web-playground/react-app/src/wasm-app/

- name: Install web playground frontend dependencies
run: npm install --prefix web-playground/react-app

- name: Build web playground frontend
run: npm run build --prefix web-playground/react-app

- name: Copy web playground into website
run: cp -r result website/playground/wasm-app
- name: Copy playground into website
run: |
rm -rf website/playground
cp -r web-playground/react-app/build website/playground

- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v1.0.7
if: success() && matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/main'
if: success() && github.ref == 'refs/heads/main'
with:
path: 'website'

deploy:
needs: build
needs: website
if: github.ref == 'refs/heads/main'

permissions:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ target
/result
/.envrc
/.direnv
/website/playground/wasm-app
*.profraw
17 changes: 16 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The web site should then be running on http://localhost:8080.
In order to build or update the Wasm playground, you can run this:

```bash
./update-web-playground.sh
./update-wasm-app.sh
```

If you need to add or update Tree-sitter grammar Wasm files, you can do it like
Expand All @@ -84,3 +84,18 @@ this (using JSON as an example):
to copy some directories (you also have to move a `common` directory).
6. npx tree-sitter build-wasm node_modules/tree-sitter-json
7. mv tree-sitter-json.wasm website/playground/scripts/

The playground frontend is a small React app. You can run a development server for that like this:

```bash
cd web-playground/react-app
npm start
```

If you want to build the playground so it works with the full website running with Deno as above,
you can do:

```bash
cd web-playground/react-app
npm run build
```
8 changes: 4 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let
"languages"
"src"
"tests"
"web-playground"
"web-playground/wasm-app"
];
};

Expand Down Expand Up @@ -77,9 +77,9 @@ in
'';
});

web-playground = craneLibWasm.buildPackage (commonArgs // {
wasm-app = craneLibWasm.buildPackage (commonArgs // {
inherit cargoArtifacts;
cargoExtraArgs = "--manifest-path=web-playground/Cargo.toml --target ${wasmTarget}";
cargoExtraArgs = "--manifest-path=web-playground/wasm-app/Cargo.toml --target ${wasmTarget}";

# Tests currently need to be run via `cargo wasi` which
# isn't packaged in nixpkgs yet...
Expand All @@ -90,7 +90,7 @@ in
rm -rf $out/lib
echo 'Running wasm-bindgen'
wasm-bindgen --version
wasm-bindgen --target web --out-dir $out web-playground/target/wasm32-unknown-unknown/release/topiary_playground.wasm;
wasm-bindgen --target web --out-dir $out web-playground/wasm-app/target/wasm32-unknown-unknown/release/topiary_playground.wasm;
echo 'Running wasm-opt'
wasm-opt --version
wasm-opt -Oz -o $out/output.wasm $out/topiary_playground_bg.wasm
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
in
{
packages = with code; {
inherit web-playground;
inherit wasm-app;
default = app;
};
checks = with code; {
Expand Down
7 changes: 5 additions & 2 deletions src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ impl Language {
};

Ok(join_all(language_names.iter().map(|name| async move {
web_tree_sitter::Language::load_path(&format!("scripts/tree-sitter-{}.wasm", name))
.await
web_tree_sitter::Language::load_path(&format!(
"/playground/scripts/tree-sitter-{}.wasm",
name
))
.await
}))
.await
.into_iter()
Expand Down
5 changes: 5 additions & 0 deletions update-wasm-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
nix build .#wasm-app
rm -rf web-playground/react-app/src/wasm-app
cp -r result web-playground/react-app/src/wasm-app
chmod -R +w web-playground/react-app/src/wasm-app
4 changes: 0 additions & 4 deletions update-web-playground.sh

This file was deleted.

23 changes: 23 additions & 0 deletions web-playground/react-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
46 changes: 46 additions & 0 deletions web-playground/react-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
Loading