version: "3"
vars:
  REGISTRY: registry.ma-al.com
  Version: "0.0.6"
  BuildDate: $(date +"%Y-%m-%d %H:%M")
  Company: Maal sp. z o.o.
  CompanyUrl: "https://www.ma-al.com"
  CompileStr: go build -ldflags "-s -w -X 'pocketbase/custom/version.Version={{.Version}}' -X 'pocketbase/custom/version.BuildDate={{.BuildDate}}' -X 'pocketbase/custom/version.Company={{.Company}}' -X 'pocketbase/custom/version.CompanyUrl={{.CompanyUrl}}'" -o ../.pocketbase/pocketbase .

tasks:
  default:
    cmds:
      - task --list
    silent: true

  # compile_musl:
  #   aliases: [cm]
  #   desc: "compiles pocketbase for musl"
  #   env:
  #     CGO_ENABLED: "0"
  #     GOOS: "linux"
  #     GOARCH: "amd64"
  #     CC: "x86_64-linux-musl-gcc"
  #   cmds:
  #     - |
  #       mkdir -p ./.output
  #       cd ./backend
  #       {{.CompileStr}}

  # compile_gnu:
  #   aliases: [cg]
  #   desc: "compiles pocketbase for gnu"
  #   env:
  #     CGO_ENABLED: "0"
  #     GOOS: "linux"
  #     GOARCH: "amd64"
  #   cmds:
  #     - |
  #       mkdir -p ./.output
  #       cd ./backend
  #       {{.CompileStr}}

  # build_run_gnu:
  #   aliases: [br]
  #   desc: "compiles pocketbase for gnu"
  #   env:
  #     CGO_ENABLED: "0"
  #     GOOS: "linux"
  #     GOARCH: "amd64"
  #   cmds:
  #     - |
  #       mkdir -p ./.output
  #       cd ./backend
  #       go build -ldflags "-s -w" -o ../.pocketbase/pocketbase .
  #       cd ..
  #       ./.pocketbase/pocketbase serve --dir=./backend/pb_data

  # watch_backend:
  #   aliases: [wb]
  #   desc: "watch backend and compile"
  #   cmds:
  #     - |
  #       cd ./backend
  #       pwd
  #       air -build.args_bin='serve --dir=./pb_data' -build.exclude_dir=pb_data,backups -build.include_ext=go

  watch_front:
    aliases: [wf]
    desc: "build and watch frontend in dev mode"
    cmds:
      - |
        pnpm run dev

  preview_front:
    aliases: [pf]
    desc: "build and preview frontend"
    cmds:
      - |
        pnpm run build && pnpm run preview

  rebuild_front:
    aliases: [rf]
    desc: "remove all and install all packages"
    cmds:
      - |
        rm -rf ./node_modules ./pnpm-lock.yaml ./.nuxt ./.output
        pnpm install

  # build_docker_image:
  #   aliases: [bdi]
  #   desc: "build docker image"
  #   cmds:
  #     - |
  #       pnpm run build
  #       task compile_gnu
  #       cat <<EOF > temp.Dockerfile
  #       FROM node:slim

  #       COPY ./.output /nuxt
  #       COPY ./.pocketbase/pocketbase /bin/
  #       RUN mkdir /data

  #       # ENTRYPOINT ["ash"]
  #       CMD ["pocketbase", "serve", "--dir=/data", "--proxy=http://localhost:3000", "--subcommand=node /nuxt/server/index.mjs", "--http=0.0.0.0:8090"]
  #       EOF
  #       docker build -t {{.REGISTRY}}/abrasive/abrasive:{{.Version}} -t {{.REGISTRY}}/abrasive/abrasive:latest -f temp.Dockerfile .
  #       rm temp.Dockerfile

  # push_docker_image:
  #   aliases: [pdi]
  #   desc: "push docker image to registry server"
  #   cmds:
  #     - |
  #       docker push {{.REGISTRY}}/abrasive/abrasive:{{.Version}}
  #       docker push {{.REGISTRY}}/abrasive/abrasive:latest
