# dirs
ARCADIA_DIR := $(shell pwd | sed 's|/arcadia/.*|/arcadia|')

# tools
YA := $(ARCADIA_DIR)/ya
HOST ?= $(shell hostname)
REPO ?= "search-test"


help:
	echo "Known targets:"
	echo "   lint            - run linter to find potential bugs"
	echo "   test            - run test suites"
	echo "   build           - build distributable static files"
	echo "   analyze         - analyze bundle"
	echo "   get-deps        - update node_modules directory and yarn.lock file"
	echo "   run-web         - run local web server"
	echo "   run-web-remote  - run remote web server"
	echo "   storybook       - run storybook"
	echo "   upload-deps     - will update node_modules dir, build package and"
	echo "                     upload it to sandbox"
	echo "   deb             - build yandex-solomon-web package by"
	echo "                     default will upload it to search-test repo. Use"
	echo "                     REPO env variable to change it."

lint:
	yarn run lint

test:
	CI=1 yarn run test

storybook:
	yarn run storybook

build:
	yarn run build

analyze:
	yarn run analyze

run-web:
	yarn run start

run-web-local:
	HOST=localhost yarn run start

run-web-remote:
	HOST=$(HOST) yarn run start

get-deps:
	$(RM) -r node_modules
	yarn

upload-deps:
	if [ -z $(SANDBOX_TOKEN) ]; then \
		echo "Please, get the token from sandbox: https://sandbox.yandex-team.ru/oauth"; \
		echo "and then run: "; \
		echo "    $$ SANDBOX_TOKEN=<token> make $@"; \
		exit 1; \
	fi
	tar cfz node_modules.tar.gz node_modules
	$(YA) upload node_modules.tar.gz \
		--description "host: $(HOST), user: $(USER), pwd: $(PWD), date: $(shell date)" \
		--token $(SANDBOX_TOKEN) \
		--ttl inf
	$(RM) node_modules.tar.gz

# TODO: delete it after YA_PACKAGE task will work correctly
PKG := "yandex-solomon-web"
deb:
	$(RM) -r deb/
	mkdir deb/
	cd deb/ && $(YA) package --debian \
		$(ARCADIA_DIR)/solomon/packages/$(PKG)/pkg.json
	tar xvf deb/$(PKG).*.tar.gz -C deb/
	cd deb/ && dupload --to $(REPO) $(PKG)*.changes


.PHONY: help lint build run-web run-web-remote test storybook upload-deps deb

ifndef VERBOSE
.SILENT:
endif
