2016-03-25 21:11:14 +03:00
|
|
|
# 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>
|
2016-03-27 00:31:27 +03:00
|
|
|
# @copyright Bernhard Posselt 2016
|
2016-03-25 21:11:14 +03:00
|
|
|
|
2016-07-23 23:02:21 +03:00
|
|
|
# Generic Makefile for building and packaging a Nextcloud app which uses npm and
|
2016-03-25 21:35:37 +03:00
|
|
|
# Composer.
|
2016-03-25 21:11:14 +03:00
|
|
|
#
|
|
|
|
# Dependencies:
|
|
|
|
# * make
|
2016-03-25 22:10:42 +03:00
|
|
|
# * which
|
2016-03-25 21:35:37 +03:00
|
|
|
# * curl: used if phpunit and composer are not installed to fetch them from the web
|
2016-03-25 21:11:14 +03:00
|
|
|
# * tar: for building the archive
|
|
|
|
# * npm: for building and testing everything JS
|
2016-03-25 21:35:37 +03:00
|
|
|
#
|
|
|
|
# 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
|
2016-03-25 22:14:59 +03:00
|
|
|
# the app root or the js/ directory.
|
2016-03-25 21:35:37 +03:00
|
|
|
#
|
|
|
|
# The npm command by launches the npm build script:
|
|
|
|
#
|
2016-03-25 22:12:32 +03:00
|
|
|
# npm run build
|
2016-03-25 21:35:37 +03:00
|
|
|
#
|
|
|
|
# The npm test command launches the npm test script:
|
|
|
|
#
|
2016-03-25 22:12:32 +03:00
|
|
|
# npm run test
|
2016-03-25 21:35:37 +03:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2017-06-18 13:19:38 +03:00
|
|
|
# The following npm scripts in your package.json install the npm dependencies
|
|
|
|
# and use gulp as build system (notice how everything is run from the
|
|
|
|
# node_modules folder):
|
2016-03-25 21:35:37 +03:00
|
|
|
#
|
2016-03-25 22:12:32 +03:00
|
|
|
# "scripts": {
|
|
|
|
# "test": "node node_modules/gulp-cli/bin/gulp.js karma",
|
2017-06-18 13:19:38 +03:00
|
|
|
# "prebuild": "npm install",
|
2016-03-25 22:12:32 +03:00
|
|
|
# "build": "node node_modules/gulp-cli/bin/gulp.js"
|
|
|
|
# },
|
2016-03-25 22:11:25 +03:00
|
|
|
|
2016-03-25 19:54:22 +03:00
|
|
|
app_name=$(notdir $(CURDIR))
|
2016-03-25 21:45:29 +03:00
|
|
|
build_tools_directory=$(CURDIR)/build/tools
|
2016-04-21 00:37:05 +03:00
|
|
|
source_build_directory=$(CURDIR)/build/source/news
|
|
|
|
source_artifact_directory=$(CURDIR)/build/artifacts/source
|
|
|
|
source_package_name=$(source_artifact_directory)/$(app_name)
|
|
|
|
appstore_build_directory=$(CURDIR)/build/appstore/news
|
|
|
|
appstore_artifact_directory=$(CURDIR)/build/artifacts/appstore
|
|
|
|
appstore_package_name=$(appstore_artifact_directory)/$(app_name)
|
2016-03-25 21:35:37 +03:00
|
|
|
npm=$(shell which npm 2> /dev/null)
|
2016-03-25 22:10:42 +03:00
|
|
|
composer=$(shell which composer 2> /dev/null)
|
2014-05-15 06:46:32 +04:00
|
|
|
|
2016-04-21 01:20:00 +03:00
|
|
|
# code signing
|
|
|
|
# assumes the following:
|
2016-07-23 23:02:21 +03:00
|
|
|
# * the app is inside the nextcloud/apps folder
|
|
|
|
# * the private key is located in ~/.nextcloud/news.key
|
|
|
|
# * the certificate is located in ~/.nextcloud/news.crt
|
2016-04-21 01:20:00 +03:00
|
|
|
occ=$(CURDIR)/../../occ
|
2016-07-23 23:02:21 +03:00
|
|
|
private_key=$(HOME)/.nextcloud/$(app_name).key
|
|
|
|
certificate=$(HOME)/.nextcloud/$(app_name).crt
|
2016-04-21 18:34:55 +03:00
|
|
|
sign=php -f $(occ) integrity:sign-app --privateKey="$(private_key)" --certificate="$(certificate)"
|
2016-04-21 01:32:03 +03:00
|
|
|
sign_skip_msg="Skipping signing, either no key and certificate found in $(private_key) and $(certificate) or occ can not be found at $(occ)"
|
|
|
|
ifneq (,$(wildcard $(private_key)))
|
|
|
|
ifneq (,$(wildcard $(certificate)))
|
|
|
|
ifneq (,$(wildcard $(occ)))
|
|
|
|
CAN_SIGN=true
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
2016-04-21 01:20:00 +03:00
|
|
|
|
2016-03-25 19:54:22 +03:00
|
|
|
all: build
|
2014-05-15 06:46:32 +04:00
|
|
|
|
2016-03-25 22:10:42 +03:00
|
|
|
# Fetches the PHP and JS dependencies and compiles the JS. If no composer.json
|
|
|
|
# is present, the composer step is skipped, if no package.json or js/package.json
|
|
|
|
# is present, the npm step is skipped
|
2016-03-25 19:54:22 +03:00
|
|
|
.PHONY: build
|
|
|
|
build:
|
|
|
|
make composer
|
|
|
|
make npm
|
2014-05-15 06:46:32 +04:00
|
|
|
|
2016-03-25 21:11:14 +03:00
|
|
|
# Installs and updates the composer dependencies. If composer is not installed
|
|
|
|
# a copy is fetched from the web
|
2016-03-25 19:54:22 +03:00
|
|
|
.PHONY: composer
|
|
|
|
composer:
|
2016-03-25 22:10:42 +03:00
|
|
|
ifeq (, $(composer))
|
2016-03-25 21:11:14 +03:00
|
|
|
@echo "No composer command available, downloading a copy from the web"
|
2016-03-25 21:45:29 +03:00
|
|
|
mkdir -p $(build_tools_directory)
|
2016-03-25 19:54:22 +03:00
|
|
|
curl -sS https://getcomposer.org/installer | php
|
2016-03-25 21:45:29 +03:00
|
|
|
mv composer.phar $(build_tools_directory)
|
|
|
|
php $(build_tools_directory)/composer.phar install --prefer-dist
|
|
|
|
php $(build_tools_directory)/composer.phar update --prefer-dist
|
2016-03-25 20:24:17 +03:00
|
|
|
else
|
|
|
|
composer install --prefer-dist
|
|
|
|
composer update --prefer-dist
|
|
|
|
endif
|
2014-05-15 06:46:32 +04:00
|
|
|
|
2016-03-25 21:11:14 +03:00
|
|
|
# Installs npm dependencies
|
2016-03-25 19:54:22 +03:00
|
|
|
.PHONY: npm
|
|
|
|
npm:
|
2016-03-25 20:24:17 +03:00
|
|
|
cd js && $(npm) run build
|
2015-01-27 11:31:40 +03:00
|
|
|
|
2016-03-25 21:11:14 +03:00
|
|
|
# Removes the appstore build
|
2016-03-25 19:54:22 +03:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm -rf ./build
|
2014-05-15 06:46:32 +04:00
|
|
|
|
2017-06-18 13:19:38 +03:00
|
|
|
# Same as clean but also removes dependencies installed by composer and
|
2016-03-25 21:11:14 +03:00
|
|
|
# npm
|
2016-03-25 19:57:29 +03:00
|
|
|
.PHONY: distclean
|
|
|
|
distclean: clean
|
|
|
|
rm -rf vendor
|
2016-03-25 22:26:29 +03:00
|
|
|
rm -rf node_modules
|
2016-03-25 19:57:29 +03:00
|
|
|
rm -rf js/node_modules
|
|
|
|
|
2016-03-25 22:26:29 +03:00
|
|
|
# Builds the source and appstore package
|
2016-03-25 19:54:22 +03:00
|
|
|
.PHONY: dist
|
|
|
|
dist:
|
2016-03-25 22:26:29 +03:00
|
|
|
make source
|
|
|
|
make appstore
|
|
|
|
|
|
|
|
# Builds the source package
|
|
|
|
.PHONY: source
|
|
|
|
source:
|
2016-04-21 00:37:05 +03:00
|
|
|
rm -rf $(source_build_directory) $(source_artifact_directory)
|
|
|
|
mkdir -p $(source_build_directory) $(source_artifact_directory)
|
|
|
|
rsync -rv . $(source_build_directory) \
|
|
|
|
--exclude=/.git/ \
|
|
|
|
--exclude=/.idea/ \
|
|
|
|
--exclude=/build/ \
|
|
|
|
--exclude=/js/node_modules/ \
|
|
|
|
--exclude=*.log
|
2016-04-21 01:32:03 +03:00
|
|
|
ifdef CAN_SIGN
|
2016-04-21 20:28:19 +03:00
|
|
|
$(sign) --path "$(source_build_directory)"
|
2016-04-21 01:20:00 +03:00
|
|
|
else
|
2016-04-21 01:32:03 +03:00
|
|
|
@echo $(sign_skip_msg)
|
2016-04-21 01:20:00 +03:00
|
|
|
endif
|
2016-04-21 00:37:05 +03:00
|
|
|
tar -cvzf $(source_package_name).tar.gz -C $(source_build_directory)/../ $(app_name)
|
2016-03-25 19:54:22 +03:00
|
|
|
|
2016-03-25 21:45:29 +03:00
|
|
|
# Builds the source package for the app store, ignores php and js tests
|
|
|
|
.PHONY: appstore
|
|
|
|
appstore:
|
2016-04-21 00:37:05 +03:00
|
|
|
rm -rf $(appstore_build_directory) $(appstore_artifact_directory)
|
|
|
|
mkdir -p $(appstore_build_directory) $(appstore_artifact_directory)
|
|
|
|
cp --parents -r \
|
|
|
|
"appinfo" \
|
|
|
|
"css" \
|
|
|
|
"img" \
|
|
|
|
"l10n" \
|
2016-08-10 21:05:33 +03:00
|
|
|
"lib" \
|
2016-04-21 00:37:05 +03:00
|
|
|
"templates" \
|
|
|
|
"vendor" \
|
|
|
|
"COPYING" \
|
|
|
|
"AUTHORS.md" \
|
2016-10-02 17:57:11 +03:00
|
|
|
"CHANGELOG.md" \
|
2016-04-21 00:37:05 +03:00
|
|
|
"js/build/app.min.js" \
|
|
|
|
"js/admin/Admin.js" \
|
|
|
|
$(appstore_build_directory)
|
2016-04-21 01:32:03 +03:00
|
|
|
ifdef CAN_SIGN
|
2016-04-21 18:34:55 +03:00
|
|
|
$(sign) --path="$(appstore_build_directory)"
|
2016-04-21 01:20:00 +03:00
|
|
|
else
|
2016-04-21 01:32:03 +03:00
|
|
|
@echo $(sign_skip_msg)
|
2016-04-21 01:20:00 +03:00
|
|
|
endif
|
|
|
|
tar -czf $(appstore_package_name).tar.gz -C $(appstore_build_directory)/../ $(app_name)
|
2016-04-21 00:37:05 +03:00
|
|
|
|
2016-03-25 21:11:14 +03:00
|
|
|
|
|
|
|
# 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
|
2016-03-25 19:54:22 +03:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
2016-03-25 20:24:17 +03:00
|
|
|
cd js && $(npm) run test
|
2017-06-06 19:20:20 +03:00
|
|
|
./vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-clover build/php-unit.clover
|
|
|
|
# \Test\TestCase is only allowed to access the db if TRAVIS environment variable is set
|
|
|
|
env TRAVIS=1 ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml --coverage-clover build/php-unit.clover
|