Update makefile taked from nextcloud-notes

This commit is contained in:
Matias De lellis
2018-04-27 11:19:23 -03:00
parent a158a38fff
commit 19e142f0c4

234
Makefile
View File

@@ -1,98 +1,38 @@
# This file is licensed under the Affero General Public License version 3 or #
# later. See the COPYING file. # Nextcloud scaffolder tool
# @author Bernhard Posselt <dev@bernhard-posselt.com> #
# @copyright Bernhard Posselt 2012, 2014 # Copyright (C) 2013 Bernhard Posselt, <nukewhale@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Generic Makefile for building and packaging an ownCloud app which uses npm and # Makefile for building the project
# Composer. app_name=quicknotes
# project_dir=$(CURDIR)/../$(app_name)
# Dependencies: build_dir=$(CURDIR)/build/artifacts
# * make sign_dir=$(build_dir)/sign
# * which appstore_dir=$(build_dir)/appstore
# * curl: used if phpunit and composer are not installed to fetch them from the web package_name=$(app_name)
# * tar: for building the archive cert_dir=$(HOME)/.nextcloud/certificates
# * 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
# the 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_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)
npm=$(shell which npm 2> /dev/null)
composer=$(shell which composer 2> /dev/null)
# building the javascript
all: build all: build
build: deps
# Fetches the PHP and JS dependencies and compiles the JS. If no composer.json # general
# is present, the composer step is skipped, if no package.json or js/package.json
# is present, the npm step is skipped
.PHONY: build
build:
ifneq (,$(wildcard $(CURDIR)/composer.json))
make composer
endif
ifneq (,$(wildcard $(CURDIR)/package.json))
make npm
endif
ifneq (,$(wildcard $(CURDIR)/js/package.json))
make npm
endif
# Installs and updates the composer dependencies. If composer is not installed
# a copy is fetched from the web
.PHONY: composer
composer:
ifeq (, $(composer))
@echo "No composer command available, downloading a copy from the web"
mkdir -p $(build_tools_directory)
curl -sS https://getcomposer.org/installer | php
mv composer.phar $(build_tools_directory)
php $(build_tools_directory)/composer.phar install --prefer-dist
php $(build_tools_directory)/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
deps: deps:
mkdir -p vendor mkdir -p vendor
rm vendor/* rm -rf vendor/*
wget http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v4.0.5.js wget http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v4.0.5.js
mv handlebars-v4.0.5.js vendor/handlebars.js mv handlebars-v4.0.5.js vendor/handlebars.js
@@ -113,7 +53,7 @@ deps:
depsmin: depsmin:
mkdir -p vendor mkdir -p vendor
rm vendor/* rm -rf vendor/*
wget http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v4.0.5.js wget http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v4.0.5.js
mv handlebars-v4.0.5.js vendor/handlebars.js mv handlebars-v4.0.5.js vendor/handlebars.js
@@ -132,89 +72,49 @@ depsmin:
wget https://github.com/varun-raj/medium-editor-autolist/raw/master/dist/autolist.min.js wget https://github.com/varun-raj/medium-editor-autolist/raw/master/dist/autolist.min.js
mv autolist.min.js vendor/autolist.js mv autolist.min.js vendor/autolist.js
# Removes the appstore build
.PHONY: clean
clean: clean:
rm -rf ./build rm -rf $(build_dir)
rm -rf vendor/*
# Same as clean but also removes dependencies installed by composer, bower and
# npm
.PHONY: distclean
distclean: clean distclean: clean
rm -rf vendor rm -rf vendor
rm -rf node_modules rm -rf node_modules
rm -rf js/vendor rm -rf js/vendor
rm -rf js/node_modules rm -rf js/node_modules
# Builds the source and appstore package dist: appstore
.PHONY: dist
dist:
make source
make appstore
# Builds the source package appstore: distclean depsmin
.PHONY: source mkdir -p $(sign_dir)
source: rsync -a \
make build --exclude=.git \
make test --exclude=build \
rm -rf $(source_build_directory) --exclude=.gitignore \
mkdir -p $(source_build_directory) --exclude=.travis.yml \
tar cvzf $(source_package_name).tar.gz ../$(app_name) \ --exclude=.scrutinizer.yml \
--exclude-vcs \ --exclude=CONTRIBUTING.md \
--exclude="../$(app_name)/build" \ --exclude=composer.json \
--exclude="../$(app_name)/js/node_modules" \ --exclude=composer.lock \
--exclude="../$(app_name)/*.log" \ --exclude=composer.phar \
--exclude="../$(app_name)/js/*.log" \ --exclude=.tx \
--exclude=l10n/no-php \
# Builds the source package for the app store, ignores php and js tests --exclude=Makefile \
.PHONY: appstore --exclude=nbproject \
appstore: --exclude=screenshots \
make build --exclude=phpunit*xml \
make test --exclude=tests \
rm -rf $(appstore_build_directory) --exclude=vendor/bin \
mkdir -p $(appstore_build_directory) --exclude=js/node_modules \
tar cvzf $(appstore_package_name).tar.gz ../$(app_name) \ --exclude=js/tests \
--exclude-vcs \ --exclude=js/karma.conf.js \
--exclude="../$(app_name)/build" \ --exclude=js/gulpfile.js \
--exclude="../$(app_name)/tests" \ --exclude=js/bower.json \
--exclude="../$(app_name)/Makefile" \ --exclude=js/package.json \
--exclude="../$(app_name)/*.log" \ $(project_dir) $(sign_dir)
--exclude="../$(app_name)/phpunit*xml" \ @echo "Signing…"
--exclude="../$(app_name)/composer.*" \ php ../../occ integrity:sign-app \
--exclude="../$(app_name)/js/node_modules" \ --privateKey=$(cert_dir)/$(app_name).key\
--exclude="../$(app_name)/js/tests" \ --certificate=$(cert_dir)/$(app_name).crt\
--exclude="../$(app_name)/js/test" \ --path=$(sign_dir)/$(app_name)
--exclude="../$(app_name)/js/*.log" \ tar -czf $(build_dir)/$(app_name).tar.gz \
--exclude="../$(app_name)/js/package.json" \ -C $(sign_dir) $(app_name)
--exclude="../$(app_name)/js/bower.json" \ openssl dgst -sha512 -sign $(cert_dir)/$(app_name).key $(build_dir)/$(app_name).tar.gz | openssl base64
--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/.*" \
# 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:
ifneq (,$(wildcard $(CURDIR)/js/package.json))
cd js && $(npm) run test
endif
ifneq (,$(wildcard $(CURDIR)/package.json))
$(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_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
else
phpunit -c phpunit.xml
phpunit -c phpunit.integration.xml
endif