HOOK_NAME=pre-push
HOOK_PATH=../.git/hooks/$(HOOK_NAME)

prehook:
	@echo "Setting up pre-push hook..."
	@rm -f $(HOOK_PATH)
	@echo '#!/bin/sh'								>> $(HOOK_PATH)
	@echo 'echo "Running lint for proxy-ui-app"'		>> $(HOOK_PATH)
	@echo 'cd ./proxy-ui-app'							>> $(HOOK_PATH)
	@echo 'yarn lint'						    	>> $(HOOK_PATH)
	@echo 'if [ $$? -ne 0 ]; then'					>> $(HOOK_PATH)
	@echo '  echo "Tests failed, push aborted."'	>> $(HOOK_PATH)
	@echo '  exit 1'								>> $(HOOK_PATH)
	@echo 'fi' 										>> $(HOOK_PATH)
	@echo 'echo "Running tests for proxy-ui"'		>> $(HOOK_PATH)
	@echo 'yarn test_ones'						  	>> $(HOOK_PATH)
	@echo 'if [ $$? -ne 0 ]; then'					>> $(HOOK_PATH)
	@echo '  echo "Tests failed, push aborted."'	>> $(HOOK_PATH)
	@echo '  exit 1'								>> $(HOOK_PATH)
	@echo 'fi' 										>> $(HOOK_PATH)
	@echo 'exit 0' 									>> $(HOOK_PATH)
	@chmod +x $(HOOK_PATH)
	@echo "Pre-push hook set successfully."

add:
ifeq ($(pack),)
	$(error mn is not set)
endif
	yarn add "../repo/${pack}/"

packs_list:
	cd .. && make packs_list

list_packs:
	make packs_list

push:
ifeq ($(commit),)
	$(error mn is not set)
endif
	make prehook
	git add . && git commit -m "$(commit)" && git push
