]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - prebuilt/iot-gateway/node_modules/aws-iot-device-sdk/scripts/browserize.sh
Updated to use the latest TI 15.4-Stack v2.1.0 from the SimpleLink CC13x0 SDK v1.30.
[apps/tidep0084.git] / prebuilt / iot-gateway / node_modules / aws-iot-device-sdk / scripts / browserize.sh
1 #!/bin/bash
2 #
3 # Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License").
6 # You may not use this file except in compliance with the License.
7 # A copy of the License is located at
8 #
9 #  http://aws.amazon.com/apache2.0
10 #
11 # or in the "license" file accompanying this file. This file is distributed
12 # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 # express or implied. See the License for the specific language governing
14 # permissions and limitations under the License.
15 #
16 BROWSER_BUNDLE_DIR=browser
17 #
18 # Make sure that browserify is available.
19 #
20 BROWSERIFY=`which browserify`
21 if [ $? = "0" ] 
22 then
23 #
24 # Make sure that npm is available.
25 #
26    NPM=`which npm`
27    if [ $? = "0" ] 
28    then
29 #
30 # Make sure we are in the right directory by verifying the presence of a couple of files
31 #
32       if [ -e "README.md" ] && [ -e "thing/index.js" ] && [ -d $BROWSER_BUNDLE_DIR ]
33       then
34 #
35 # Check to see how many arguments are available; if there are none, we'll create the
36 # browser bundle to be used by other applications.  If one argument is available, we'll
37 # browserify that file using external references to aws-sdk and aws-iot-device-sdk and
38 # place the result in that directory under 'bundle.js'.  If two arguments are available
39 # available, we'll use the second argument as the bundle output file.  Finally, we'll
40 # copy the browser bundle into the application directory so that it's available for use.
41 #
42          if [ $# = "0" ] || [ ! -f $BROWSER_BUNDLE_DIR/aws-iot-sdk-browser-bundle.js ]
43          then
45 #
46 # Prepare the bundle by doing an npm install in the browser bundle directory.  Note
47 # that we use this copy of the SDK files rather than pulling them from npm, so that
48 # we can easily work with local changes, if necessary.
49 #
50             (cd $BROWSER_BUNDLE_DIR; tar cvzf aws-iot-device-sdk.tgz --exclude ${PWD##*/} --exclude node_modules --exclude .git --exclude .coverdata --exclude debug --exclude examples --exclude reports --exclude test -C ../ .; mkdir -p node_modules/aws-iot-device-sdk; (cd node_modules/aws-iot-device-sdk; tar xvzf ../../aws-iot-device-sdk.tgz); npm install)
51 #
52 # Patch mqtt.js so that we have access to its internal client constructor (needed so that we 
53 # can dynamically create the URL).
54 #
55             (cd $BROWSER_BUNDLE_DIR/node_modules/mqtt/lib/connect; echo "module.exports.MqttClient = MqttClient;" >> index.js)
56 #
57 # Finally, create the browser bundle and delete all working files/directories.  Note
58 # that we allow aws-iot-device-sdk and aws-sdk to be required by other browserify bundles.
59 #
60             (cd $BROWSER_BUNDLE_DIR; rm -f bundle.js; $BROWSERIFY -r aws-iot-device-sdk -r aws-sdk -o aws-iot-sdk-browser-bundle.js; rm -rf node_modules; rm -f aws-iot-device-sdk.tgz)
61             echo ${0##*/}": prepared browser bundle"
62          fi
63 #
64 # Browserify another app using external references to aws-sdk and aws-iot-device-sdk.
65 #
66          if [ $# -ge "1" ] && [ -f $1"" ]
67          then
68             APP_PATH=${1%/*}""
69             APP_NAME=${1##*/}""
70             OUTPUT_FILE=bundle.js
72             if [ $2"" != "" ]
73             then
74                OUTPUT_FILE=${2##*/}
75             fi
76             echo "browserifying "$1" and placing result in "$APP_PATH/$OUTPUT_FILE"..."
77             (cd $APP_PATH""; $BROWSERIFY -x aws-sdk -x aws-iot-device-sdk $APP_NAME -o $OUTPUT_FILE)
78             cp $BROWSER_BUNDLE_DIR/aws-iot-sdk-browser-bundle.js $APP_PATH
79          else
80             if [ $# -gt "2" ]
81             then
82                echo "usage: "${0##*/}" [javascript application] [output file]"
83                rc=4
84             else
85                echo ${0##*/}": can't browserify ("$1") because it's not a file"
86                rc=3
87             fi
88          fi
89       else
90          echo ${0##*/}": this script must be run in the package top-level directory"
91          rc=2
92       fi
93    else
94       echo ${0##*/}": npm is not available, please install"
95       rc=1
96    fi
97 else
98    echo ${0##*/}": browserify is not available, please install, e.g. npm install -g browserify"
99    rc=1
100 fi
101 exit $rc