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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# rollup-plugin-typescript2 的默认 include 模式为 "*.ts+(|x)"/"**/*.ts+(|x)"，
# 本环境 picomatch 4.x 无法匹配该 extglob 形式，导致 index.tsx 未被该插件转换
# （rollup 直接按 JS 解析 TSX 而报 Unexpected token）。此处显式传入等价的 include。
ROLLUP_PLUGINS=-p @rollup/plugin-babel -p 'rollup-plugin-typescript2={include:["**/*.ts","**/*.tsx"]}' -p rollup-plugin-terser
ES_FILE=$(shell pkgjs-pjson . exports . import)
CJS_FILE=$(shell pkgjs-pjson . exports . require)

%:
	dh $@

override_dh_auto_build:
	rollup $(ROLLUP_PLUGINS) --external react -f es -o $(ES_FILE) index.tsx
	ln -s $(ES_FILE) index.js
	rollup $(ROLLUP_PLUGINS) --external react -p @rollup/plugin-node-resolve -f cjs -o $(CJS_FILE) index.cjs.tsx
	rm -f index.js

override_dh_installdocs:
	dh_installdocs
	dh_nodejs_autodocs
