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 2012, 2014
5
+
6
+ # Generic Makefile for building and packaging an ownCloud 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
+ make build
117
+ make test
118
+ rm -rf $(source_build_directory )
119
+ mkdir -p $(source_build_directory )
120
+ tar cvzf $(source_package_name ) .tar.gz ../$(app_name ) \
121
+ --exclude-vcs \
122
+ --exclude=" ../$( app_name) /build" \
123
+ --exclude=" ../$( app_name) /js/node_modules" \
124
+ --exclude=" ../$( app_name) /*.log" \
125
+ --exclude=" ../$( app_name) /js/*.log" \
126
+
127
+ # Builds the source package for the app store, ignores php and js tests
128
+ .PHONY : appstore
129
+ appstore :
130
+ make build
131
+ make test
132
+ rm -rf $(appstore_build_directory )
133
+ mkdir -p $(appstore_build_directory )
134
+ tar cvzf $(appstore_package_name ) .tar.gz ../$(app_name ) \
135
+ --exclude-vcs \
136
+ --exclude=" ../$( app_name) /build" \
137
+ --exclude=" ../$( app_name) /tests" \
138
+ --exclude=" ../$( app_name) /Makefile" \
139
+ --exclude=" ../$( app_name) /*.log" \
140
+ --exclude=" ../$( app_name) /phpunit*xml" \
141
+ --exclude=" ../$( app_name) /composer.*" \
142
+ --exclude=" ../$( app_name) /js/node_modules" \
143
+ --exclude=" ../$( app_name) /js/tests" \
144
+ --exclude=" ../$( app_name) /js/test" \
145
+ --exclude=" ../$( app_name) /js/*.log" \
146
+ --exclude=" ../$( app_name) /js/package.json" \
147
+ --exclude=" ../$( app_name) /js/bower.json" \
148
+ --exclude=" ../$( app_name) /js/karma.*" \
149
+ --exclude=" ../$( app_name) /js/protractor.*" \
150
+ --exclude=" ../$( app_name) /package.json" \
151
+ --exclude=" ../$( app_name) /bower.json" \
152
+ --exclude=" ../$( app_name) /karma.*" \
153
+ --exclude=" ../$( app_name) /protractor\.*" \
154
+ --exclude=" ../$( app_name) /.*" \
155
+ --exclude=" ../$( app_name) /js/.*" \
156
+
157
+ # Command for running JS and PHP tests. Works for package.json files in the js/
158
+ # and root directory. If phpunit is not installed systemwide, a copy is fetched
159
+ # from the internet
160
+ .PHONY : test
161
+ test :
162
+ ifneq (,$(wildcard $(CURDIR ) /js/package.json) )
163
+ cd js && $(npm) run test
164
+ endif
165
+ ifneq (,$(wildcard $(CURDIR ) /package.json) )
166
+ $(npm) run test
167
+ endif
168
+ ifeq (, $(shell which phpunit 2> /dev/null) )
169
+ @echo "No phpunit command available, downloading a copy from the web"
170
+ mkdir -p $(build_tools_directory)
171
+ curl -sSL https://phar.phpunit.de/phpunit.phar -o $(build_tools_directory)/phpunit.phar
172
+ php $(build_tools_directory)/phpunit.phar -c phpunit.xml
173
+ php $(build_tools_directory)/phpunit.phar -c phpunit.integration.xml
174
+ else
175
+ phpunit -c phpunit.xml
176
+ phpunit -c phpunit.integration.xml
177
+ endif
0 commit comments