From 1695d659923dd464eefb87301f6e7fc6702f906a Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 17 Jan 2014 12:10:38 -0800 Subject: [PATCH] Allow use of node from packages Change-Id: I4718d0b64f553db3453c1b80c0ea455cf1f685bc --- bin/bootstrap.sh | 15 ++++++++++++++- bin/build.sh | 11 ++--------- bin/setenv.sh | 10 ++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 bin/setenv.sh diff --git a/bin/bootstrap.sh b/bin/bootstrap.sh index 517c6bfd..37c4c8fb 100755 --- a/bin/bootstrap.sh +++ b/bin/bootstrap.sh @@ -19,10 +19,23 @@ rm -fr $workspace_path/.local/ rm -fr $workspace_path/.build/ # Create our working directories -mkdir -p $workspace_path/.local/ +mkdir -p $workspace_path/.local/bin/ mkdir -p $workspace_path/.build/ mkdir -p ~/.cache/storyboard +if hash nodejs 2>/dev/null && ! hash node 2>/dev/null; then + ln -s `which nodejs` $workspace_path/.local/bin/node +fi + +# If we have npm already, there is no need to download/compile +if hash npm 2>/dev/null; then + # Also, it needs to be new enough - that is, newer than v1 or v1.2 + # or v1.2.18. This could almost certainly be improved in some way + if test "$( npm --version | awk -F'.' ' ( $1 > 1 || ( $1 == 1 && $2 > 2 ) || ( $1 == 1 && $2 == 2 && $3 >= 18 ) ) ' )" ; then + exit 0 + fi +fi + # Download the source if we don't have it already. if [ ! -f $node_archive_path ]; then echo "Downloading Node v$node_version..." diff --git a/bin/build.sh b/bin/build.sh index 1968f05e..8e74c703 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -5,15 +5,8 @@ VDISPLAY=99 DIMENSIONS='1280x1024x24' XVFB=/usr/bin/Xvfb -BIN_DIR="$( cd "$( dirname "$0" )" && pwd )" -WORKSPACE="$(dirname "$BIN_DIR")" - -# Add our new bin directory to the PATH -echo "Adding $WORKSPACE/.local/bin to PATH" -export PATH=$WORKSPACE/.local/bin:$PATH -echo "Adding $WORKSPACE/node_modules/.bin to PATH" -export PATH=$WORKSPACE/node_modules/.bin:$PATH +source $(dirname $0)/setenv.sh cd $WORKSPACE; echo "Installing build dependencies" @@ -35,4 +28,4 @@ result=$? pkill Xvfb 2>&1 > /dev/null set -e -exit $result \ No newline at end of file +exit $result diff --git a/bin/setenv.sh b/bin/setenv.sh new file mode 100644 index 00000000..b5b05667 --- /dev/null +++ b/bin/setenv.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +BIN_DIR="$( cd "$( dirname "$0" )" && pwd )" +WORKSPACE="$(dirname "$BIN_DIR")" + +# Add our new bin directory to the PATH +echo "Adding $WORKSPACE/.local/bin to PATH" +export PATH=$WORKSPACE/.local/bin:$PATH +echo "Adding $WORKSPACE/node_modules/.bin to PATH" +export PATH=$WORKSPACE/node_modules/.bin:$PATH