-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·200 lines (167 loc) · 4.8 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/sh
BUILD_DIR=build
SRC_DIR=`pwd`/src
BUILD_CFG=$BUILD_DIR/config.json
NODE=`which node`
UGLIFY=`which uglifyjs`
VERSION=`cat VERSION`
CUR_DIR=$PWD
#possible relative path
WORKINGDIR=`dirname $0`
cd "$WORKINGDIR"
#abs path
WORKINGDIR=`pwd`
cd "$CUR_DIR"
OBJECT_NAME="HydnaChannel"
DISABLE_WS=false
DISABLE_FLASH=false
DISABLE_COMET=false
COMET_PATH="/comet/"
FLASH_PATH="bridge.swf"
function usage()
{
echo "usage: $0 [options]"
echo
echo "This script configures the hydnajs library."
echo
echo "Available options:"
echo " -h, --help Show this message"
echo " -V, --version Show package version"
echo " --environment=NAME Configure for a specific environment"
echo " --comet-path=PATH Sets path where comet requests should be sent, default '/comet/'"
echo " --flash-path=URL Sets the flash url, defaults to 'bridge.swf'"
echo " --disable-comet Removes all comet code from the output"
echo " --disable-flash Removes all flash code from the output"
echo " --disable-ws Removes all websocket code from the output"
exit $1
}
function confenvironment()
{
case "$OPTARG" in
"hydna" )
echo "Configure for 'hydna' environment"
OBJECT_NAME="HydnaChannel"
COMET_PATH="/comet/"
FLASH_PATH="http://cdn.hydna.com/1/bridge.swf"
;;
"test" )
echo "Configure for 'test' environment"
OBJECT_NAME="TestChannel"
COMET_PATH="/comet/"
FLASH_PATH="../dist/bridge.swf"
;;
"cdnjs" )
echo "Configure for 'cdnjs' environment"
OBJECT_NAME="HydnaChannel"
COMET_PATH="/comet/"
FLASH_PATH="//cdnjs.cloudflare.com/ajax/libs/hydna/$VERSION/bridge.swf"
;;
"bower" )
echo "Configure for 'bower' environment"
OBJECT_NAME="HydnaChannel"
COMET_PATH="/comet/"
FLASH_PATH="bridge.swf"
;;
* )
echo "unknown environment '$OPTARG'"
exit -1
esac
}
# translate long options to short
# Note: This enable long options but disable "--?*" in $OPTARG, or disable long options after "--" in option fields.
for ((i=1;$#;i++)) ; do
case "$1" in
--) EndOpt=1 ;;
--disable-ws) ((EndOpt)) && args[$i]="$1" || args[$i]="-W";;
--disable-flash) ((EndOpt)) && args[$i]="$1" || args[$i]="-F";;
--disable-comet) ((EndOpt)) && args[$i]="$1" || args[$i]="-C";;
--version) ((EndOpt)) && args[$i]="$1" || args[$i]="-V";;
# default case : short option use the first char of the long option:
--?*) ((EndOpt)) && args[$i]="$1" || args[$i]="-${1:2:1}";;
# pass through anything else:
*) args[$i]="$1" ;;
esac
shift
done
# reset the translated args
set -- "${args[@]}"
# now we can process with getopt
while getopts ":hvVc:Cf:FWe:" opt; do
case $opt in
h) usage ;;
v) VERBOSE=true ;;
V) echo $VERSION ; exit ;;
C) DISABLE_COMET=true ;;
F) DISABLE_FLASH=true ;;
W) DISABLE_WS=true ;;
t) TEST_SUITE=true ;;
c) COMET_PATH=$OPTARG ;;
e) confenvironment -1 ;;
\?) echo "unrecognized option: -$opt" ; usage -1 ;;
:)
echo "option -$OPTARG requires an argument"
usage -1
;;
esac
done
shift $((OPTIND-1))
[[ "$1" == "--" ]] && shift
if [ ! -x $NODE ]
then
echo "Node.js is required in order to build"
exit 1
else
echo "Node.js found at '$NODE'"
fi
if [ ! -x $UGLIFY ]
then
echo "Uglify-js is required in order to build. Install via 'npm install uglify-js"
exit 1
else
echo "Uglify-js found at '$UGLIFY'"
fi
FILES=()
FILES+=(\"$SRC_DIR/globals.js\")
FILES+=(\"$SRC_DIR/base64.js\")
FILES+=(\"$SRC_DIR/nexttick.js\")
FILES+=(\"$SRC_DIR/uri.js\")
FILES+=(\"$SRC_DIR/encoding.js\")
FILES+=(\"$SRC_DIR/events.js\")
FILES+=(\"$SRC_DIR/connection.js\")
FILES+=(\"$SRC_DIR/channel.js\")
if $DISABLE_WS ; then
echo "Ignoring websocket transport files..."
else
FILES+=(\"$SRC_DIR/websocket.js\")
fi
if $DISABLE_FLASH ; then
echo "Ignoring flash transport files..."
else
FILES+=(\"$SRC_DIR/flash.js\")
fi
if $DISABLE_COMET ; then
echo "Ignoring comet transport files..."
else
FILES+=(\"$SRC_DIR/comet.js\")
fi
FILES+=(\"$SRC_DIR/exports.js\")
BAR=""
for index in ${!FILES[*]}
do
BAR="$BAR,${FILES[$index]}"
done
mkdir -p $BUILD_DIR
echo "{" > $BUILD_CFG
echo \"VERSION\": \"$VERSION\", >> $BUILD_CFG
echo \"uglify\": \"$UGLIFY\", >> $BUILD_CFG
echo \"workingdir\": \"$WORKINGDIR\", >> $BUILD_CFG
echo \"OBJECT_NAME\": \"$OBJECT_NAME\", >> $BUILD_CFG
echo \"COMET_PATH\": \"$COMET_PATH\", >> $BUILD_CFG
echo \"FLASH_PATH\": \"$FLASH_PATH\", >> $BUILD_CFG
echo \"DISABLE_WEBSOCKET\": $DISABLE_WS, >> $BUILD_CFG
echo \"DISABLE_FLASH\": $DISABLE_FLASH, >> $BUILD_CFG
echo \"DISABLE_COMET\": $DISABLE_COMET, >> $BUILD_CFG
echo \"files\":[${BAR:1}] >> $BUILD_CFG
echo } >> $BUILD_CFG
unset FILES
echo "Configuration was successful"