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

clearhook:
	@echo "clear hooks"
	@rm -f $(HOOK_PATH)
	@echo "hooks cleared"


prehook:
	make clearhook
	@echo '#!/bin/sh'									>> $(HOOK_PATH)
	@echo 'echo "Running lint for live_monitor_vue"'	>> $(HOOK_PATH)
	@echo 'cd ./live_monitor_vue'						>> $(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 live_monitor_vue"'	>> $(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 "../pkg_js/${pack}/"

packs_list:
	cd ../pkg_js && 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

push_new:
ifeq ($(commit),)
	$(error mn is not set)
endif
	make prehook
	git add . && git commit -m "$(commit)" && git push --set-upstream origin $(shell git rev-parse --abbrev-ref HEAD)
