-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
185 lines (160 loc) · 6.62 KB
/
Makefile
File metadata and controls
185 lines (160 loc) · 6.62 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Makefile to facilitate the use of Docker and testing
# Define SED_INPLACE based on the operating system
ifeq ($(shell uname), Darwin)
SED_INPLACE = sed -i ''
else
SED_INPLACE = sed -i
endif
# Detect the operating system
ifeq ($(OS),Windows_NT)
# We are on Windows
ifdef MSYSTEM
# MSYSTEM is defined, we are in MinGW or MSYS
SYSTEM_OS := unix
else ifdef CYGWIN
# CYGWIN is defined, we are in Cygwin
SYSTEM_OS := unix
else
# Not in MinGW or Cygwin
SYSTEM_OS := windows
endif
else
# Not Windows, assuming Unix
SYSTEM_OS := unix
endif
# Check if Docker is running
check-docker:
ifeq ($(SYSTEM_OS),windows)
@echo "Detected system: Windows (cmd, powershell)"
@docker version > NUL 2>&1 || (echo. & echo Error: Docker is not running. Please make sure Docker is installed and running. & echo. & exit 1)
else
@echo "Detected system: Unix (Linux/macOS/Cygwin/MinGW)"
@docker version > /dev/null 2>&1 || (echo "" && echo "Error: Docker is not running. Please make sure Docker is installed and running." && echo "" && exit 1)
endif
# Start Docker containers in interactive mode
up: check-docker
docker compose up --remove-orphans
# Start Docker containers in background mode (daemon)
upd: check-docker
docker compose up --detach --remove-orphans
# Stop and remove Docker containers
down: check-docker
docker compose down
# Pull the latest images from the registry
pull: check-docker
docker compose -f docker-compose.yml pull
# Build or rebuild Docker containers
build: check-docker
docker compose build
# Run the linter to check PHP code style
lint:
php vendor/bin/phpcs . --standard=PSR2 --ignore=vendor/,assets/,node_modules/,tests/js/,tests/ --colors --extensions=php
# Automatically fix PHP code style issues
fix:
php vendor/bin/phpcbf . --standard=PSR2 --ignore=vendor/,assets/,node_modules/,tests/js/,tests/ --colors --extensions=php
# Open a shell inside the omekas container
shell: check-docker
docker compose exec omekas bash
# Clean up and stop Docker containers, removing volumes and orphan containers
clean: check-docker
docker compose down -v --remove-orphans
# Generate the LearningObjectAdapter-X.X.X.zip package
package:
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION not specified. Use 'make package VERSION=1.2.3'"; \
exit 1; \
fi
@echo "Updating version to $(VERSION) in module.ini..."
$(SED_INPLACE) 's/^\([[:space:]]*version[[:space:]]*=[[:space:]]*\).*$$/\1"$(VERSION)"/' config/module.ini
@echo "Creating ZIP archive: LearningObjectAdapter-$(VERSION).zip..."
composer archive --format=zip --file="LearningObjectAdapter-$(VERSION)-raw"
@echo "Repacking into proper structure..."
mkdir -p tmpzip/LearningObjectAdapter && unzip -q LearningObjectAdapter-$(VERSION)-raw.zip -d tmpzip/LearningObjectAdapter && \
cd tmpzip && zip -qr ../LearningObjectAdapter-$(VERSION).zip LearningObjectAdapter && cd .. && rm -rf tmpzip LearningObjectAdapter-$(VERSION)-raw.zip
@echo "Restoring version to 0.0.0 in module.ini..."
$(SED_INPLACE) 's/^\([[:space:]]*version[[:space:]]*=[[:space:]]*\).*$$/\1"0.0.0"/' config/module.ini
# Generate .pot template from translate() and // @translate
generate-pot:
@echo "Extracting strings using xgettext..."
find . -path ./vendor -prune -o \( -name '*.php' -o -name '*.phtml' \) -print \
| xargs xgettext \
--language=PHP \
--from-code=utf-8 \
--keyword=translate \
--keyword=translatePlural:1,2 \
--output=language/xgettext.pot
@echo "Extracting strings marked with // @translate..."
"vendor/zerocrates/extract-tagged-strings/extract-tagged-strings.php" > language/tagged.pot
@echo "Merging xgettext.pot and tagged.pot into template.pot..."
msgcat language/xgettext.pot language/tagged.pot --use-first -o language/template.pot
@rm -f language/xgettext.pot language/tagged.pot
@echo "Generated language/template.pot"
# Update all .po files from .pot template
update-po:
@echo "Updating translation files..."
@find language -name "*.po" | while read po; do \
echo "Updating $$po..."; \
msgmerge --update --backup=off "$$po" language/template.pot; \
done
# Check for untranslated strings
check-untranslated:
@echo "Checking untranslated strings..."
@find language -name "*.po" | while read po; do \
echo "\n$$po:"; \
msgattrib --untranslated "$$po" | if grep -q msgid; then \
echo "Warning: Untranslated strings found!"; exit 1; \
else \
echo "All strings translated!"; \
fi \
done
# Compile all .po files in the language directory into .mo
compile-mo:
@echo "Compiling .po files into .mo..."
@find language -name '*.po' | while read po; do \
mo=$${po%.po}.mo; \
msgfmt "$$po" -o "$$mo"; \
echo "Compiled $$po -> $$mo"; \
done
# Full i18n workflow: pot -> po -> mo
i18n: generate-pot update-po check-untranslated compile-mo
# Run unit tests
.PHONY: test
test:
@echo "Running unit tests..."
php vendor/bin/phpunit -c test/phpunit.xml --colors=always --testdox
# Display help with available commands
help:
@echo ""
@echo "Usage: make <command>"
@echo ""
@echo "Docker management:"
@echo " up - Start Docker containers in interactive mode"
@echo " upd - Start Docker containers in background mode (detached)"
@echo " down - Stop and remove Docker containers"
@echo " build - Build or rebuild Docker containers"
@echo " pull - Pull the latest images from the registry"
@echo " clean - Stop containers and remove volumes and orphans"
@echo " shell - Open a shell inside the omekas container"
@echo ""
@echo "Code quality:"
@echo " lint - Run PHP linter (PHP_CodeSniffer)"
@echo " fix - Automatically fix PHP code style issues"
@echo ""
@echo "Testing:"
@echo " test - Run unit tests with PHPUnit"
@echo ""
@echo "Packaging:"
@echo " package - Generate a .zip package of the module with version tag"
@echo ""
@echo "Translations (i18n):"
@echo " generate-pot - Extract translatable strings to template.pot"
@echo " update-po - Update .po files from template.pot"
@echo " check-untranslated- Check for untranslated strings in .po files"
@echo " compile-mo - Compile .mo files from .po files"
@echo " i18n - Run full translation workflow (generate, update, check, compile)"
@echo ""
@echo "Other:"
@echo " help - Show this help message"
@echo ""
# Set help as the default goal if no target is specified
.DEFAULT_GOAL := help