news/Makefile

176 строки
5.5 KiB
Makefile
Исходник Обычный вид История

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>
# @copyright Bernhard Posselt 2012, 2014
2016-03-25 21:35:37 +03:00
# Generic Makefile for building and packaging an ownCloud app which uses npm and
# 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.
#
# 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):
#
2016-03-25 22:12:32 +03:00
# "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"
# },
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
source_build_directory=$(CURDIR)/build/artifacts/source
source_package_name=$(source_build_directory)/$(app_name)
appstore_build_directory=$(CURDIR)/build/artifacts/appstore
appstore_package_name=$(appstore_build_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-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:
2016-03-25 22:10:42 +03:00
ifneq (,$(wildcard $(CURDIR)/composer.json))
2016-03-25 19:54:22 +03:00
make composer
2016-03-25 22:10:42 +03:00
endif
ifneq (,$(wildcard $(CURDIR)/package.json))
make npm
endif
ifneq (,$(wildcard $(CURDIR)/js/package.json))
2016-03-25 19:54:22 +03:00
make npm
2016-03-25 22:10:42 +03:00
endif
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:
ifeq (,$(wildcard $(CURDIR)/package.json))
2016-03-25 20:24:17 +03:00
cd js && $(npm) run build
else
npm run build
endif
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
2016-03-25 21:11:14 +03:00
# Same as clean but also removes dependencies installed by composer, bower and
# npm
2016-03-25 19:57:29 +03:00
.PHONY: distclean
distclean: clean
rm -rf vendor
rm -rf node_modules
2016-03-25 19:57:29 +03:00
rm -rf js/vendor
rm -rf js/node_modules
# Builds the source and appstore package
2016-03-25 19:54:22 +03:00
.PHONY: dist
dist:
make source
make appstore
# Builds the source package
.PHONY: source
source:
2016-03-25 19:54:22 +03:00
make build
rm -rf $(source_build_directory)
2016-03-25 21:45:29 +03:00
mkdir -p $(source_build_directory)
tar cvzf $(source_package_name).tar.gz ../$(app_name) \
2014-05-31 01:04:35 +04:00
--exclude-vcs \
2016-03-25 22:10:42 +03:00
--exclude="../$(app_name)/build" \
--exclude="../$(app_name)/js/node_modules" \
--exclude="../$(app_name)/*.log" \
--exclude="../$(app_name)/js/*.log" \
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:
make build
rm -rf $(appstore_build_directory)
2016-03-25 21:45:29 +03:00
mkdir -p $(appstore_build_directory)
tar cvzf $(appstore_package_name).tar.gz ../$(app_name) \
--exclude-vcs \
2016-03-25 22:10:42 +03:00
--exclude="../$(app_name)/build" \
--exclude="../$(app_name)/tests" \
--exclude="../$(app_name)/Makefile" \
--exclude="../$(app_name)/*.log" \
--exclude="../$(app_name)/phpunit*xml" \
--exclude="../$(app_name)/composer.*" \
--exclude="../$(app_name)/js/node_modules" \
--exclude="../$(app_name)/js/tests" \
--exclude="../$(app_name)/js/test" \
--exclude="../$(app_name)/js/*.log" \
--exclude="../$(app_name)/js/package.json" \
--exclude="../$(app_name)/js/bower.json" \
--exclude="../$(app_name)/js/karma.*" \
--exclude="../$(app_name)/js/protractor.*" \
--exclude="../$(app_name)/package.json" \
--exclude="../$(app_name)/bower.json" \
--exclude="../$(app_name)/karma.*" \
--exclude="../$(app_name)/protractor\.*" \
--exclude="../$(app_name)/.*" \
--exclude="../$(app_name)/js/.*" \
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:
ifneq (,$(wildcard $(CURDIR)/js/package.json))
2016-03-25 20:24:17 +03:00
cd js && $(npm) run test
endif
ifneq (,$(wildcard $(CURDIR)/package.json))
$(npm) run test
2016-03-25 21:11:14 +03:00
endif
ifeq (, $(shell which phpunit 2> /dev/null))
@echo "No phpunit command available, downloading a copy from the web"
2016-03-25 21:45:29 +03:00
mkdir -p $(build_tools_directory)
curl -sSL https://phar.phpunit.de/phpunit.phar -o $(build_tools_directory)/phpunit.phar
php $(build_tools_directory)/phpunit.phar -c phpunit.xml
php $(build_tools_directory)/phpunit.phar -c phpunit.integration.xml
2016-03-25 21:11:14 +03:00
else
2016-03-25 19:54:22 +03:00
phpunit -c phpunit.xml
phpunit -c phpunit.integration.xml
2016-03-25 21:11:14 +03:00
endif