setup.sh - Adapt to local version of composer/bower/karma
authorTim Otten <totten@civicrm.org>
Sat, 3 Jan 2015 21:24:04 +0000 (13:24 -0800)
committerTim Otten <totten@civicrm.org>
Sat, 3 Jan 2015 21:24:04 +0000 (13:24 -0800)
 * 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 [deleted file]
bin/setup.lib.sh
bin/setup.sh
package.json
tools/scripts/npm/postinstall.sh [new file with mode: 0644]
tools/scripts/npm/test.sh [new file with mode: 0644]

diff --git a/bin/npm_postinstall.sh b/bin/npm_postinstall.sh
deleted file mode 100644 (file)
index 9308d36..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-find node_modules/ -name '*.info' -type f -delete
-node node_modules/bower/bin/bower install
index 8ee4db00add4f2bc063da82c8e1e358a47dd24ee..d98f2f52e27b1bcb1a9baf6719fb2720f8f16225 100644 (file)
@@ -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 <cmd1> <cmd2> ...
+function has_commands() {
+  for cmd in "$@" ; do
+    if ! which $cmd >> /dev/null ; then
+      return 1
+    fi
+  done
+  return 0
+}
index 9696cd5c2f529c3bd11b15c377e357f6899056bf..5261c2ee39ba299fedf1860cfe39ebb67252e40b 100755 (executable)
@@ -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
 
index 51a99add26b1751149d4d15b6e8be993fdea3740..61e7bdb36a78d6a023ff884554339a0bf7fb6bcc 100644 (file)
@@ -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 (file)
index 0000000..e79ddd6
--- /dev/null
@@ -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 (file)
index 0000000..40ac68b
--- /dev/null
@@ -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