Makefile 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. .DEFAULT_GOAL := help
  2. ifndef TAG
  3. TAG=alpine
  4. endif
  5. PORT ?= 8080
  6. NETWORK ?= freshrss-network
  7. # detect docker or podman
  8. DOCKER ?= $(shell which docker 2>/dev/null || which podman 2>/dev/null)
  9. ifeq ($(DOCKER),)
  10. NO_DOCKER := 1
  11. endif
  12. ifdef NO_DOCKER
  13. PHP = $(shell which php)
  14. else
  15. PHP = $(DOCKER) run \
  16. --rm \
  17. --volume $(shell pwd):/var/www/FreshRSS:z \
  18. --env FRESHRSS_ENV=development \
  19. --name freshrss-php-cli \
  20. docker.io/freshrss/freshrss:$(TAG) \
  21. php
  22. endif
  23. ifeq ($(findstring alpine,$(TAG)),alpine)
  24. DOCKERFILE=Dockerfile-Alpine
  25. else
  26. DOCKERFILE=Dockerfile
  27. endif
  28. ##@ Docker
  29. .PHONY: build
  30. build: ## Build a Docker image
  31. $(DOCKER) build \
  32. --pull \
  33. --tag freshrss/freshrss:$(TAG) \
  34. --file Docker/$(DOCKERFILE) .
  35. .PHONY: start
  36. start: ## Start the development environment (use Docker)
  37. $(DOCKER) network create --driver bridge $(NETWORK) || true
  38. $(foreach extension,$(extensions),$(eval volumes=$(volumes) --volume $(extension):/var/www/FreshRSS/extensions/$(notdir $(extension)):z))
  39. $(DOCKER) run \
  40. -it \
  41. --rm \
  42. --volume $(shell pwd):/var/www/FreshRSS:z \
  43. $(volumes) \
  44. --publish $(PORT):80 \
  45. --env FRESHRSS_ENV=development \
  46. --name freshrss-dev \
  47. --network $(NETWORK) \
  48. docker.io/freshrss/freshrss:$(TAG)
  49. .PHONY: stop
  50. stop: ## Stop FreshRSS container if any
  51. $(DOCKER) stop freshrss-dev || true
  52. $(DOCKER) network rm $(NETWORK) || true
  53. ##@ Tests and linter
  54. .PHONY: lint
  55. lint: bin/phpcs ## Run the linter on PHP files
  56. $(PHP) bin/phpcs . -p -s
  57. .PHONY: lint-fix
  58. lint-fix: bin/phpcbf ## Fix the errors detected by the linter
  59. $(PHP) bin/phpcbf . -p -s
  60. .PHONY: test
  61. test: bin/phpunit ## Run the PHP test suite
  62. $(PHP) bin/phpunit --bootstrap ./tests/bootstrap.php ./tests
  63. bin/composer:
  64. mkdir -p bin/
  65. cd bin ; \
  66. wget 'https://raw.githubusercontent.com/composer/getcomposer.org/acf8a43b6a379f3a5ef72ebf21979f4936a608fd/web/installer' && \
  67. echo 'aad0c40a36d9938664f5a34eb2ed39dbc1021792f9706dbcb9cd6d8001227c99 installer' | sha256sum -c - && \
  68. php installer -- --quiet --install-dir='./' --filename='composer' && \
  69. rm installer && \
  70. cd ..
  71. # building any of these builds them all
  72. vendor/bin/phpunit vendor/bin/phpcs vendor/bin/phpcbf vendor/bin/phpstan &: bin/composer
  73. bin/composer install --prefer-dist --no-progress
  74. # Any of these depend on the vendor/ target, and then symlink the vendor/bin/ to the bin/.
  75. # use -sf so if the symlink already exists it won't error out. Running this from a container often won't properly detect it already exists
  76. bin/phpunit bin/phpcs bin/phpcbf bin/phpstan : % : vendor/%
  77. ln -sf $< $@
  78. bin/typos:
  79. mkdir -p bin/
  80. cd bin ; \
  81. wget 'https://github.com/crate-ci/typos/releases/download/v1.49.0/typos-v1.49.0-x86_64-unknown-linux-musl.tar.gz' && \
  82. echo '48bd2d58e02ce713b8c0f1aa239e68ee4f7d8c551013135806e6aed3938d9e10 typos-v1.49.0-x86_64-unknown-linux-musl.tar.gz' | sha256sum -c - && \
  83. tar -xvf *.tar.gz './typos' && \
  84. chmod +x typos && \
  85. rm *.tar.gz ; \
  86. cd ..
  87. node_modules/.bin/eslint:
  88. npm install
  89. node_modules/.bin/rtlcss:
  90. npm install
  91. node_modules/.bin/svgo:
  92. npm install
  93. # TODO: Add composer install
  94. .PHONY: composer-test
  95. composer-test: bin/phpstan bin/composer
  96. bin/composer run-script test
  97. .PHONY: composer-fix
  98. composer-fix: bin/composer
  99. bin/composer run-script fix
  100. .PHONY: npm-test
  101. npm-test: node_modules/.bin/eslint
  102. npm test
  103. .PHONY: npm-fix
  104. npm-fix: node_modules/.bin/eslint
  105. npm run fix
  106. .PHONY: typos-test
  107. typos-test: bin/typos
  108. bin/typos
  109. # TODO: Add shellcheck, shfmt, hadolint
  110. .PHONY: test-all
  111. test-all: composer-test npm-test typos-test ## Run all tests
  112. .PHONY: fix-all
  113. fix-all: composer-fix npm-fix ## Run all fixes
  114. ##@ I18n
  115. .PHONY: i18n-add-file
  116. i18n-add-file: ## Add a new translation file to all supported languages
  117. ifndef key
  118. $(error To add a new file, you need to provide one in the "key" variable)
  119. endif
  120. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key)
  121. @echo File added.
  122. .PHONY: i18n-add-key
  123. i18n-add-key: ## Add a translation key to all supported languages
  124. ifndef key
  125. $(error To add a key, you need to provide one in the "key" variable)
  126. endif
  127. ifndef value
  128. $(error To add a key, you need to provide its value in the "value" variable)
  129. endif
  130. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)"
  131. @echo Key added.
  132. .PHONY: i18n-move-key
  133. i18n-move-key: ## Move an existing key into a new location
  134. ifndef key
  135. $(error To move a key, you need to provide one in the "key" variable)
  136. endif
  137. ifndef new-key
  138. $(error To specify a location to move the key to, you need to provide it in the "new-key" variable)
  139. endif
  140. @$(PHP) ./cli/manipulate.translation.php --action move --key $(key) --new-key "$(new-key)"
  141. @echo Key moved.
  142. .PHONY: i18n-add-language
  143. i18n-add-language: ## Add a new supported language
  144. ifndef lang
  145. $(error To add a new language, you need to provide one in the "lang" variable)
  146. endif
  147. $(PHP) ./cli/manipulate.translation.php --action add --language $(lang) --origin-language $(ref)
  148. @echo Language added.
  149. .PHONY: i18n-compile-plurals
  150. i18n-compile-plurals: ## Compile plural formulas from app/i18n/*/plurals.php
  151. @$(PHP) ./cli/compile.plurals.php --all
  152. @echo Plural files compiled.
  153. .PHONY: i18n-format
  154. i18n-format: ## Format I18N files
  155. @$(PHP) ./cli/manipulate.translation.php --action format
  156. @$(PHP) ./cli/compile.plurals.php --all
  157. @echo Files formatted.
  158. .PHONY: i18n-ignore-key
  159. i18n-ignore-key: ## Ignore a translation key for the selected language
  160. ifndef lang
  161. $(error To ignore a key, you need to provide a language in the "lang" variable)
  162. endif
  163. ifndef key
  164. $(error To ignore a key, you need to provide one in the "key" variable)
  165. endif
  166. @$(PHP) ./cli/manipulate.translation.php --action ignore --key $(key) --language $(lang)
  167. @echo Key ignored.
  168. .PHONY: i18n-ignore-unmodified-keys
  169. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  170. ifndef lang
  171. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  172. endif
  173. @$(PHP) ./cli/manipulate.translation.php --action ignore_unmodified --language $(lang)
  174. @echo Unmodified keys ignored.
  175. .PHONY: i18n-key-exists
  176. i18n-key-exists: ## Check if a translation key exists
  177. ifndef key
  178. $(error To check if a key exists, you need to provide one in the "key" variable)
  179. endif
  180. @$(PHP) ./cli/manipulate.translation.php --action exist --key $(key)
  181. .PHONY: i18n-remove-key
  182. i18n-remove-key: ## Remove a translation key from all supported languages
  183. ifndef key
  184. $(error To remove a key, you need to provide one in the "key" variable)
  185. endif
  186. @$(PHP) ./cli/manipulate.translation.php --action delete --key $(key)
  187. @echo Key removed.
  188. .PHONY: i18n-update-key
  189. i18n-update-key: ## Update a translation key in all supported languages
  190. ifndef key
  191. $(error To update a key, you need to provide one in the "key" variable)
  192. endif
  193. ifndef value
  194. $(error To update a key, you need to provide its value in the "value" variable)
  195. endif
  196. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)" --language en
  197. @echo Key updated.
  198. ##@ Tools
  199. .PHONY: pot
  200. pot: ## Generate POT templates for docs
  201. cd docs && ../cli/translation-update.sh
  202. .PHONY: readme
  203. readme: ## Generate translation progress in README file
  204. @$(PHP) ./cli/check.translation.php --generate-readme
  205. .PHONY: refresh
  206. refresh: ## Refresh feeds by fetching new messages
  207. @$(PHP) ./app/actualize_script.php
  208. .PHONY: rtl
  209. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  210. npm run-script rtlcss
  211. .PHONY: svgo
  212. svgo: node_modules/.bin/svgo ## Optimize SVG image files
  213. npm run-script svgo
  214. ##@ Help
  215. .PHONY: help
  216. help: ## Display this help
  217. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-30s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)