node_modules:
	npm install

WEBPACK_BUILD := ./node_modules/.bin/webpack-cli --config webpack.config.js

dist/bundle.js: prod
.PHONY: prod
prod:
	${WEBPACK_BUILD} --mode production

.PHONY: dev
dev:
	${WEBPACK_BUILD} --mode development

.PHONY: start
start: dev
	node dist/bundle.js

VERSION := $(shell cat package.json | jq -r ".version")
CONTAINER_TAG := "lateinicus/server:${VERSION}"
container: dist/bundle.js
	@echo Building the container
	cp wait-for dist/
	sudo docker build -t ${CONTAINER_TAG} -f Dockerfile dist/
	rm -f dist/wait-for

	@echo Exporting the container
	sudo docker save ${CONTAINER_TAG} > backend.tar
	tar -czf backend.tgz backend.tar
	rm -f backend.tar
