GOPATH ?= $(shell echo $GOPATH)

# Ensure GOPATH is set before running build process.
ifeq "$(GOPATH)" ""
  OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
  WORKDIR := "/go/src/github.com/pingcap/tidb-enterprise/dashboard-ui"
  PWD := $(shell pwd)
  GO := docker run --rm -it -e CGO_ENABLED=0 -e GOOS=$(OS)  -w $(WORKDIR) -v $(PWD):$(WORKDIR) golang:1.10-alpine go
else
  GO := CGO_ENABLED=0 go
endif

default: build

setup:
	npm install -g yarn
	yarn install --fronzen-lockfile
	go get -u github.com/rakyll/statik

frontend:
	npm run build
	statik -f -src=build

build: frontend
	$(GO) build -o bin/dashboard-ui

.PHONY: setup frontend build
