~aasg/nixexprs

159f12cd8855fc005d045897d715ceb6ab20425a — Aluísio Augusto Silva Gonçalves 4 months ago c57863c master
aasg-brotlify: Make file extensions configurable

Allow packages to specify the file extensions to compress, by either
extending or overriding the default list.
1 files changed, 19 insertions(+), 2 deletions(-)

M pkgs/build-support/aasg-brotlify/setup-hook.sh
M pkgs/build-support/aasg-brotlify/setup-hook.sh => pkgs/build-support/aasg-brotlify/setup-hook.sh +19 -2
@@ 1,11 1,28 @@
# Setup hook to compress files in $out with Brotli while keeping the
# originals.
#
# `brotlifyExtensions` is an array of file extensions to compress,
# defaulting to CSS, HTML, and JS files, and their source maps;
# `extraBrotlifyExtensions` can be set to append (instead of
# overwrite) to the defaults.
#
# To disable this setup hook, set `dontBrotlify`.

declare -a brotlifyExtensions extraBrotlifyExtensions

aasgBrotlifyPhase() {
	echo "compressing files with Brotli"
	fd "" "$out" -t f -e html -e css -e js -e css.map -e js.map -X brotli --best
	local ext

	if [[ ! -v brotlifyExtensions ]]; then
		brotlifyExtensions=(html css js html.map css.map js.map)
	fi
	brotlifyExtensions+=("${extraBrotlifyExtensions[@]}")
	for ext in "${brotlifyExtensions[@]}"; do
		args+=("-e" "$ext")
	done

	echo "compressing with Brotli files ending in: ${brotlifyExtensions[@]}"
	fd "" "$out" -t f "${args[@]}" -X brotli --best
}

if [[ -z "${dontBrotlify:-}" ]]; then