#
# This file is a template Makefile. Some targets are presented here as examples.
# Feel free to customize it to your needs!
#
CMD_ON_PROJECT = docker-compose run -u www-data --rm php
PHP_RUN = $(CMD_ON_PROJECT) php
YARN_RUN = docker-compose run -u node --rm -e YARN_REGISTRY -e PUPPETEER_SKIP_CHROMIUM_DOWNLOAD node yarn
ICON_INSTALL_PATH = ./vendor/webkul/prestashopconnectorbundle/src/Webkul/PrestashopConnectorBundle/front_package/icon_install.sh NO_COMPOSER=false
COMPOSER= $(shell which composer)

ifdef NO_DOCKER
  CMD_ON_PROJECT =
  YARN_RUN = yarnpkg
  PHP_RUN = php
endif

ifdef NO_COMPOSER
	ICON_INSTALL_PATH = ./src/Webkul/PrestashopConnectorBundle/front_package/icon_install.sh NO_COMPOSER=true	 
endif

.DEFAULT_GOAL := dev

yarn.lock: package.json
	PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 $(YARN_RUN) install

node_modules: yarn.lock 
	PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 $(YARN_RUN) install

.PHONY: icon
icon: 
	$(shell $(ICON_INSTALL_PATH))

.PHONY: javascript-extensions
javascript-extensions: 
	$(YARN_RUN) run update-extensions

.PHONY: front-packages
front-packages: 
	PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 $(YARN_RUN) packages:build

.PHONY: assets
assets: 
	$(CMD_ON_PROJECT) rm -rf public/bundles public/js
	$(PHP_RUN) bin/console pim:installer:assets --symlink --clean

.PHONY: css
css: 
	$(CMD_ON_PROJECT) rm -rf public/css
	$(YARN_RUN) run less

.PHONY: javascript-prod
javascript-prod: 
	$(CMD_ON_PROJECT) rm -rf public/dist
	$(YARN_RUN) run webpack
 
.PHONY: cache
cache:
	$(CMD_ON_PROJECT) rm -rf var/cache && $(PHP_RUN) bin/console cache:warmup 


.PHONY: wk_install
wk_install:
	$(CMD_ON_PROJECT) $(ICON_INSTALL_PATH)
	$(PHP_RUN) -d memory_limit=4G $(COMPOSER) --prefer-dist --no-scripts require navneetbhardwaj/akeneo-quickexport-configurator
	$(MAKE) node_modules
	$(MAKE) cache
	$(MAKE) assets
	$(MAKE) front-packages
	$(MAKE) javascript-prod
	$(MAKE) css
	$(MAKE) javascript-extensions
	$(PHP_RUN) bin/console doctrine:schema:update --force
