---
version: '3'

vars:
  ROWY_HOMEPAGE: https://megabyte.space/tables
  ROWY_PATH: ./rowy
  ROWY_SLUG: tables

tasks:
  rowy:build:
    deps:
      - :install:npm:browserslist
      - :install:software:yarn
    env:
      REACT_APP_FIREBASE_PROJECT_ID:
        sh: jq -r '.blueprint.firebase.projectId' package.json
      REACT_APP_FIREBASE_PROJECT_WEB_API_KEY:
        sh: jq -r '.blueprint.firebase.webApiKey' package.json
    cmds:
      - mkdir -p "$(dirname '{{.ROWY_PATH}}')"
      - git clone https://github.com/rowyio/rowy.git {{.ROWY_PATH}}
      - cd {{.ROWY_PATH}} && yarn
      - browserslist --update-db
      - |
        TMP="$(mktemp)"
        jq --arg rowy '{{.ROWY_HOMEPAGE}}' '.homepage = $rowy' {{.ROWY_PATH}}/package.json > "$TMP"
        mv "$TMP" {{.ROWY_PATH}}/package.json
      - cd {{.ROWY_PATH}} && yarn build
      - mv {{.ROWY_PATH}}/build dist/{{.ROWY_SLUG}}
