Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. wget 'https://raw.githubusercontent.com/composer/getcomposer.org/a5abae68b349213793dca4a1afcaada0ad11143b/web/installer' -O - -q | php -- --quiet --install-dir='./bin/' --filename='composer'
  66. # building any of these builds them all
  67. vendor/bin/phpunit vendor/bin/phpcs vendor/bin/phpcbf vendor/bin/phpstan &: bin/composer
  68. bin/composer install --prefer-dist --no-progress
  69. # Any of these depend on the vendor/ target, and then symlink the vendor/bin/ to the bin/.
  70. # 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
  71. bin/phpunit bin/phpcs bin/phpcbf bin/phpstan : % : vendor/%
  72. ln -sf $< $@
  73. bin/typos:
  74. mkdir -p bin/
  75. cd bin ; \
  76. wget -q 'https://github.com/crate-ci/typos/releases/download/v1.29.9/typos-v1.29.9-x86_64-unknown-linux-musl.tar.gz' && \
  77. tar -xvf *.tar.gz './typos' && \
  78. chmod +x typos && \
  79. rm *.tar.gz ; \
  80. cd ..
  81. node_modules/.bin/eslint:
  82. npm install
  83. node_modules/.bin/rtlcss:
  84. npm install
  85. # TODO: Add composer install
  86. .PHONY: composer-test
  87. composer-test: bin/phpstan bin/composer
  88. bin/composer run-script test
  89. .PHONY: composer-fix
  90. composer-fix: bin/composer
  91. bin/composer run-script fix
  92. .PHONY: npm-test
  93. npm-test: node_modules/.bin/eslint
  94. npm test
  95. .PHONY: npm-fix
  96. npm-fix: node_modules/.bin/eslint
  97. npm run fix
  98. .PHONY: typos-test
  99. typos-test: bin/typos
  100. bin/typos
  101. # TODO: Add shellcheck, shfmt, hadolint
  102. .PHONY: test-all
  103. test-all: composer-test npm-test typos-test ## Run all tests
  104. .PHONY: fix-all
  105. fix-all: composer-fix npm-fix ## Run all fixes
  106. ##@ I18n
  107. .PHONY: i18n-add-file
  108. i18n-add-file: ## Add a new translation file to all supported languages
  109. ifndef key
  110. $(error To add a new file, you need to provide one in the "key" variable)
  111. endif
  112. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key)
  113. @echo File added.
  114. .PHONY: i18n-add-key
  115. i18n-add-key: ## Add a translation key to all supported languages
  116. ifndef key
  117. $(error To add a key, you need to provide one in the "key" variable)
  118. endif
  119. ifndef value
  120. $(error To add a key, you need to provide its value in the "value" variable)
  121. endif
  122. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)"
  123. @echo Key added.
  124. .PHONY: i18n-move-key
  125. i18n-move-key: ## Move an existing key into a new location
  126. ifndef key
  127. $(error To move a key, you need to provide one in the "key" variable)
  128. endif
  129. ifndef new-key
  130. $(error To specify a location to move the key to, you need to provide it in the "new-key" variable)
  131. endif
  132. @$(PHP) ./cli/manipulate.translation.php --action move --key $(key) --new-key "$(new-key)"
  133. @echo Key moved.
  134. .PHONY: i18n-add-language
  135. i18n-add-language: ## Add a new supported language
  136. ifndef lang
  137. $(error To add a new language, you need to provide one in the "lang" variable)
  138. endif
  139. $(PHP) ./cli/manipulate.translation.php --action add --language $(lang) --origin-language $(ref)
  140. @echo Language added.
  141. .PHONY: i18n-format
  142. i18n-format: ## Format I18N files
  143. @$(PHP) ./cli/manipulate.translation.php --action format
  144. @echo Files formatted.
  145. .PHONY: i18n-ignore-key
  146. i18n-ignore-key: ## Ignore a translation key for the selected language
  147. ifndef lang
  148. $(error To ignore a key, you need to provide a language in the "lang" variable)
  149. endif
  150. ifndef key
  151. $(error To ignore a key, you need to provide one in the "key" variable)
  152. endif
  153. @$(PHP) ./cli/manipulate.translation.php --action ignore --key $(key) --language $(lang)
  154. @echo Key ignored.
  155. .PHONY: i18n-ignore-unmodified-keys
  156. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  157. ifndef lang
  158. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  159. endif
  160. @$(PHP) ./cli/manipulate.translation.php --action ignore_unmodified --language $(lang)
  161. @echo Unmodified keys ignored.
  162. .PHONY: i18n-key-exists
  163. i18n-key-exists: ## Check if a translation key exists
  164. ifndef key
  165. $(error To check if a key exists, you need to provide one in the "key" variable)
  166. endif
  167. @$(PHP) ./cli/manipulate.translation.php --action exist --key $(key)
  168. .PHONY: i18n-remove-key
  169. i18n-remove-key: ## Remove a translation key from all supported languages
  170. ifndef key
  171. $(error To remove a key, you need to provide one in the "key" variable)
  172. endif
  173. @$(PHP) ./cli/manipulate.translation.php --action delete --key $(key)
  174. @echo Key removed.
  175. .PHONY: i18n-update-key
  176. i18n-update-key: ## Update a translation key in all supported languages
  177. ifndef key
  178. $(error To update a key, you need to provide one in the "key" variable)
  179. endif
  180. ifndef value
  181. $(error To update a key, you need to provide its value in the "value" variable)
  182. endif
  183. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)" --language en
  184. @echo Key updated.
  185. ##@ Tools
  186. .PHONY: pot
  187. pot: ## Generate POT templates for docs
  188. cd docs && ../cli/translation-update.sh
  189. .PHONY: readme
  190. readme: ## Generate translation progress in README file
  191. @$(PHP) ./cli/check.translation.php --generate-readme
  192. .PHONY: refresh
  193. refresh: ## Refresh feeds by fetching new messages
  194. @$(PHP) ./app/actualize_script.php
  195. .PHONY: rtl
  196. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  197. npm run-script rtlcss
  198. ##@ Help
  199. .PHONY: help
  200. help: ## Display this help
  201. @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)