Makefile 6.9 KB

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