#!/usr/bin/make -f
%:
	dh $@

override_dh_install:
	install -Dt debian/workadventure-front/usr/src/workadventure/front front/dist/index.html
	install -d debian/workadventure-front/usr/src/workadventure/front/js
	cp -r front/dist/static front/dist/resources front/dist/*.js front/dist/style*.css debian/workadventure-front/usr/src/workadventure/front
	cp -r front/dist/js/*.js debian/workadventure-front/usr/src/workadventure/front/js


	install -d debian/workadventure-front-map/usr/src/workadventure/front/js
	cp -r front/dist/*.js.map front/dist/style*.css.map debian/workadventure-front-map/usr/src/workadventure/front
	cp -r front/dist/js/*.js.map debian/workadventure-front-map/usr/src/workadventure/front/js

	install -d debian/workadventure-back/usr/src/workadventure/back
	cp -r back/dist/server.js back/dist/src debian/workadventure-back/usr/src/workadventure/back
	cp back/yarn.lock back/package.json debian/workadventure-back/usr/src/workadventure/back
	install -d debian/workadventure-back/var/lib/workadventure/back
	ln -s /usr/src/workadventure/back/package.json /usr/src/workadventure/back/yarn.lock /usr/src/workadventure/back/src /usr/src/workadventure/back/server.js debian/workadventure-back/var/lib/workadventure/back/

	install -d debian/workadventure-pusher/usr/src/workadventure/pusher
	cp -r pusher/dist/server.js pusher/dist/src debian/workadventure-pusher/usr/src/workadventure/pusher
	cp pusher/yarn.lock pusher/package.json debian/workadventure-pusher/usr/src/workadventure/pusher
	install -d debian/workadventure-back/var/lib/workadventure/pusher
	ln -s /usr/src/workadventure/pusher/package.json /usr/src/workadventure/pusher/yarn.lock /usr/src/workadventure/pusher/src /usr/src/workadventure/pusher/server.js debian/workadventure-back/var/lib/workadventure/pusher/


front/src/Messages/generated:
	ln -s ../../../messages/generated front/src/Messages

back/src/Messages/generated:
	ln -s ../../../messages/generated back/src/Messages

pusher/src/Messages/generated:
	ln -s ../../../messages/generated pusher/src/Messages

override_dh_auto_build: front/src/Messages/generated back/src/Messages/generated pusher/src/Messages/generated
	cd messages && yarnpkg install && yarnpkg run proto
	rm -Rf front/dist/js
	cd front && ./templater.sh && yarnpkg install && yarnpkg run build
	cd back && yarnpkg install && yarnpkg run tsc
	cd pusher && yarnpkg install && yarnpkg run tsc

# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
