summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile86
1 files changed, 86 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..196cb5a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,86 @@
+PLUGIN := cepis-woocommerce
+VERSION := 0.1.0
+DIST := dist
+ZIP := $(DIST)/$(PLUGIN)-$(VERSION).zip
+
+PHP_LOCAL := $(shell command -v php 2>/dev/null)
+ifeq ($(PHP_LOCAL),)
+PHP := docker run --rm -v "$(CURDIR)":/app -w /app php:8.3-cli php
+else
+PHP := $(PHP_LOCAL)
+endif
+
+PHPCS := docker run --rm -v "$(CURDIR)":/app -v "$(CURDIR)/.phpcs/vendor":/phpcs -w /app \
+ php:8.3-cli /phpcs/bin/phpcs --standard=phpcs.xml.dist --no-colors
+
+SOURCES := cepis-woocommerce.php uninstall.php includes lib assets languages LICENSE README.md
+
+.DEFAULT_GOAL := help
+
+.PHONY: help install test lint format build check clean phpcs up down
+
+help:
+ @echo "targets:"
+ @echo " test stand the store up and drive the checkout in Chromium"
+ @echo " lint php -l, prettier --check, and phpcs when installed"
+ @echo " format apply prettier (writes)"
+ @echo " build produce $(ZIP)"
+ @echo " check lint, then test, then build"
+ @echo " clean remove build output and throw the test containers away"
+ @echo " phpcs fetch PHP_CodeSniffer and the WordPress standard"
+ @echo " up start the test store and leave it running"
+ @echo " down stop the test store"
+
+# node_modules is gitignored, so a fresh clone has no playwright-core and the
+# suite dies before the first assertion. Depending on it here is what makes
+# `make check` work on a machine that has only just cloned this.
+node_modules: package.json
+ bun install
+ @touch node_modules
+
+install: node_modules
+
+test: node_modules
+ sh test/setup.sh
+ bun test test/checkout.test.js
+
+lint: node_modules
+ @find . -name '*.php' -not -path './node_modules/*' -not -path './.phpcs/*' -not -path './dist/*' \
+ | sort | sed 's|^\./||' | xargs -n1 $(PHP) -l >/dev/null
+ @echo "php -l: no syntax errors"
+ @bunx prettier --check 'assets/js/cepis-woocommerce-*.js' 'test/*.js'
+ @if [ -x .phpcs/vendor/bin/phpcs ]; then \
+ $(PHPCS); \
+ else \
+ echo "phpcs: not installed, run 'make phpcs' for the WordPress standard"; \
+ fi
+
+format:
+ bunx prettier --write 'assets/js/cepis-woocommerce-*.js' 'test/*.js'
+
+phpcs:
+ sh tools/install-phpcs.sh
+
+build: clean-dist
+ @mkdir -p $(DIST)/$(PLUGIN)
+ @cp -R $(SOURCES) $(DIST)/$(PLUGIN)/
+ @cd $(DIST) && zip -qr $(PLUGIN)-$(VERSION).zip $(PLUGIN)
+ @rm -rf $(DIST)/$(PLUGIN)
+ @unzip -l $(ZIP) | tail -1
+ @echo "built $(ZIP)"
+
+check: lint test build
+
+up:
+ sh test/setup.sh
+
+down:
+ docker compose -f test/compose.yml down
+
+clean: clean-dist
+ docker compose -f test/compose.yml down -v --remove-orphans 2>/dev/null || true
+ rm -rf node_modules .phpcs
+
+.PHONY: clean-dist
+clean-dist:
+ @rm -rf $(DIST)