#!/usr/bin/make -f

# NODE_ENV specifies the environment for Node.js (e.g., development, production, or test).
# It is set to 'production' here to enable optimized builds and production-specific settings.
export NODE_ENV = production

# Create a list of all existing package names
SCAN_PACKAGE_DIR = $(foreach DIR, \
	$(sort $(dir $(wildcard src/*/))), \
	$(subst /,, $(subst src/,,$(DIR))) \
)

%:
	dh $@

# Build all cockpit package by calling the Makefile in a loop and save
# artifacts in distsave-<package-name> before building the next plugin, which
# will clear the dist directory
override_dh_auto_build:
	$(foreach PKG,$(SCAN_PACKAGE_DIR), \
		$(MAKE) PACKAGE_NAME=$(PKG) build-with-metainfo ; \
		mv dist distsave-$(PKG) ; \
	)

# Clean up saved plugins in distsave-<package-name>
override_dh_auto_clean:
	dh_auto_clean
	rm -rf distsave-*

# Do not use dh_auto_test, tests are WIP in upstream project
override_dh_auto_test:

# Do not use dh_auto_install, we use install files to distribute the build outputs to different Debian packages.
override_dh_auto_install:
