forked from RetireJS/retire.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fx.sh
executable file
·163 lines (143 loc) · 4.14 KB
/
fx.sh
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
#!/bin/bash
# ------------------------------------------------------------------------------
# Defaults:
# ------------------------------------------------------------------------------
ADD_ON_DIR=./firefox
NODE_RETIRE_JS_FILE=./node/lib/retire.js
FX_RETIRE_JS_FILE=$ADD_ON_DIR/lib/retire.js
FX_PROFILE_DIR=""
FX_PATH=""
target=$1
release=false
# ------------------------------------------------------------------------------
# check if the jpm tool exist
# ------------------------------------------------------------------------------
if ! type jpm > /dev/null; then
echo "Aborting jpm command not found"
exit 1
fi
# ------------------------------------------------------------------------------
# puts out the help text
# ------------------------------------------------------------------------------
function howToUse {
echo "Usage: $0 target [target-specific options]"
echo
echo "Targets:"
echo " test - run the tests"
echo " run - run the add-on in a browser"
echo " build - exports the xpi"
echo
echo "Options:"
echo " -p PROFILEDIR"
echo " Use an existing profile located in PROFILEDIR. If the PROFILEDIR does not exist it will be automatically created."
echo " Example:"
echo " ./fx.sh run -p ~/firefox-retire-profile"
echo
echo " -release"
echo " Creates a release. Does not append a timestamp to the filename."
echo
exit 1
}
# ------------------------------------------------------------------------------
# create the firfox/lib/retire.js file based on the node/lib/retire.js
# ------------------------------------------------------------------------------
function createRetireJs {
if (grep -Fxq "var exports = exports || {};" $NODE_RETIRE_JS_FILE); then
cat $NODE_RETIRE_JS_FILE > $FX_RETIRE_JS_FILE
sed -i.bak s/"var exports = exports || {};"/"if (typeof exports != \"object\") exports = {};"/g $FX_RETIRE_JS_FILE
rm $FX_RETIRE_JS_FILE."bak"
else
echo "Exit. Could not create $FX_RETIRE_JS_FILE"
exit 1
fi
}
# ------------------------------------------------------------------------------
# parsing command line parameters
# ------------------------------------------------------------------------------
while [ "$2" != "" ];
do
case $2 in
-p | --profiledir )
shift
FX_PROFILE_DIR=$2
;;
-b | --binarypath )
shift
FX_PATH=$2
;;
-release )
shift
release=true
;;
esac
shift
done
# ------------------------------------------------------------------------------
# runs the tests
# ------------------------------------------------------------------------------
function runTests {
jpm test
}
# ------------------------------------------------------------------------------
# runs the add-on in the browser
# ------------------------------------------------------------------------------
function runBrowser {
PROG_ARG=""
if ! [ -z $FX_PROFILE_DIR ]
then
PROG_ARG="$PROG_ARG -p $FX_PROFILE_DIR "
fi
#jpm run -p $FX_PROFILE_DIR
if ! [ -z $FX_PATH ]
then
PROG_ARG="$PROG_ARG -b $FX_PATH"
echo $PROG_ARG
fi
echo $PROG_ARG
echo "jpm run @@$PROG_ARG@@"
jpm run $PROG_ARG
echo $PROG_ARG
}
# ------------------------------------------------------------------------------
# creates an xpi
# ------------------------------------------------------------------------------
function build {
addonName=$(sed -n 's/.*"name": "\(.*\)",/\1/p' package.json)
version=$(sed -n 's/.*"version": "\(.*\)",/\1/p' package.json)
now=$(date +"%Y%m%d%H%M%S")
if $release;
then
filename="${addonName}-${version}.xpi"
else
filename="${addonName}-${version}_${now}.xpi"
fi
jpm xpi
mv $addonName.xpi $filename
echo "Add-on built: $filename"
}
# ------------------------------------------------------------------------------
# prepearing
# ------------------------------------------------------------------------------
createRetireJs
cd $ADD_ON_DIR
case "$target" in
"test")
runTests
;;
"run")
runBrowser
;;
"build")
build
;;
"-help")
howToUse
;;
*)
echo
echo "$0: Target not supported (yet): $target"
echo
howToUse
exit 1
;;
esac