From 77665792d704adaa68dbbb3d7df93321b74d5add Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 3 Jan 2015 13:24:04 -0800 Subject: [PATCH] setup.sh - Adapt to local version of composer/bower/karma * For developers who work with many builds, it's better to have one copy of bower/karma rather than reinstalling an extra 50mb for each build. If a system already has a copy of these, then don't forcibly download them. (If you really want extra copies, you can run "npm install" yourself.) * Documentation for composer is historically a bit inconsistent about whether to use "composer" or "composer.phar". Work with either. --- bin/npm_postinstall.sh | 2 -- bin/setup.lib.sh | 25 ++++++++++++++++++++++++- bin/setup.sh | 15 ++++++++++++--- package.json | 10 +++++++--- tools/scripts/npm/postinstall.sh | 4 ++++ tools/scripts/npm/test.sh | 9 +++++++++ 6 files changed, 56 insertions(+), 9 deletions(-) delete mode 100644 bin/npm_postinstall.sh create mode 100644 tools/scripts/npm/postinstall.sh create mode 100644 tools/scripts/npm/test.sh diff --git a/bin/npm_postinstall.sh b/bin/npm_postinstall.sh deleted file mode 100644 index 9308d36442..0000000000 --- a/bin/npm_postinstall.sh +++ /dev/null @@ -1,2 +0,0 @@ -find node_modules/ -name '*.info' -type f -delete -node node_modules/bower/bin/bower install diff --git a/bin/setup.lib.sh b/bin/setup.lib.sh index 8ee4db00ad..d98f2f52e2 100644 --- a/bin/setup.lib.sh +++ b/bin/setup.lib.sh @@ -31,4 +31,27 @@ function mysqladmin_cmd() { function mysqldump_cmd() { _mysql_vars echo "mysqldump -u$DBUSER $PASSWDSECTION $HOSTSECTION $PORTSECTION $DBARGS" -} \ No newline at end of file +} + +## Pick the first available command. If none, then abort. +## example: COMPOSER=$(pickcmd composer composer.phar) +function pickcmd() { + for name in "$@" ; do + if which $name >> /dev/null ; then + echo $name + return + fi + done + echo "ERROR: Failed to find any of these commands: $@" + exit 1 +} + +## usage: has_commands ... +function has_commands() { + for cmd in "$@" ; do + if ! which $cmd >> /dev/null ; then + return 1 + fi + done + return 0 +} diff --git a/bin/setup.sh b/bin/setup.sh index 9696cd5c2f..5261c2ee39 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -131,9 +131,18 @@ set -x if [ -n "$DO_DOWNLOAD" ]; then pushd "$CALLEDPATH/.." - composer install - # Install npm and bower modules - npm install + COMPOSER=$(pickcmd composer composer.phar) + $COMPOSER install + + if has_commands bower karma ; then + ## dev dependencies have been installed globally; don't force developer to redownload + npm install --production + else + npm install + fi + + BOWER=$(pickcmd node_modules/bower/bin/bower bower) + $BOWER install popd fi diff --git a/package.json b/package.json index 51a99add26..61e7bdb36a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,11 @@ "main": "index.js", "license": "MIT", "name": "civicrm", - "version": "5.0.0", + "version": "4.6.0", + "repository": { + "type": "git", + "url": "git://github.com/civicrm/civicrm-core.git" + }, "devDependencies": { "bower": "^1.3.1", "karma": "^0.12.16", @@ -12,7 +16,7 @@ "karma-jasmine": "~0.3.2" }, "scripts": { - "postinstall": "bash bin/npm_postinstall.sh", - "test": "node node_modules/karma/bin/karma start tests/karma.conf.js" + "postinstall": "bash tools/scripts/npm/postinstall.sh", + "test": "bash tools/scripts/npm/test.sh" } } diff --git a/tools/scripts/npm/postinstall.sh b/tools/scripts/npm/postinstall.sh new file mode 100644 index 0000000000..e79ddd6d6d --- /dev/null +++ b/tools/scripts/npm/postinstall.sh @@ -0,0 +1,4 @@ +#!/bin/bash +if [ -d node_modules ]; then + find node_modules/ -name '*.info' -type f -delete +fi diff --git a/tools/scripts/npm/test.sh b/tools/scripts/npm/test.sh new file mode 100644 index 0000000000..40ac68bcf4 --- /dev/null +++ b/tools/scripts/npm/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +if which node_modules/karma/bin/karma >> /dev/null; then + node node_modules/karma/bin/karma start tests/karma.conf.js +elif which karma >> /dev/null ; then + karma start tests/karma.conf.js +else + echo "ERROR: Failed to find karma" + exit 1 +fi -- 2.25.1