You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
5.6 KiB

3 years ago
  1. # This file is licensed under the Affero General Public License version 3 or
  2. # later. See the COPYING file.
  3. # @author Bernhard Posselt <dev@bernhard-posselt.com>
  4. # @copyright Bernhard Posselt 2016
  5. # Generic Makefile for building and packaging an ownCloud app which uses npm and
  6. # Composer.
  7. #
  8. # Dependencies:
  9. # * make
  10. # * which
  11. # * curl: used if phpunit and composer are not installed to fetch them from the web
  12. # * tar: for building the archive
  13. # * npm: for building and testing everything JS
  14. #
  15. # If no composer.json is in the app root directory, the Composer step
  16. # will be skipped. The same goes for the package.json which can be located in
  17. # the app root or the js/ directory.
  18. #
  19. # The npm command by launches the npm build script:
  20. #
  21. # npm run build
  22. #
  23. # The npm test command launches the npm test script:
  24. #
  25. # npm run test
  26. #
  27. # The idea behind this is to be completely testing and build tool agnostic. All
  28. # build tools and additional package managers should be installed locally in
  29. # your project, since this won't pollute people's global namespace.
  30. #
  31. # The following npm scripts in your package.json install and update the bower
  32. # and npm dependencies and use gulp as build system (notice how everything is
  33. # run from the node_modules folder):
  34. #
  35. # "scripts": {
  36. # "test": "node node_modules/gulp-cli/bin/gulp.js karma",
  37. # "prebuild": "npm install && node_modules/bower/bin/bower install && node_modules/bower/bin/bower update",
  38. # "build": "node node_modules/gulp-cli/bin/gulp.js"
  39. # },
  40. app_name=$(notdir $(CURDIR))
  41. build_tools_directory=$(CURDIR)/build/tools
  42. source_build_directory=$(CURDIR)/build/artifacts/source
  43. source_package_name=$(source_build_directory)/$(app_name)
  44. appstore_build_directory=$(CURDIR)/build/artifacts/appstore
  45. appstore_package_name=$(appstore_build_directory)/$(app_name)
  46. npm=$(shell which npm 2> /dev/null)
  47. composer=$(shell which composer 2> /dev/null)
  48. all: build
  49. # Fetches the PHP and JS dependencies and compiles the JS. If no composer.json
  50. # is present, the composer step is skipped, if no package.json or js/package.json
  51. # is present, the npm step is skipped
  52. .PHONY: build
  53. build:
  54. ifneq (,$(wildcard $(CURDIR)/composer.json))
  55. make composer
  56. endif
  57. ifneq (,$(wildcard $(CURDIR)/package.json))
  58. make npm
  59. endif
  60. ifneq (,$(wildcard $(CURDIR)/js/package.json))
  61. make npm
  62. endif
  63. # Installs and updates the composer dependencies. If composer is not installed
  64. # a copy is fetched from the web
  65. .PHONY: composer
  66. composer:
  67. ifeq (, $(composer))
  68. @echo "No composer command available, downloading a copy from the web"
  69. mkdir -p $(build_tools_directory)
  70. curl -sS https://getcomposer.org/installer | php
  71. mv composer.phar $(build_tools_directory)
  72. php $(build_tools_directory)/composer.phar install --prefer-dist
  73. php $(build_tools_directory)/composer.phar update --prefer-dist
  74. else
  75. composer install --prefer-dist
  76. composer update --prefer-dist
  77. endif
  78. # Installs npm dependencies
  79. .PHONY: npm
  80. npm:
  81. ifeq (,$(wildcard $(CURDIR)/package.json))
  82. cd js && $(npm) run build
  83. else
  84. npm run build
  85. endif
  86. # Removes the appstore build
  87. .PHONY: clean
  88. clean:
  89. rm -rf ./build
  90. # Same as clean but also removes dependencies installed by composer, bower and
  91. # npm
  92. .PHONY: distclean
  93. distclean: clean
  94. rm -rf vendor
  95. rm -rf node_modules
  96. rm -rf js/vendor
  97. rm -rf js/node_modules
  98. # Builds the source and appstore package
  99. .PHONY: dist
  100. dist:
  101. make source
  102. make appstore
  103. # Builds the source package
  104. .PHONY: source
  105. source:
  106. rm -rf $(source_build_directory)
  107. mkdir -p $(source_build_directory)
  108. tar cvzf $(source_package_name).tar.gz --exclude-vcs \
  109. --exclude="../$(app_name)/build" \
  110. --exclude="../$(app_name)/js/node_modules" \
  111. --exclude="../$(app_name)/node_modules" \
  112. --exclude="../$(app_name)/*.log" \
  113. --exclude="../$(app_name)/js/*.log" \
  114. ../$(app_name) \
  115. # Builds the source package for the app store, ignores php and js tests
  116. .PHONY: appstore
  117. appstore:
  118. rm -rf $(appstore_build_directory)
  119. mkdir -p $(appstore_build_directory)
  120. tar cvzf $(appstore_package_name).tar.gz \
  121. --exclude="../$(app_name)/build" \
  122. --exclude="../$(app_name)/tests" \
  123. --exclude="../$(app_name)/Makefile" \
  124. --exclude="../$(app_name)/*.log" \
  125. --exclude="../$(app_name)/phpunit*xml" \
  126. --exclude="../$(app_name)/composer.*" \
  127. --exclude="../$(app_name)/js/node_modules" \
  128. --exclude="../$(app_name)/js/tests" \
  129. --exclude="../$(app_name)/js/test" \
  130. --exclude="../$(app_name)/js/*.log" \
  131. --exclude="../$(app_name)/js/package.json" \
  132. --exclude="../$(app_name)/js/bower.json" \
  133. --exclude="../$(app_name)/js/karma.*" \
  134. --exclude="../$(app_name)/js/protractor.*" \
  135. --exclude="../$(app_name)/package.json" \
  136. --exclude="../$(app_name)/bower.json" \
  137. --exclude="../$(app_name)/karma.*" \
  138. --exclude="../$(app_name)/protractor\.*" \
  139. --exclude="../$(app_name)/.*" \
  140. --exclude="../$(app_name)/js/.*" \
  141. --exclude-vcs \
  142. ../$(app_name)
  143. # Command for running JS and PHP tests. Works for package.json files in the js/
  144. # and root directory. If phpunit is not installed systemwide, a copy is fetched
  145. # from the internet
  146. .PHONY: test
  147. test:
  148. ifneq (,$(wildcard $(CURDIR)/js/package.json))
  149. cd js && $(npm) run test
  150. endif
  151. ifneq (,$(wildcard $(CURDIR)/package.json))
  152. $(npm) run test
  153. endif
  154. ifeq (, $(shell which phpunit 2> /dev/null))
  155. @echo "No phpunit command available, downloading a copy from the web"
  156. mkdir -p $(build_tools_directory)
  157. curl -sSL https://phar.phpunit.de/phpunit.phar -o $(build_tools_directory)/phpunit.phar
  158. php $(build_tools_directory)/phpunit.phar -c phpunit.xml
  159. php $(build_tools_directory)/phpunit.phar -c phpunit.integration.xml
  160. else
  161. phpunit -c phpunit.xml --coverage-clover build/php-unit.clover
  162. phpunit -c phpunit.integration.xml --coverage-clover build/php-unit.clover
  163. endif