#!/usr/bin/make -f
# -*- makefile -*-

%:
	dh $@

override_dh_auto_build:
ifeq (,$(filter pkg.node-rollup.npm,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	set -e && \
	cd build-plugins && \
	for file in *.ts; do \
		tsc --module commonjs --moduleResolution node $$file; \
	done
	tsc --module commonjs --moduleResolution node --resolveJsonModule --esModuleInterop --skipLibCheck rollup.config.ts || test -e rollup.config.js
	# es module
	rollup --config rollup.config.js --configPlugin typescript
	# commonjs
	patch -p1 < debian/patches/dont-embed-acorn.diff
	rollup --config rollup.config.js --configPlugin typescript --configTest
	patch -p1 -R < debian/patches/dont-embed-acorn.diff
else
	@echo "### Build with npm ###"
	rm -rf node_modules
	HOME=/tmp npm install --ignore-scripts
	HOME=/tmp npm run build:cjs
endif
	cp src/rollup/types.d.ts dist/rollup.d.ts
	chmod +x dist/bin/rollup
	marked-man --version $$(grep version package.json | cut -d\" -f4) --gfm --breaks cli/help.md -o rollup.1
	# Ne need to embed (big) maps
	find dist -name '*.map' -delete

override_dh_fixperms:
	dh_fixperms
	chmod +x debian/rollup/usr/share/nodejs/rollup/dist/bin/rollup
