forked from adamfowleruk/mljs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmljsme.sh
executable file
·160 lines (139 loc) · 3.26 KB
/
mljsme.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
#!/bin/bash
usage(){
echo "Usage: CUSTOM APP: $0 -m custom [-d /your/app/main/dir] [-j /sub/js/dir] [-i /sub/images/dir] [-c /sub/css/dir]"
echo "Usage: ROXY: $0 -m roxy [-d /your/app/main/dir]"
echo "Usage: REST: $0 -m rest [-d /your/app/main/dir]"
echo "Usage: -d defaults to the current directory. For Roxy and Rest, this should be the parent of the src directory."
echo "Usage: Roxy mode creates the mljstest controller and test pages too."
exit 1
}
# Find latest temporary directory
T=${TMPDIR}mljsme
# Find application folder - -d option or PWD
ORIG=$PWD
APP=$ORIG
# Roxy full copy commands
while getopts ":c:j:i:m:d:" o; do
case "${o}" in
m)
case "$OPTARG" in
roxy)
ROXY=true
;;
rest)
REST=true
;;
*)
CUSTOM=true
;;
esac
;;
j)
J=$APP/$OPTARG
;;
i)
I=$APP/$OPTARG
;;
c)
C=$APP/$OPTARG
;;
d)
APP=$OPTARG
;;
*)
echo "$0: Unknown option specified"
usage
;;
esac
done
if [ $ROXY ]; then
echo "Roxy mode"
mkdir -p $APP/src
else
if [ $REST ]; then
echo "REST mode"
C=$APP/src/css/mljs
J=$APP/src/js/mljs
I=$APP/src/images/mljs
mkdir -p $C
mkdir -p $J
mkdir -p $I
else
echo "Custom mode"
J=$APP/src/public/js/mljs
C=$APP/src/public/css/mljs
I=$APP/src/public/images
# Ensure destination folders exist
mkdir -p $C
mkdir -p $J
mkdir -p $I
fi
fi
echo "-d=$APP -j=$J -i=$I -c=$C -roxy=$ROXY"
# make new temp folder
mkdir $T
# TODO check for existence of wget or curl and use the most appropriate, or print a helpful error message about installation each
# -bash: wget: command not found
#adam-mac:~ adamfowler$ /bin/sh flibble
#/bin/sh: flibble: No such file or directory
#adam-mac:~ adamfowler$ flibble
#-bash: flibble: command not found
RETVAL=`wget --version`
if [[ "$RETVAL" =~ ".*command not found.*" ]]; then
WGET=false
else
WGET=true
fi
RETVAL=`curl --version`
if [[ "$RETVAL" =~ ".*command not found.*" ]]; then
CURL=false
else
CURL=true
fi
if [ $CURL ]; then
echo "Got CURL"
else
echo "No CURL"
fi
if [ $WGET ]; then
echo "Got WGET"
else
echo "No WGET"
fi
$WGET=false
# Fetch latest MLJS download tar.gz file
cd $T
if [ $WGET ]; then
wget -nd --no-check-certificate https://raw.github.com/adamfowleruk/mljs/master/dist/browser-dev.tar.gz
else
if [ $CURL]; then
curl -o browser-dev.tar.gz https://raw.github.com/adamfowleruk/mljs/master/dist/browser-dev.tar.gz
else
echo "$0: Neither CURL nor WGET are installed. One must be installed to use mljsme.sh"
usage
fi
fi
# Unpack in to new temp folder
tar xzf browser-dev.tar.gz
cd dist/
if [ $ROXY ]; then
echo "Roxy mode copies"
# copy required and test files
cp -R js/* $APP/src/public/js/
cp -R images/* $APP/src/public/images/
cp -R css/* $APP/src/public/css/
else
echo "Custom mode copies"
# Copy relevant files only
cp -f js/* $J/
cp -f images/* $I/
cp -f css/* $C/
fi
# delete temp folder
cd $ORIG
rm -rf $T
# Print instructions for adding script and css links in to HTML
# Exit successfully
echo "Done."
echo "Remember, you can alias me by adding this line to your ~/.bash_profile: alias mljsme=/your/path/to/mljsme.sh "$@""
exit 0