#!/usr/bin/make -f

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

# detect if build targets experimental suite (or is a draft)
DEB_SUITE_EXP = $(filter experimental% UNRELEASED,$(DEB_DISTRIBUTION))

# avoid colors in testsuite output
export NODE_DISABLE_COLORS = 1

# generate documentation unless nodoc requested
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
DOCS = README.html README.txt
endif

ESLINT = eslint --format tap --no-eslintrc --env es6,node
MOCHA = mocha --reporter tap

override_dh_auto_build: $(DOCS)

# * tolerate known errors when targeted experimental
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(ESLINT) --no-inline-config '**/*.js'
#	standard
	tape Xerror/test.js Xkeys/test.js
	mkdir -p debian/node_modules
	ln --symbolic ../../Xerror debian/node_modules/module-not-found-error
	ln --symbolic ../../Xkeys debian/node_modules/fill-keys
	NODE_PATH=debian/node_modules $(MOCHA) \
		$(if $(DEB_SUITE_EXP),|| true)
endif

override_dh_installdocs:
	dh_installdocs --all -- $(DOCS)

dh_clean:
	dh_clean -- $(DOCS)

%.html: %.md
	pandoc --from gfm-raw_html --to html --standalone --output $@ $<

%.txt: %.md
	pandoc --from gfm-raw_html --to plain --output $@ $<

%:
	dh $@
