nextcloud-raw/ Makefile
158 lines
4.9 KiB

  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 a Nextcloud 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 ../$(app_name) \
  109. --exclude-vcs \
  110. --exclude="../$(app_name)/build" \
  111. --exclude="../$(app_name)/js/node_modules" \
  112. --exclude="../$(app_name)/node_modules" \
  113. --exclude="../$(app_name)/*.log" \
  114. --exclude="../$(app_name)/js/*.log" \
  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 ../$(app_name) \
  121. --exclude-vcs \
  122. --exclude="../$(app_name)/build" \
  123. --exclude="../$(app_name)/tests" \
  124. --exclude="../$(app_name)/Makefile" \
  125. --exclude="../$(app_name)/*.log" \
  126. --exclude="../$(app_name)/phpunit*xml" \
  127. --exclude="../$(app_name)/composer.*" \
  128. --exclude="../$(app_name)/js/node_modules" \
  129. --exclude="../$(app_name)/js/tests" \
  130. --exclude="../$(app_name)/js/test" \
  131. --exclude="../$(app_name)/js/*.log" \
  132. --exclude="../$(app_name)/js/package.json" \
  133. --exclude="../$(app_name)/js/bower.json" \
  134. --exclude="../$(app_name)/js/karma.*" \
  135. --exclude="../$(app_name)/js/protractor.*" \
  136. --exclude="../$(app_name)/package.json" \
  137. --exclude="../$(app_name)/bower.json" \
  138. --exclude="../$(app_name)/karma.*" \
  139. --exclude="../$(app_name)/protractor\.*" \
  140. --exclude="../$(app_name)/.*" \
  141. --exclude="../$(app_name)/js/.*" \
  142. .PHONY: test
  143. test: composer
  144. $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.xml
  145. $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml