Makefile 6.1 KB

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