.DEFAULT_GOAL := build-www

build-www:
	mkdir -p dest/
	rm -rf dest/www
	cp -pr www dest/www

	tsc

	sed -i 's:"\(/res/[^"]*\|/favicon.ico\|/app.webmanifest\)":"\1?v=$(shell date -u +%Y%m%d-%H%M%S)":g' dest/www/index.html
	perl -i -pE \
		"s/^(import .*)\"(.*?)(\.js)?(\?.*?)?\"/(\$$1).(\"\\\".\/\$$2.js?v=$(shell date -u +%Y%m%d-%H%M%S)\\\"\")/ge" \
		dest/www/res/scripts/*.js

	tools/minify-css.sh
	sed -i 's|/res/styles/styles.css|/res/styles/min.css|g' dest/www/index.html

	#convert -background none dest/www/res/svgs/tucal.svg -alpha set -define icon:auto-resize=256,128,64,32,24,16 dest/www/favicon.ico

clean:
	rm -rf dest/
