Makefile 6.1 KB

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