summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 37cd7a1dbfa62e8ce69ff2e19edb7cdb8401599e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# This file is licensed under the Affero General Public License version 3 or
# later. See the COPYING file.
# @author Bernhard Posselt <dev@bernhard-posselt.com>
# @copyright Bernhard Posselt 2012, 2014

# Generic Makefile for building and packaging an ownCloud app which uses npm and
# Composer.
#
# Dependencies:
# * make
# * curl: used if phpunit and composer are not installed to fetch them from the web
# * tar: for building the archive
# * npm: for building and testing everything JS
#
# If no composer.json is in the app root directory, the Composer step
# will be skipped. The same goes for the package.json which can be located in
# app root or the js/ directory.
#
# The npm command by launches the npm build script:
#
#   npm run build
#
# The npm test command launches the npm test script:
#
#	npm run test
#
# The idea behind this is to be completely testing and build tool agnostic. All
# build tools and additional package managers should be installed locally in
# your project, since this won't pollute people's global namespace.
#
# The following npm scripts in your package.json install and update the bower
# and npm dependencies and use gulp as build system (notice how everything is
# run from the node_modules folder):
#
#	"scripts": {
#	    "test": "node node_modules/gulp-cli/bin/gulp.js karma",
#	    "prebuild": "npm install && node_modules/bower/bin/bower install && node_modules/bower/bin/bower update",
#		"build": "node node_modules/gulp-cli/bin/gulp.js"
#	},
app_name=$(notdir $(CURDIR))
build_directory=$(CURDIR)/build/artifacts/source
package_name=$(build_directory)/$(app_name)
npm=$(shell which npm 2> /dev/null)

all: build

# Fetches the PHP and JS dependencies and compiles the JS
.PHONY: build
build:
	make composer
	make npm

# Installs and updates the composer dependencies. If composer is not installed
# a copy is fetched from the web
.PHONY: composer
composer:
ifeq (, $(shell which composer 2> /dev/null))
	@echo "No composer command available, downloading a copy from the web"
	mkdir -p build/tools
	curl -sS https://getcomposer.org/installer | php
	mv composer.phar build/tools/
	php build/tools/composer.phar install --prefer-dist
	php build/tools/composer.phar update --prefer-dist
else
	composer install --prefer-dist
	composer update --prefer-dist
endif

# Installs npm dependencies
.PHONY: npm
npm:
ifeq (,$(wildcard $(CURDIR)/package.json))
	cd js && $(npm) run build
else
	npm run build
endif

# Removes the appstore build
.PHONY: clean
clean:
	rm -rf ./build

# Same as clean but also removes dependencies installed by composer, bower and
# npm
.PHONY: distclean
distclean: clean
	rm -rf vendor
	rm -rf js/vendor
	rm -rf js/node_modules

# Builds the package for the app store
.PHONY: dist
dist:
	make clean
	make build
	make test
	mkdir -p $(build_directory)
	tar cvzf $(package_name).tar.gz ../$(app_name) \
	--exclude-vcs \
	--exclude=../$(app_name)/build \
	--exclude=../$(app_name)/js/node_modules \


# Command for running JS and PHP tests. Works for package.json files in the js/
# and root directory. If phpunit is not installed systemwide, a copy is fetched
# from the internet
.PHONY: test
test:
ifeq (,$(wildcard $(CURDIR)/package.json))
	cd js && $(npm) run test
else
	npm run test
endif
ifeq (, $(shell which phpunit 2> /dev/null))
	@echo "No phpunit command available, downloading a copy from the web"
	mkdir -p build/tools
	curl -sSL https://phar.phpunit.de/phpunit.phar -o build/tools/phpunit.phar
	php build/tools/phpunit.phar -c phpunit.xml
	php build/tools/phpunit.phar -c phpunit.integration.xml
else
	phpunit -c phpunit.xml
	phpunit -c phpunit.integration.xml
endif