summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 94b019705e07d4aadb50de55be720913e04caf5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
PIDFILE=/tmp/smtp-sink.pid

help: ## What you're currently reading
	@IFS=$$'\n' ; \
	help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
	clear ; \
	printf "Usage: make [target]\n\n" ; \
	printf "%-30s %s\n" "[target]" "help" ; \
	printf "%-30s %s\n" "--------" "----" ; \
	for help_line in $${help_lines[@]}; do \
		IFS=$$':' ; \
		help_split=($$help_line) ; \
		help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
		help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
		printf '\033[36m'; \
		printf "%-30s %s" $$help_command ; \
		printf '\033[0m'; \
		printf "%s\n" $$help_info; \
	done; \
	printf "\n"; \

install: ## Installs dev dependencies
	composer install
	npm install

test: server-start ## Runs tests
	"./vendor/bin/phpunit" --no-coverage
	make server-stop

coverage: server-start ## Runs tests with code coverage
	"./vendor/bin/phpunit" --coverage-html=./coverage/ --coverage-clover=./coverage/clover.xml
	make server-stop

$(PIDFILE): ## Starts the smtp-sink server
	./node_modules/.bin/smtp-sink -w allowed-sender@example.org & echo $$! > $@

server-start: server-stop $(PIDFILE) ## Stops and starts the smtp-sink server

server-stop: ## Stops smtp-sink server if it's running
	if [ -e $(PIDFILE) ]; then \
		PID=$$(cat $(PIDFILE)); \
		# Getting smtp-sink's pid by matching second column (ppid) of ps output clumsily \
		NODEPID=$$(ps xao pid,ppid,pgid,sid,comm | awk -v pid="$$PID" '$$2==pid{print $$1}'); \
		#PGID=$$(ps xao pid,ppid,pgid,sid,comm -p $$PID | sed '1d' | awk '{print $$3}'); \
		#MYPPID=$$(ps xao pid,ppid,pgid,sid,comm -p $$PID | sed '1d' | awk '{print $$2}'); \
		echo PID=$$PID; \
		echo NODEPID=$$NODEPID; \
		#echo PGID=$$PGID; \
		#echo PPID=$$PPID; \
		#echo MYPPID=$$MYPPID; \
		# Killing nodejs pid that we spawned (hopefully) \
		if [ ! -z "$$NODEPID" ]; then \
			kill $$NODEPID || true; \
		fi; \
		# Killing juts the PID is not enough sometimes, nodejs server still lingers on (at least on Windows) \
		if [ ! -z "$$PID" ]; then \
			kill $$PID || true; \
		fi; \
# TODO/FIXME: this manages to kill too much or something, whole recipe fails :/ \
#		if [ ! -z "$$PGID" ]; then \
#			kill -- -$$PGID || true; \
#		fi; \
		rm -rf $(PIDFILE) || true; \
	fi; \

clean: ## Removes installed dev dependencies
	rm -rf ./vendor
	rm -rf ./node_modules

.PHONY: help install test clean coverage server-start server-stop