#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

GRUNT = grunt --no-color
MOCHA = mocha --no-timeout
# normalize output with TAP where possible unless terse requested
ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
MOCHA += --reporter tap
else
MOCHA += --reporter dot --no-colors
endif

%:
	dh $@

override_dh_auto_clean:
	tsc --build --clean Xbase-x
	rm -rf dist lib

override_dh_auto_build:
	tsc --project Xbase-x
	$(GRUNT) --base=Xloglevel concat uglify
	# Browser build
	mkdir -p dist
	webpack --config debian/webpack.config.js \
	--entry ./src/browser-index.js \
	--output ./dist/browser-matrix.js \
	--mode development
	webpack --config debian/webpack.config.js \
	--entry ./src/browser-index.js \
	--output ./dist/browser-matrix.min.js \
	--mode production
	# node module build
	babeljs-7 -d lib --presets @babel/preset-env --verbose --extensions ".ts,.js" src
	# quick-and-dirty hook
	perl -i -pe 's/=\s*import\(/= require\(/' lib/matrix.js
	tsc --emitDeclarationOnly

# TODO: check another-json tests when node-jasmine-node is in Debian
# TODO: check loglevel tests when node-grunt-contrib-jasmine is in Debian
override_dh_auto_test:
#	cd Xanother-json && jasmine-node spec/ --verbose --junitreport --forceexit --captureExceptions
	tape Xbase-x/test/*.js
	tape Xbs58/test/index.js
#	$(GRUNT) --base=Xloglevel test
	cd Xunhomoglyph && $(MOCHA)
