#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

source = $(shell find src/ -name '*.js')

override_dh_auto_build: dist/jstree.js dist/jstree.min.js
	dh_auto_build

build.js: debian/build.js
	cp $< $@

dist/jstree.js: build.js $(source)
	nodejs /usr/share/nodejs/requirejs/r.js -o build.js
	sed -i -e 's/{{VERSION}}/$(DEB_VERSION_UPSTREAM)/' $@
	@echo "Checking syntax of $@ ..."
	@nodejs --check $@ || (mv $@ $@.failed; false)

dist/jstree.min.js: dist/jstree.js
	uglifyjs $^ --output $@ --compress

override_dh_auto_test: dist/jstree.js dist/jstree.min.js
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	nodejs --check dist/jstree.js
	nodejs --check dist/jstree.min.js
endif

override_dh_auto_clean:
	$(RM) -rf dist/
	$(RM) build.js
	dh_auto_clean

%:
	dh $@