# While this is a Makefile for using Docker, it's a Node.js app underneath so it
# has a package.json file we can pull properties from.

# In order to read the package.json file, you can use this function For nested
# properties, use dot notation (e.g. "dependencies.express").
define GetFromPkg
	$(shell node -p "require('./package.json').$(1)")
endef

PKG_NAME := $(call GetFromPkg,name)
PKG_VERSION := $(call GetFromPkg,version)
PROJECT_URL := $(call GetFromPkg,homepage)
AUTHOR := $(call GetFromPkg,author.name)

display-variables:
	@echo "PKG_NAME = $(PKG_NAME)"
	@echo "PKG_VERSION = $(PKG_VERSION)"
	@echo "PROJECT_URL = $(PROJECT_URL)"
	@echo "AUTHOR = $(AUTHOR)"

rebuild: build clean start logs

clean:
	@rm -rf node_modules package-lock.json yarn.lock pnpm-lock.yaml dist

build:
	@echo "Building/transpiling codebase..."
	@pnpm build

bump:
	@echo "Bumping version..."
	@npm version ${LEVEL}

add-tag:
	@echo "Adding v${VERSION} tag..."
	@git tag v${VERSION} -m "Release v${VERSION}"

push:
	@echo "Pushing to Remote..."
	@git push
	@git push --tags

publish: build
	@echo "Publishing to NPM..."
	@npm publish --access public

pretty:
	@prettier --write .
