Makefile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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-compile-plurals
  142. i18n-compile-plurals: ## Compile plural formulas from app/i18n/*/plurals.php
  143. @$(PHP) ./cli/compile.plurals.php --all
  144. @echo Plural files compiled.
  145. .PHONY: i18n-format
  146. i18n-format: ## Format I18N files
  147. @$(PHP) ./cli/manipulate.translation.php --action format
  148. @$(PHP) ./cli/compile.plurals.php --all
  149. @echo Files formatted.
  150. .PHONY: i18n-ignore-key
  151. i18n-ignore-key: ## Ignore a translation key for the selected language
  152. ifndef lang
  153. $(error To ignore a key, you need to provide a language in the "lang" variable)
  154. endif
  155. ifndef key
  156. $(error To ignore a key, you need to provide one in the "key" variable)
  157. endif
  158. @$(PHP) ./cli/manipulate.translation.php --action ignore --key $(key) --language $(lang)
  159. @echo Key ignored.
  160. .PHONY: i18n-ignore-unmodified-keys
  161. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  162. ifndef lang
  163. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  164. endif
  165. @$(PHP) ./cli/manipulate.translation.php --action ignore_unmodified --language $(lang)
  166. @echo Unmodified keys ignored.
  167. .PHONY: i18n-key-exists
  168. i18n-key-exists: ## Check if a translation key exists
  169. ifndef key
  170. $(error To check if a key exists, you need to provide one in the "key" variable)
  171. endif
  172. @$(PHP) ./cli/manipulate.translation.php --action exist --key $(key)
  173. .PHONY: i18n-remove-key
  174. i18n-remove-key: ## Remove a translation key from all supported languages
  175. ifndef key
  176. $(error To remove a key, you need to provide one in the "key" variable)
  177. endif
  178. @$(PHP) ./cli/manipulate.translation.php --action delete --key $(key)
  179. @echo Key removed.
  180. .PHONY: i18n-update-key
  181. i18n-update-key: ## Update a translation key in all supported languages
  182. ifndef key
  183. $(error To update a key, you need to provide one in the "key" variable)
  184. endif
  185. ifndef value
  186. $(error To update a key, you need to provide its value in the "value" variable)
  187. endif
  188. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)" --language en
  189. @echo Key updated.
  190. ##@ Tools
  191. .PHONY: pot
  192. pot: ## Generate POT templates for docs
  193. cd docs && ../cli/translation-update.sh
  194. .PHONY: readme
  195. readme: ## Generate translation progress in README file
  196. @$(PHP) ./cli/check.translation.php --generate-readme
  197. .PHONY: refresh
  198. refresh: ## Refresh feeds by fetching new messages
  199. @$(PHP) ./app/actualize_script.php
  200. .PHONY: rtl
  201. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  202. npm run-script rtlcss
  203. ##@ Help
  204. .PHONY: help
  205. help: ## Display this help
  206. @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)