From 4a7c9d541db3bdbab455d824e33082a2600a8d06 Mon Sep 17 00:00:00 2001 From: Adrien CLERC Date: Mon, 2 Sep 2019 22:16:08 +0200 Subject: [PATCH] add compress_assets target to compress PNG. It depends on zopflipng, find and xargs. Only zopflipng is tested, since it is the less common. --- Makefile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Makefile b/Makefile index 1f36a846..784920f2 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ DEV_STAMP = $(VENV)/.dev_env_installed.stamp DOC_STAMP = $(VENV)/.doc_env_installed.stamp INSTALL_STAMP = $(VENV)/.install.stamp TEMPDIR := $(shell mktemp -d) +ZOPFLIPNG := zopflipng .PHONY: all all: install ## Alias for install @@ -47,6 +48,15 @@ test: $(DEV_STAMP) ## Run the tests release: $(DEV_STAMP) ## Release a new version (see https://ihatemoney.readthedocs.io/en/latest/contributing.html#how-to-release) $(VENV)/bin/fullrelease +.PHONY: compress_assets +compress_assets: ## Compress static assets + @which $(ZOPFLIPNG) >/dev/null || (echo "ZopfliPNG ($(ZOPFLIPNG)) is missing" && exit 1) + mkdir $(TEMPDIR)/zopfli + $(eval CPUCOUNT := $(shell python -c "import psutil; print(psutil.cpu_count(logical=False))")) +# We need to go into the directory to use an absolute path as a prefix + cd ihatemoney/static/images/; find -name '*.png' -printf '%f\0' | xargs --null --max-args=1 --max-procs=$(CPUCOUNT) $(ZOPFLIPNG) --iterations=500 --filters=01234mepb --lossy_8bit --lossy_transparent --prefix=$(TEMPDIR)/zopfli/ + mv $(TEMPDIR)/zopfli/* ihatemoney/static/images/ + .PHONY: build-translations build-translations: ## Build the translations $(VENV)/bin/pybabel compile -d ihatemoney/translations