#SHELL=/usr/bin/env bash

CLEAN:=
BINS:=
DATE_TIME=`date +'%Y%m%d %H:%M:%S'`
COMMIT_ID=`git rev-parse --short HEAD`
MANAGER_DIR=${PWD}
CONSOLE_CODE=/tmp/updsrv-frontend

build:
	rm -f updsrv
	go mod tidy && go build -ldflags "-s -w -X 'main.BuildTime=${DATE_TIME}' -X 'main.GitCommit=${COMMIT_ID}'" -o updsrv cmd/main.go
.PHONY: build
BINS+=updsrv

nodejs:
	curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - && sudo apt update && sudo apt install -y nodejs build-essential && sudo npm install -g yarn
.PHONY: nodejs

console:
	rm -rf ${CONSOLE_CODE} && git clone -b master https://git.jellydropsllc.com/updsrv-frontend.git ${CONSOLE_CODE}
	cd ${CONSOLE_CODE} && git log -2 && npm install && npm run build:prod
.PHONY: console

docker-test: build
	docker build --tag updsrv -f Dockerfile.test .
.PHONY: docker-test

docker:
	rm -f updsrv
	docker build --tag updsrv -f Dockerfile .
.PHONY: docker

# 检查环境变量
env-%:
	@ if [ "${${*}}" = "" ]; then \
	    echo "Environment variable $* not set"; \
	    exit 1; \
	fi

db2go:
	go install github.com/civet148/db2go@latest
.PHONY: db2go

models:
	cd pkg/dal/db2go && ./gen_models.sh

clean:
	rm -rf $(CLEAN) $(BINS)
.PHONY: clean
