-
Notifications
You must be signed in to change notification settings - Fork 0
/
runme
executable file
·226 lines (191 loc) · 7.13 KB
/
runme
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
BLUE='\033[0;34m'
GREEN='\033[1;32m'
RED='\033[1;31m'
RESET='\033[0m'
BBLUE='\033[1;34;107m'
BGREEN='\033[1;32;107m'
BYELLOW='\033[1;33;107m'
BRED='\033[1;31;107m'
BOLD='\033[1m'
BG='\033[107m'
YES_NO="(${RESET}${GREEN}Y${RESET}${BLUE}/${RESET}${RED}n${RESET}${BLUE}) ${RESET}"
update_bc=true
update_np=true
try_using_modified_polymer=false
modified_polymer=false
download_examples=false
# Prints flag options for user
print_help() {
printf "${BBLUE} O${BRED}p${BYELLOW}t${BBLUE}i${BGREEN}o${BRED}n${BBLUE}s${RESET}${BG}: ${RESET}\n"
printf "${BLUE}-b${RESET}: DO ${BOLD}NOT${RESET} update ${BG}bower components${RESET} (also keeps pre-existing bower_components folder)\n"
printf "${BLUE}-e${RESET}: Download some ${BG}test cases${RESET}\n"
printf "${BLUE}-n${RESET}: Do ${BOLD}NOT${RESET} update ${BG}node modules${RESET} (also keeps pre-existing node_modules folder)\n"
printf "${BLUE}-p${RESET}: Use ${BG}modified Polymer 1.0${RESET} version\n"
printf "${BLUE}-h${RESET}: For ${BG}help${RESET}, i.e. printing this message again. ¯\_(ツ)_/¯\n"
}
# Attempt to download the Polymer repository
use_modified_polymer() {
printf "${BOLD}To use the modified Polymer 1.0 version:${RESET}\n"
printf "${BLUE}To continue, clone the Polymer repository? ${RESET}${YES_NO}"
read input
shopt -s nocasematch
if [[ $input == "yes" ]] || [[ $input == "y" ]]; then
git clone "https://github.com/Polymer/polymer.git"
modified_polymer=true
else
printf "${RED}Exiting without download.${RESET}"
fi
shopt -u nocasematch
}
# Use cURL to download examples for the server
curl_examples() {
mkdir -p data
mkdir -p src
printf "${BLUE}Downloading examples...${RESET}\n"
# Pesto Example
cd src
curl -s -L https://goo.gl/ILwX3j -o app-icons.html
curl -s -L https://goo.gl/hbKryv -o recipe-app.html
curl -s -L https://goo.gl/h2tzGk -o recipe-detail.html
curl -s -L https://goo.gl/hHgYal -o recipe-list.html
cd ../data
curl -s -L https://goo.gl/dmNXVE -o recipes.json
cd ../
curl -s -L https://goo.gl/DwbCss -o pesto_manifest.json
curl -s -L https://goo.gl/AMSOKT -o index.html
curl -s -L https://goo.gl/ZQjNqo -o indexshadow.html
# Shrine Example
cd src
curl -s -L https://goo.gl/anBAEt -o shrine-app.html
curl -s -L https://goo.gl/tyrD1G -o shrine-detail.html
curl -s -L https://goo.gl/I7wT3y -o shrine-featured-item.html
curl -s -L https://goo.gl/MaZREb -o shrine-item.html
curl -s -L https://goo.gl/CSi8iZ -o shrine-list.html
curl -s -L https://goo.gl/s1tuuc -o shrine-simple-item.html
cd ../data
curl -s -L https://goo.gl/5KGt2k -o featured.json
curl -s -L https://goo.gl/pw8jdW -o items.json
cd ../
curl -s -L https://goo.gl/kgO6qw -o shrine_manifest.json
curl -s -L https://goo.gl/omvoeN -o index2.html
curl -s -L https://goo.gl/0XScHA -o index2shadow.html
# Getting Started Example
cd src
curl -s -L https://goo.gl/CQ7Nkc -o x-app.html
cd ../
curl -s -L https://goo.gl/FFYNKx -o index3.html
curl -s -L https://goo.gl/SZbIRR -o index3shadow.html
printf "${BLUE}Examples downloaded. Check the ${RESET}${BG}src/${RESET} "
printf "${BLUE}directory and${RESET} ${BG}index*.html${RESET} ${BLUE}files.${RESET}\n"
}
# Change paths linked to bower_components/.../polymer.html and webcomponents.js to
# The polymer.html and webcomponentsjs from the modified Polymer code
change_paths() {
printf "${BOLD}Paths must be converted from Polymer in ${BG}bower_components${RESET}${BOLD} to "
printf "Polymer in ${BG}node_modules${RESET}.\n${RESET}"
printf "${BLUE}Continue?${RESET} ${YES_NO}"
read input
shopt -s nocasematch
if [[ $input == "yes" ]] || [[ $input == "y" ]]; then
rm BowerToNPM*.class
javac BowerToNPM.java
printf "${BLUE}Attempt to use default paths for ${RESET}${BG}webcomponentsjs${RESET} "
printf "${BLUE}and${RESET} ${BG}polymer${RESET}${BLUE}? ${RESET}"
printf "${YES_NO}"
read input
shopt -s nocasematch
# Change paths of files in bower_components/ directory
if [[ $input == "yes" ]] || [[ $input == "y" ]]; then
_p='node_modules/@polymer/polymer/polymer.html\n'
_wc='node_modules/@polymer/polymer/node_modules/webcomponents.js/webcomponents-lite.js\n'
_op='bower_components/polymer/polymer.html\n'
_owc='bower_components/webcomponentsjs/webcomponents-lite.js\n'
_dir='bower_components\n'
txt=$_p$_wc$_op$_owc$_dir
cp /dev/null _default_bower_to_npm_inputs.txt
echo -e ${txt} >> _default_bower_to_npm_inputs.txt
java BowerToNPM -s < _default_bower_to_npm_inputs.txt
if [[ "$download_examples" == true ]]; then
# Change paths of downloaded example files in the current directory
files=("index.html" "index2.html" "index3.html" "indexshadow.html" "index2shadow.html" "index3shadow.html")
for i in "${files[@]}"
do
tmp=$_p$_wc$_op$_owc$i
cp /dev/null _default_bower_to_npm_inputs.txt
echo -e ${tmp} >> _default_bower_to_npm_inputs.txt
java BowerToNPM -s < _default_bower_to_npm_inputs.txt
done
# Change paths of downloaded example files in the src/ directory
_tmpDir='src'
tmp=$_p$_wc$_op$_owc$_tmpDir
cp /dev/null _default_bower_to_npm_inputs.txt
echo -e ${tmp} >> _default_bower_to_npm_inputs.txt
java BowerToNPM -s < _default_bower_to_npm_inputs.txt
fi
elif [[ $input == "no" ]] || [[ $input == "n" ]]; then
# Lets the user enter inputs for BowerToNPM.java manually
java BowerToNPM
else
printf "${RED}Exiting without download.${RESET}"
fi
shopt -u nocasematch
else
printf "${RED}Exiting without running${RESET} ${BG}BowerToNPM\n${RESET}."
fi
shopt -u nocasematch
}
# Clean up by removing Java class files
cleanup() {
rm BowerToNPM*.class
}
# Parse flags from user for setting up the environment
while getopts ":b|:e|:h|:n|:p" opt; do
case $opt in
b)
update_bc=false
;;
e)
download_examples=true
;;
h)
print_help
exit 1
;;
n)
update_np=false
;;
p)
try_using_modified_polymer=true
;;
esac
done
# Update bower components by default unless flag -b set
if [[ "$update_bc" == true ]]; then
rm -rf bower_components
bower update
fi
# Update node modules by default unless flag -n set
if [[ "$update_np" == true ]]; then
rm -rf node_modules
npm update
fi
# Download examples files for testing if flag -e set
if [[ "$download_examples" == true ]]; then
curl_examples
fi
# Attempt to download the Polymer library if flag -p set
if [[ "$try_using_modified_polymer" == true ]]; then
use_modified_polymer
fi
# Attempt to change changes based on the modified Polymer library if
# it was downloaded successfully in the previous step
if [[ "$modified_polymer" == true ]]; then
npm rm @polymer/polymer -g
cd polymer
npm link @polymer/polymer
cd ..
npm link @polymer/polymer
change_paths
mv _modified_polymer_shadow.html polymer/node_modules/\@polymer/polymer/src/mini/shadow.html
fi
cleanup