## consts

dir_lib := lib
dir_source := source
dir_temp := /tmp/zeitbild-frontend-web-temp
dir_build := build
dir_tools := tools

cmd_cat := cat
cmd_chmod := chmod
cmd_cp := cp
cmd_log := echo "--"
cmd_mkdir := mkdir -p
cmd_tsc := ${dir_tools}/typescript/node_modules/.bin/tsc


## rules

.PHONY: default
default: index templates style logic

.PHONY: index
index: ${dir_build}/index.html

${dir_build}/index.html: \
		${dir_source}/index.html
	@ ${cmd_log} "index …"
	@ ${cmd_mkdir} $(dir $@)
	@ ${cmd_cp} -u -v $^ $@

.PHONY: templates
templates: \
		$(wildcard ${dir_source}/templates/*)
	@ ${cmd_log} "templates …"
	@ ${cmd_mkdir} ${dir_build}/templates
	@ ${cmd_cp} -r -u -v ${dir_source}/templates/* ${dir_build}/templates/

.PHONY: style
style: \
		$(wildcard ${dir_source}/style/*)
	@ ${cmd_log} "style …"
	@ ${cmd_mkdir} ${dir_build}
	@ ${cmd_cat} ${dir_source}/style/* > ${dir_build}/style.css

.PHONY: logic
logic: ${dir_build}/logic.js

${dir_temp}/logic-unlinked.js: \
		${dir_lib}/plankton/plankton.d.ts \
		${dir_source}/logic/helpers.ts \
		${dir_source}/logic/conf.ts \
		${dir_source}/logic/types.ts \
		${dir_source}/logic/backend.ts \
		${dir_source}/logic/view.ts \
		${dir_source}/logic/main.ts
	@ ${cmd_log} "logic | compile …"
	@ ${cmd_mkdir} $(dir $@)
	@ ${cmd_tsc} --lib dom,es2020 $^ --outFile $@ # --strict

${dir_build}/logic.js: \
		${dir_lib}/plankton/plankton.js \
		${dir_temp}/logic-unlinked.js
	@ ${cmd_log} "logic | link …"
	@ ${cmd_mkdir} $(dir $@)
	@ ${cmd_cat} $^ > $@
