Makefile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 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. ##@ I18n
  81. .PHONY: i18n-add-file
  82. i18n-add-file: ## Add a new translation file to all supported languages
  83. ifndef key
  84. $(error To add a new file, you need to provide one in the "key" variable)
  85. endif
  86. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key)
  87. @echo File added.
  88. .PHONY: i18n-add-key
  89. i18n-add-key: ## Add a translation key to all supported languages
  90. ifndef key
  91. $(error To add a key, you need to provide one in the "key" variable)
  92. endif
  93. ifndef value
  94. $(error To add a key, you need to provide its value in the "value" variable)
  95. endif
  96. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)"
  97. @echo Key added.
  98. .PHONY: i18n-add-language
  99. i18n-add-language: ## Add a new supported language
  100. ifndef lang
  101. $(error To add a new language, you need to provide one in the "lang" variable)
  102. endif
  103. $(PHP) ./cli/manipulate.translation.php --action add --language $(lang) --origin-language $(ref)
  104. @echo Language added.
  105. .PHONY: i18n-format
  106. i18n-format: ## Format I18N files
  107. @$(PHP) ./cli/manipulate.translation.php --action format
  108. @echo Files formatted.
  109. .PHONY: i18n-ignore-key
  110. i18n-ignore-key: ## Ignore a translation key for the selected language
  111. ifndef lang
  112. $(error To ignore a key, you need to provide a language in the "lang" variable)
  113. endif
  114. ifndef key
  115. $(error To ignore a key, you need to provide one in the "key" variable)
  116. endif
  117. @$(PHP) ./cli/manipulate.translation.php --action ignore --key $(key) --language $(lang)
  118. @echo Key ignored.
  119. .PHONY: i18n-ignore-unmodified-keys
  120. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  121. ifndef lang
  122. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  123. endif
  124. @$(PHP) ./cli/manipulate.translation.php --action ignore_unmodified --language $(lang)
  125. @echo Unmodified keys ignored.
  126. .PHONY: i18n-key-exists
  127. i18n-key-exists: ## Check if a translation key exists
  128. ifndef key
  129. $(error To check if a key exists, you need to provide one in the "key" variable)
  130. endif
  131. @$(PHP) ./cli/manipulate.translation.php --action exist --key $(key)
  132. .PHONY: i18n-remove-key
  133. i18n-remove-key: ## Remove a translation key from all supported languages
  134. ifndef key
  135. $(error To remove a key, you need to provide one in the "key" variable)
  136. endif
  137. @$(PHP) ./cli/manipulate.translation.php --action delete --key $(key)
  138. @echo Key removed.
  139. .PHONY: i18n-update-key
  140. i18n-update-key: ## Update a translation key in all supported languages
  141. ifndef key
  142. $(error To update a key, you need to provide one in the "key" variable)
  143. endif
  144. ifndef value
  145. $(error To update a key, you need to provide its value in the "value" variable)
  146. endif
  147. @$(PHP) ./cli/manipulate.translation.php --action add --key $(key) --value "$(value)" --language en
  148. @echo Key updated.
  149. ##@ Tools
  150. .PHONY: pot
  151. pot: ## Generate POT templates for docs
  152. cd docs && ../cli/translation-update.sh
  153. .PHONY: readme
  154. readme: ## Generate translation progress in README file
  155. @$(PHP) ./cli/check.translation.php --generate-readme
  156. .PHONY: refresh
  157. refresh: ## Refresh feeds by fetching new messages
  158. @$(PHP) ./app/actualize_script.php
  159. .PHONY: rtl
  160. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  161. npm run-script rtlcss
  162. ###############################
  163. ## New commands aligned on CI #
  164. ## Work in progress #
  165. ###############################
  166. # TODO: Add composer install
  167. .PHONY: composer-test
  168. composer-test: bin/phpstan bin/composer
  169. bin/composer run-script test
  170. .PHONY: composer-fix
  171. composer-fix: bin/composer
  172. bin/composer run-script fix
  173. .PHONY: npm-test
  174. npm-test: node_modules/.bin/eslint
  175. npm test
  176. .PHONY: npm-fix
  177. npm-fix: node_modules/.bin/eslint
  178. npm run fix
  179. .PHONY: typos-test
  180. typos-test: bin/typos
  181. bin/typos
  182. # TODO: Add shellcheck, shfmt, hadolint
  183. .PHONY: test-all
  184. test-all: composer-test npm-test typos-test
  185. .PHONY: fix-all
  186. fix-all: composer-fix npm-fix
  187. ##@ Help
  188. .PHONY: help
  189. help: ## Display this help
  190. @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)