Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. ############
  24. ## Docker ##
  25. ############
  26. .PHONY: build
  27. build: ## Build a Docker image
  28. docker build \
  29. --pull \
  30. --tag freshrss/freshrss:$(TAG) \
  31. --file Docker/$(DOCKERFILE) .
  32. .PHONY: start
  33. start: ## Start the development environment (use Docker)
  34. docker network create --driver bridge $(NETWORK) || true
  35. $(foreach extension,$(extensions),$(eval volumes=$(volumes) --volume $(extension):/var/www/FreshRSS/extensions/$(notdir $(extension)):z))
  36. docker run \
  37. --rm \
  38. --volume $(shell pwd):/var/www/FreshRSS:z \
  39. $(volumes) \
  40. --publish $(PORT):80 \
  41. --env FRESHRSS_ENV=development \
  42. --name freshrss-dev \
  43. --network $(NETWORK) \
  44. freshrss/freshrss:$(TAG)
  45. .PHONY: stop
  46. stop: ## Stop FreshRSS container if any
  47. docker stop freshrss-dev || true
  48. docker network rm $(NETWORK) || true
  49. ######################
  50. ## Tests and linter ##
  51. ######################
  52. .PHONY: test
  53. test: vendor/bin/phpunit ## Run the test suite
  54. $(PHP) vendor/bin/phpunit --bootstrap ./tests/bootstrap.php ./tests
  55. .PHONY: lint
  56. lint: vendor/bin/phpcs ## Run the linter on the PHP files
  57. $(PHP) vendor/bin/phpcs . -p -s
  58. .PHONY: lint-fix
  59. lint-fix: vendor/bin/phpcbf ## Fix the errors detected by the linter
  60. $(PHP) vendor/bin/phpcbf . -p -s
  61. bin/composer:
  62. mkdir -p bin/
  63. wget 'https://raw.githubusercontent.com/composer/getcomposer.org/a19025d6c0a1ff9fc1fac341128b2823193be462/web/installer' -O - -q | php -- --quiet --install-dir='./bin/' --filename='composer'
  64. vendor/bin/phpunit: bin/composer
  65. bin/composer install --prefer-dist --no-progress
  66. ln -s ../vendor/bin/phpunit bin/phpunit
  67. vendor/bin/phpcs: bin/composer
  68. bin/composer install --prefer-dist --no-progress
  69. ln -s ../vendor/bin/phpcs bin/phpcs
  70. vendor/bin/phpcbf: bin/composer
  71. bin/composer install --prefer-dist --no-progress
  72. ln -s ../vendor/bin/phpcbf bin/phpcbf
  73. bin/typos:
  74. mkdir -p bin/
  75. cd bin ; \
  76. wget -q 'https://github.com/crate-ci/typos/releases/download/v1.16.21/typos-v1.16.21-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. vendor/bin/phpstan: bin/composer
  86. bin/composer install --prefer-dist --no-progress
  87. ##########
  88. ## I18N ##
  89. ##########
  90. .PHONY: i18n-format
  91. i18n-format: ## Format I18N files
  92. @$(PHP) ./cli/manipulate.translation.php -a format
  93. @echo Files formatted.
  94. .PHONY: i18n-add-language
  95. i18n-add-language: ## Add a new supported language
  96. ifndef lang
  97. $(error To add a new language, you need to provide one in the "lang" variable)
  98. endif
  99. $(PHP) ./cli/manipulate.translation.php -a add -l $(lang) -o $(ref)
  100. @echo Language added.
  101. .PHONY: i18n-add-key
  102. i18n-add-key: ## Add a translation key to all supported languages
  103. ifndef key
  104. $(error To add a key, you need to provide one in the "key" variable)
  105. endif
  106. ifndef value
  107. $(error To add a key, you need to provide its value in the "value" variable)
  108. endif
  109. @$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)"
  110. @echo Key added.
  111. .PHONY: i18n-remove-key
  112. i18n-remove-key: ## Remove a translation key from all supported languages
  113. ifndef key
  114. $(error To remove a key, you need to provide one in the "key" variable)
  115. endif
  116. @$(PHP) ./cli/manipulate.translation.php -a delete -k $(key)
  117. @echo Key removed.
  118. .PHONY: i18n-update-key
  119. i18n-update-key: ## Update a translation key in all supported languages
  120. ifndef key
  121. $(error To update a key, you need to provide one in the "key" variable)
  122. endif
  123. ifndef value
  124. $(error To update a key, you need to provide its value in the "value" variable)
  125. endif
  126. @$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)" -l en
  127. @echo Key updated.
  128. .PHONY: i18n-ignore-key
  129. i18n-ignore-key: ## Ignore a translation key for the selected language
  130. ifndef lang
  131. $(error To ignore a key, you need to provide a language in the "lang" variable)
  132. endif
  133. ifndef key
  134. $(error To ignore a key, you need to provide one in the "key" variable)
  135. endif
  136. @$(PHP) ./cli/manipulate.translation.php -a ignore -k $(key) -l $(lang)
  137. @echo Key ignored.
  138. .PHONY: i18n-ignore-unmodified-keys
  139. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  140. ifndef lang
  141. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  142. endif
  143. @$(PHP) ./cli/manipulate.translation.php -a ignore_unmodified -l $(lang)
  144. @echo Unmodified keys ignored.
  145. .PHONY: i18n-key-exists
  146. i18n-key-exists: ## Check if a translation key exists
  147. ifndef key
  148. $(error To check if a key exists, you need to provide one in the "key" variable)
  149. endif
  150. @$(PHP) ./cli/manipulate.translation.php -a exist -k $(key)
  151. ###########
  152. ## TOOLS ##
  153. ###########
  154. .PHONY: rtl
  155. rtl: node_modules/.bin/rtlcss ## Generate RTL CSS files
  156. npm run-script rtlcss
  157. .PHONY: pot
  158. pot: ## Generate POT templates for docs
  159. cd docs && ../cli/translation-update.sh
  160. .PHONY: refresh
  161. refresh: ## Refresh feeds by fetching new messages
  162. @$(PHP) ./app/actualize_script.php
  163. ###############################
  164. ## New commands aligned on CI #
  165. ## Work in progress #
  166. ###############################
  167. # TODO: Add composer install
  168. .PHONY: composer-test
  169. composer-test: vendor/bin/phpstan
  170. bin/composer run-script test
  171. .PHONY: composer-fix
  172. composer-fix:
  173. bin/composer run-script fix
  174. .PHONY: npm-test
  175. npm-test: node_modules/.bin/eslint
  176. npm test
  177. .PHONY: npm-fix
  178. npm-fix: node_modules/.bin/eslint
  179. npm run fix
  180. .PHONY: typos-test
  181. typos-test: bin/typos
  182. bin/typos
  183. # TODO: Add shellcheck, shfmt, hadolint
  184. .PHONY: test-all
  185. test-all: composer-test npm-test typos-test
  186. .PHONY: fix-all
  187. fix-all: composer-fix npm-fix
  188. ##########
  189. ## HELP ##
  190. ##########
  191. .PHONY: help
  192. help:
  193. @grep --extended-regexp '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'