Makefile 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. .DEFAULT_GOAL := help
  2. ifndef TAG
  3. TAG=alpine
  4. endif
  5. PORT ?= 8080
  6. ifdef NO_DOCKER
  7. PHP = $(shell which php)
  8. else
  9. PHP = docker run \
  10. --rm \
  11. --volume $(shell pwd):/var/www/FreshRSS:z \
  12. --env FRESHRSS_ENV=development \
  13. --name freshrss-php-cli \
  14. freshrss/freshrss:$(TAG) \
  15. php
  16. endif
  17. ifeq ($(findstring alpine,$(TAG)),alpine)
  18. DOCKERFILE=Dockerfile-Alpine
  19. else ifeq ($(findstring arm,$(TAG)),arm)
  20. DOCKERFILE=Dockerfile-QEMU-ARM
  21. else
  22. DOCKERFILE=Dockerfile
  23. endif
  24. ############
  25. ## Docker ##
  26. ############
  27. .PHONY: build
  28. build: ## Build a Docker image
  29. docker build \
  30. --pull \
  31. --tag freshrss/freshrss:$(TAG) \
  32. --file Docker/$(DOCKERFILE) .
  33. .PHONY: start
  34. start: ## Start the development environment (use Docker)
  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. freshrss/freshrss:$(TAG)
  44. .PHONY: stop
  45. stop: ## Stop FreshRSS container if any
  46. docker stop freshrss-dev
  47. ######################
  48. ## Tests and linter ##
  49. ######################
  50. .PHONY: test
  51. test: bin/phpunit ## Run the test suite
  52. $(PHP) ./bin/phpunit --bootstrap ./tests/bootstrap.php ./tests
  53. .PHONY: lint
  54. lint: bin/phpcs ## Run the linter on the PHP files
  55. $(PHP) ./bin/phpcs . -p -s
  56. .PHONY: lint-fix
  57. lint-fix: bin/phpcbf ## Fix the errors detected by the linter
  58. $(PHP) ./bin/phpcbf . -p -s
  59. bin/composer:
  60. mkdir -p bin/
  61. wget 'https://raw.githubusercontent.com/composer/getcomposer.org/ce43e63e47a7fca052628faf1e4b14f9100ae82c/web/installer' -O - -q | php -- --quiet --install-dir='./bin/' --filename='composer'
  62. bin/phpunit:
  63. mkdir -p bin/
  64. wget -O bin/phpunit https://phar.phpunit.de/phpunit-9.5.2.phar
  65. echo 'bcf913565bc60dfb5356cf67cbbccec1d8888dbd595b0fbb8343a5019342c67c bin/phpunit' | sha256sum -c - || rm bin/phpunit
  66. bin/phpcs:
  67. mkdir -p bin/
  68. wget -O bin/phpcs https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.5.5/phpcs.phar
  69. echo '4a2f6aff1b1f760216bb00c0b3070431131e3ed91307436bb1bfb252281a804a bin/phpcs' | sha256sum -c - || rm bin/phpcs
  70. bin/phpcbf:
  71. mkdir -p bin/
  72. wget -O bin/phpcbf https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.5.5/phpcbf.phar
  73. echo '6f64fe00dee53fa7b256f63656dc0154f5964666fc7e535fac86d0078e7dea41 bin/phpcbf' | sha256sum -c - || rm bin/phpcbf
  74. bin/typos:
  75. mkdir -p bin/
  76. cd bin ; \
  77. wget -q 'https://github.com/crate-ci/typos/releases/download/v1.3.3/typos-v1.3.3-x86_64-unknown-linux-musl.tar.gz' && \
  78. tar -xvf *.tar.gz './typos' && \
  79. chmod +x typos && \
  80. rm *.tar.gz ; \
  81. cd ..
  82. node_modules/.bin/eslint:
  83. npm install
  84. vendor/bin/phpstan: bin/composer
  85. bin/composer install --prefer-dist --no-progress
  86. ##########
  87. ## I18N ##
  88. ##########
  89. .PHONY: i18n-format
  90. i18n-format: ## Format I18N files
  91. @$(PHP) ./cli/manipulate.translation.php -a format
  92. @echo Files formatted.
  93. .PHONY: i18n-add-language
  94. i18n-add-language: ## Add a new supported language
  95. ifndef lang
  96. $(error To add a new language, you need to provide one in the "lang" variable)
  97. endif
  98. $(PHP) ./cli/manipulate.translation.php -a add -l $(lang) -o $(ref)
  99. @echo Language added.
  100. .PHONY: i18n-add-key
  101. i18n-add-key: ## Add a translation key to all supported languages
  102. ifndef key
  103. $(error To add a key, you need to provide one in the "key" variable)
  104. endif
  105. ifndef value
  106. $(error To add a key, you need to provide its value in the "value" variable)
  107. endif
  108. @$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)"
  109. @echo Key added.
  110. .PHONY: i18n-remove-key
  111. i18n-remove-key: ## Remove a translation key from all supported languages
  112. ifndef key
  113. $(error To remove a key, you need to provide one in the "key" variable)
  114. endif
  115. @$(PHP) ./cli/manipulate.translation.php -a delete -k $(key)
  116. @echo Key removed.
  117. .PHONY: i18n-update-key
  118. i18n-update-key: ## Update a translation key in all supported languages
  119. ifndef key
  120. $(error To update a key, you need to provide one in the "key" variable)
  121. endif
  122. ifndef value
  123. $(error To update a key, you need to provide its value in the "value" variable)
  124. endif
  125. @$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)" -l en
  126. @echo Key updated.
  127. .PHONY: i18n-ignore-key
  128. i18n-ignore-key: ## Ignore a translation key for the selected language
  129. ifndef lang
  130. $(error To ignore a key, you need to provide a language in the "lang" variable)
  131. endif
  132. ifndef key
  133. $(error To ignore a key, you need to provide one in the "key" variable)
  134. endif
  135. @$(PHP) ./cli/manipulate.translation.php -a ignore -k $(key) -l $(lang)
  136. @echo Key ignored.
  137. .PHONY: i18n-ignore-unmodified-keys
  138. i18n-ignore-unmodified-keys: ## Ignore all unmodified translation keys for the selected language
  139. ifndef lang
  140. $(error To ignore unmodified keys, you need to provide a language in the "lang" variable)
  141. endif
  142. @$(PHP) ./cli/manipulate.translation.php -a ignore_unmodified -l $(lang)
  143. @echo Unmodified keys ignored.
  144. .PHONY: i18n-key-exists
  145. i18n-key-exists: ## Check if a translation key exists
  146. ifndef key
  147. $(error To check if a key exists, you need to provide one in the "key" variable)
  148. endif
  149. @$(PHP) ./cli/manipulate.translation.php -a exist -k $(key)
  150. ###########
  151. ## TOOLS ##
  152. ###########
  153. .PHONY: rtl
  154. rtl: ## Generate RTL CSS files
  155. rtlcss -d p/themes/ && find p/themes/ -type f -name '*.rtl.rtl.css' -delete
  156. .PHONY: pot
  157. pot: ## Generate POT templates for docs
  158. cd docs && ../cli/translation-update.sh
  159. .PHONY: refresh
  160. refresh: ## Refresh feeds by fetching new messages
  161. @$(PHP) ./app/actualize_script.php
  162. ###############################
  163. ## New commands aligned on CI #
  164. ## Work in progress #
  165. ###############################
  166. # TODO: Add composer install
  167. .PHONY: composer-test
  168. composer-test: vendor/bin/phpstan
  169. bin/composer run-script test
  170. .PHONY: composer-fix
  171. composer-fix:
  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. ##########
  188. ## HELP ##
  189. ##########
  190. .PHONY: help
  191. help:
  192. @grep --extended-regexp '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'