# ====================================================================================
# Setup Project
ROOT := $(shell pwd)
PROJECT_FOLDER := $(ROOT)/src
BUILD_TOOLS_FOLDER := $(ROOT)/build-tools
MODULE_NAME := vinted_scraper
TECHNOLOGY := python

include $(BUILD_TOOLS_FOLDER)/common.mk
include $(BUILD_TOOLS_FOLDER)/common_linters.mk
include $(BUILD_TOOLS_FOLDER)/$(TECHNOLOGY)/python.mk
include $(BUILD_TOOLS_FOLDER)/git.mk
include $(BUILD_TOOLS_FOLDER)/image/docker.mk

AUTOGENERATED_FILE_REGEX := .*/(docs|htmlcov)/.* # This exclude these folder from the linter

# ====================================================================================
# Actions

.PHONY: all
all: update fmt lint coverage

.PHONY: test
test: test.local

.PHONY: test.local
test.local:
	export FROM_ROOT=true && $(MAKE) py.test

.PHONY: build
build: py.build

.PHONY: init
init: py.init git.hooks.setup

.PHONY: update
update: git.submodules py.update

.PHONY: update.user.agent
update.user.agent:
	curl -s "https://www.useragents.me/#most-common-mobile-useragents-json-csv" | grep -A 20 'id="most-common-mobile-useragents-json-csv"' | grep -A 15 'class="col-lg-6"' | grep -o '<textarea class="form-control" rows="8">.*</textarea>' | sed -E 's/<textarea class="form-control" rows="8">//;s/<\/textarea>//' > $(PROJECT_FOLDER)/$(MODULE_NAME)/agents.json

.PHONY: coverage
coverage:
	export FROM_ROOT=true && $(MAKE) py.coverage

.PHONY: docs
docs: py.docs

.PHONY: fmt
fmt: py.fmt

.PHONY: lint
lint: lint.checkmake lint.superlinter

.PHONY: clean
clean: py.clean lint.clean