on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

name: Webassembly demo

jobs:
  check_style:
    name: Check webassembly demo style
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Check code formatting
        run: npx prettier --check .

  build:
    name: Build webassembly demo
    runs-on: ubuntu-latest
    env:
      WASM_PACK_PATH: ~/.cargo/bin/wasm-pack
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
      - name: Install wasm-pack
        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
      - name: Cache npm build
        uses: actions/cache@v3
        with:
          path: |
            node_modules
            target
            ~/.cargo/git
            ~/.cargo/registry
            boa_wasm/pkg
          key: ${{ runner.os }}-npm-build-target-${{ hashFiles('**/package-lock.json') }}
      - uses: actions/setup-node@v3
        with:
          node-version: "16"
      - run: npm ci
      - run: npm run build
