Makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. # TODO: Add composer install
  92. .PHONY: composer-test
  93. composer-test: bin/phpstan bin/composer
  94. bin/composer run-script test
  95. .PHONY: composer-fix
  96. composer-fix: bin/composer
  97. bin/composer run-script fix
  98. .PHONY: npm-test
  99. npm-test: node_modules/.bin/eslint
  100. npm test
  101. .PHONY: npm-fix
  102. npm-fix: node_modules/.bin/eslint
  103. npm run fix
  104. .PHONY: typos-test
  105. typos-test: bin/typos
  106. bin/typos
  107. # TODO: Add shellcheck, shfmt, hadolint
  108. .PHONY: test-all
  109. test-all: composer-test npm-test typos-test ## Run all tests
  110. .PHONY: fix-all
  111. fix-all: composer-fix npm-fix ## Run all fixes
  112. ##@ I18n
  113. .PHONY: i18n-add-file
  114. i18n-add-file: ## Add a new translation file to all supported languages
  115. ifndef key
  116. $(error To add a new file, you need to provide one in the "key" variable)
  117. endif
  118. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key)
  119. @echo File added.
  120. .PHONY: i18n-add-key
  121. i18n-add-key: ## Add a translation key to all supported languages
  122. ifndef key
  123. $(error To add a key, you need to provide one in the "key" variable)
  124. endif
  125. ifndef value
  126. $(error To add a key, you need to provide its value in the "value" variable)
  127. endif
  128. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)"
  129. @echo Key added.
  130. .PHONY: i18n-move-key
  131. i18n-move-key: ## Move an existing key into a new location
  132. ifndef key
  133. $(error To move a key, you need to provide one in the "key" variable)
  134. endif
  135. ifndef new-key
  136. $(error To specify a location to move the key to, you need to provide it in the "new-key" variable)
  137. endif
  138. @$(PHP) ./cli/manipulate.translation.php --action move --key $(key) --new-key "$(new-key)"
  139. @echo Key moved.
  140. .PHONY: i18n-add-language
  141. i18n-add-language: ## Add a new supported language
  142. ifndef lang
  143. $(error To add a new language, you need to provide one in the "lang" variable)
  144. endif
  145. $(PHP) ./cli/manipulate.translation.php --action add --language $(lang) --origin-language $(ref)
  146. @echo Language added.
  147. .PHONY: i18n-compile-plurals
  148. i18n-compile-plurals: ## Compile plural formulas from app/i18n/*/plurals.php
  149. @$(PHP) ./cli/compile.plurals.php --all
  150. @echo Plural files compiled.
  151. .PHONY: i18n-format
  152. i18n-format: ## Format I18N files
  153. @$(PHP) ./cli/manipulate.translation.php --action format
  154. @$(PHP) ./cli/compile.plurals.php --all
  155. @echo Files formatted.
  156. .PHONY: i18n-ignore-key
  157. i18n-ignore-key: ## Ignore a translation key for the selected language
  158. ifndef lang
  159. $(error To ignore a key, you need to provide a language in the "lang" variable)
  160. endif
  161. ifndef key
  162. $(error To ignore a key, you need to provide one in the "key" variable)
  163. endif
  164. @$(PHP) ./cli/manipulate.translation.php --action ignore --key $(key) --language $(lang)
  165. @echo Key ignored.
  166. .PHONY: i18n-ignore-unmodified-keys
  167. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  168. ifndef lang
  169. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  170. endif
  171. @$(PHP) ./cli/manipulate.translation.php --action ignore_unmodified --language $(lang)
  172. @echo Unmodified keys ignored.
  173. .PHONY: i18n-key-exists
  174. i18n-key-exists: ## Check if a translation key exists
  175. ifndef key
  176. $(error To check if a key exists, you need to provide one in the "key" variable)
  177. endif
  178. @$(PHP) ./cli/manipulate.translation.php --action exist --key $(key)
  179. .PHONY: i18n-remove-key
  180. i18n-remove-key: ## Remove a translation key from all supported languages
  181. ifndef key
  182. $(error To remove a key, you need to provide one in the "key" variable)
  183. endif
  184. @$(PHP) ./cli/manipulate.translation.php --action delete --key $(key)
  185. @echo Key removed.
  186. .PHONY: i18n-update-key
  187. i18n-update-key: ## Update a translation key in all supported languages
  188. ifndef key
  189. $(error To update a key, you need to provide one in the "key" variable)
  190. endif
  191. ifndef value
  192. $(error To update a key, you need to provide its value in the "value" variable)
  193. endif
  194. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)" --language en
  195. @echo Key updated.
  196. ##@ Tools
  197. .PHONY: pot
  198. pot: ## Generate POT templates for docs
  199. cd docs && ../cli/translation-update.sh
  200. .PHONY: readme
  201. readme: ## Generate translation progress in README file
  202. @$(PHP) ./cli/check.translation.php --generate-readme
  203. .PHONY: refresh
  204. refresh: ## Refresh feeds by fetching new messages
  205. @$(PHP) ./app/actualize_script.php
  206. .PHONY: rtl
  207. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  208. npm run-script rtlcss
  209. ##@ Help
  210. .PHONY: help
  211. help: ## Display this help
  212. @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)