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

export LC_ALL=C.UTF-8

# Upstream's .babelrc.js keeps the test and demo sources out of dist/; the same
# files are ignored here so that they are not shipped in the installed module.
BABEL_IGNORE := **/*.jest.js,**/*.e2e.js,**/*.ssr.js,**/*.example.js,**/demo/**,**/TestUtils.js

%:
	dh $@

# Upstream's build script drives yarn, cross-env and webpack, none of which are
# in Debian.  Rebuild the bundles it publishes instead: dist/commonjs, dist/es,
# and the UMD file that zotero loads as a plain script.
#
# rollup resolves bare imports through node_modules, while Debian installs its
# modules in /usr/share/nodejs, so the symlink is created for that one step.
execute_after_dh_auto_build:
	babeljs --config-file ./debian/babel.config.cjs --ignore '$(BABEL_IGNORE)' source --out-dir dist/commonjs
	BABEL_TARGET=es babeljs --config-file ./debian/babel.config.cjs --ignore '$(BABEL_IGNORE)' source --out-dir dist/es
	sh debian/flow-types.sh
	ln -sfn /usr/share/nodejs node_modules
	rollup -c debian/rollup.config.cjs
	rm -f node_modules
	cp source/styles.css styles.css
