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