source: OpenWorkouts-current/bin/js_deps

current
Last change on this file was 778d53d, checked in by Borja Lopez <borja@…>, 5 years ago

(#7) Show per-sport stats in the profile page:

  • Show a dropdown list of sports for which the user has activities. By default we choose the sport with most activities.
  • Show a dropdown list of years for which the user has activities. By default we show stats for the current year. If the user picks up a different year, we show the totals (distance, time, elevation, number of workouts) for that year.
  • Show the totals of all time for the chosen sport
  • Property mode set to 100755
File size: 8.8 KB
Line 
1#!/bin/sh
2#
3# Download all the needed static js assets and put them in the
4# proper place
5#
6
7# Hints on curl:
8#  -L - needed to follow redirections, which is needed for downloading release
9#       tarballs from github
10#  -O - keep the remote file name when saving it locally
11#  -# - show progress bar
12
13# Set curl, unzip and tar full paths + default parameters/options
14GET="`which curl` -L -O -#"
15UNZIP="`which unzip` -q"
16TAR="`which tar` -zxf"
17
18# Temp dir where compressed files are downloaded, uncompressed, etc
19TMP=ow/static/tmp
20# Destination directory for all the components
21COMPONENTS=ow/static/components
22# Cache file, to keep track of which components have been installed
23# already
24CACHE=$COMPONENTS/js_deps.cache
25# Full path to where we run the script from
26CURRENT=`pwd`
27
28# Some repeated messages all over the script
29ALREADY_INSTALLED="is already installed, use --reinstall to install again"
30
31if [ ! -d ${CURRENT}/ow ]; then
32    echo "Error: Please run this script inside the OpenWorkouts repository"
33    exit 1
34fi
35
36if [ ! -d ${TMP} ]; then
37    mkdir ${TMP}
38fi
39
40if [ ! -d ${COMPONENTS} ]; then
41    mkdir ${COMPONENTS}
42fi
43
44if [ ! -f ${CACHE} ]; then
45    touch ${CACHE}
46fi
47
48# Look for the --reinstall parameter, which forces the reinstall of any
49# installed components
50REINSTALL=1
51if [ "$1" == "--reinstall" ]; then
52    REINSTALL=0
53fi
54
55check_cache() {
56    # Check the cache file, see if we can skip installing a component
57    #
58    # Expects 2 parameters, first one is the component name, second is
59    # the version of that component
60    grep -q "$1-$2" $CACHE
61    res=$?
62    return "$res"
63}
64
65# The next few functions will take care of download and "install" each
66# component.
67#
68# To Upgrade a component to a new version, change VERSION inside the function
69# and run the script. Fix the code inside the function if needed
70#
71# To Add a new component, add a new function, using one of the existing as
72# a base start. Some of them download js/css files directly, some of them
73# grab a zipped file or a tarball and uncompress it, copying over the needed
74# data to the proper place, just try to find out what fits best for the new
75# component and start from there.
76#
77# HINT: when installing a new component, comment the lines calling all the other
78# components install functions, so you do not have to wait for all components to
79# be installed.
80
81jquery() {
82    NAME="jquery"
83    VERSION=3.3.1
84    URL=https://code.jquery.com/${NAME}-${VERSION}.js
85    check_cache ${NAME} ${VERSION}
86    in_cache=$?
87    if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then
88        echo "${NAME}-${VERSION} $ALREADY_INSTALLED"
89    else
90        echo "> Installing ${NAME} ${VERSION}"
91        if [ -d ${COMPONENTS}/${NAME} ]; then
92            # Clean up, delete previous install before installing
93            rm -r ${COMPONENTS}/${NAME}
94        fi
95        mkdir ${COMPONENTS}/${NAME}
96        cd ${COMPONENTS}/${NAME}
97        ${GET} ${URL}
98        # Better to have a simple jquery.js, so we do not have to set an
99        # specific version when loading it in the templates or assets
100        ln -sf ${NAME}-${VERSION}.js ${NAME}.js
101        cd ${CURRENT}
102        echo "${NAME}-${VERSION}" >> ${CACHE}
103        echo "< Installed ${NAME} ${VERSION}"
104    fi
105}
106
107easy_autocomplete() {
108    NAME="EasyAutocomplete"
109    VERSION=1.3.4
110    URL=https://github.com/pawelczak/${NAME}/archive/${VERSION}.tar.gz
111    check_cache ${NAME} ${VERSION}
112    in_cache=$?
113    if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then
114        echo "${NAME}-${VERSION} $ALREADY_INSTALLED"
115    else
116        echo "> Installing ${NAME} ${VERSION}"
117        if [ -d ${COMPONENTS}/${NAME} ]; then
118            # Clean up, delete previous install before installing
119            rm -r ${COMPONENTS}/${NAME}
120        fi
121        cd ${TMP}
122        ${GET} ${URL}
123        ${TAR} ${VERSION}.tar.gz
124        cd ${CURRENT}
125        mv ${TMP}/${NAME}-${VERSION}/dist ${COMPONENTS}/${NAME}
126        echo "${NAME}-${VERSION}" >> ${CACHE}
127        echo "< Installed ${NAME} ${VERSION}"
128    fi
129}
130
131leaflet() {
132    NAME="Leaflet"
133    VERSION=1.3.4
134    URL=https://github.com/${NAME}/${NAME}/archive/v${VERSION}.tar.gz
135    check_cache ${NAME} ${VERSION}
136    in_cache=$?
137    if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then
138        echo "${NAME}-${VERSION} $ALREADY_INSTALLED"
139    else
140        echo "> Installing ${NAME} ${VERSION}"
141        if [ -d ${COMPONENTS}/${NAME} ]; then
142            # Clean up, delete previous install before installing
143            rm -r ${COMPONENTS}/${NAME}
144        fi
145        cd ${TMP}
146        ${GET} ${URL}
147        ${TAR} v${VERSION}.tar.gz
148        cd ${CURRENT}
149        mv ${TMP}/${NAME}-${VERSION}/dist ${COMPONENTS}/${NAME}
150        echo "${NAME}-${VERSION}" >> ${CACHE}
151        echo "< Installed ${NAME} ${VERSION}"
152    fi
153}
154
155
156leaflet_gpx() {
157    NAME="leaflet-gpx"
158    VERSION=1.4.0
159    URL=https://github.com/mpetazzoni/${NAME}/archive/v${VERSION}.tar.gz
160    check_cache ${NAME} ${VERSION}
161    in_cache=$?
162    if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then
163        echo "${NAME}-${VERSION} $ALREADY_INSTALLED"
164    else
165        echo "> Installing ${NAME} ${VERSION}"
166        if [ -d ${COMPONENTS}/${NAME} ]; then
167            # Clean up, delete previous install before installing
168            rm -r ${COMPONENTS}/${NAME}
169        fi
170        cd ${TMP}
171        ${GET} ${URL}
172        ${TAR} v${VERSION}.tar.gz
173        cd ${CURRENT}
174        mv ${TMP}/${NAME}-${VERSION} ${COMPONENTS}/${NAME}
175        echo "${NAME}-${VERSION}" >> ${CACHE}
176        echo "< Installed ${NAME} ${VERSION}"
177    fi
178}
179
180leaflet_elevation() {
181    NAME="leaflet-elevation"
182    VERSION="0.0.8"
183    URL=https://github.com/Raruto/${NAME}/archive/${VERSION}.tar.gz
184    check_cache ${NAME} ${VERSION}
185    in_cache=$?
186    if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then
187        echo "${NAME}-${VERSION} $ALREADY_INSTALLED"
188    else
189        echo "> Installing ${NAME} ${VERSION}"
190        if [ -d ${COMPONENTS}/${NAME} ]; then
191            # Clean up, delete previous install before installing
192            rm -r ${COMPONENTS}/${NAME}
193        fi
194        cd ${TMP}
195        ${GET} ${URL}
196        ${TAR} ${VERSION}.tar.gz
197        cd ${CURRENT}
198        mv ${TMP}/${NAME}-${VERSION} ${COMPONENTS}/${NAME}
199        echo "${NAME}-${VERSION}" >> ${CACHE}
200        echo "< Installed ${NAME} ${VERSION}"
201    fi
202}
203
204pickadate() {
205    NAME="pickadate"
206    VERSION=3.5.6
207    URL=https://github.com/amsul/${NAME}.js/archive/${VERSION}.tar.gz
208    check_cache ${NAME} ${VERSION}
209    in_cache=$?
210    if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then
211        echo "${NAME}-${VERSION} $ALREADY_INSTALLED"
212    else
213        echo "> Installing ${NAME} ${VERSION}"
214        if [ -d ${COMPONENTS}/${NAME} ]; then
215            # Clean up, delete previous install before installing
216            rm -r ${COMPONENTS}/${NAME}
217        fi
218        mkdir ${COMPONENTS}/${NAME}
219        cd ${TMP}
220        ${GET} ${URL}
221        ${TAR} ${VERSION}.tar.gz
222        cd ${CURRENT}
223        mv ${TMP}/${NAME}.js-${VERSION}/lib/* ${COMPONENTS}/${NAME}
224        echo "${NAME}-${VERSION}" >> ${CACHE}
225        echo "< Installed ${NAME} ${VERSION}"
226    fi
227}
228
229d3() {
230    NAME="d3"
231    VERSION=5.7.0
232    URL=https://github.com/${NAME}/${NAME}/releases/download/v${VERSION}/${NAME}.zip
233    check_cache ${NAME} ${VERSION}
234    in_cache=$?
235    if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then
236        echo "${NAME}-${VERSION} $ALREADY_INSTALLED"
237    else
238        echo "> Installing ${NAME} ${VERSION}"
239        if [ -d ${COMPONENTS}/${NAME} ]; then
240            # Clean up, delete previous install before installing
241            rm -r ${COMPONENTS}/${NAME}
242        fi
243        cd ${TMP}
244        ${GET} ${URL}
245        ${UNZIP} ${NAME}.zip -d ${NAME}
246        cd ${CURRENT}
247        mv ${TMP}/${NAME} ${COMPONENTS}/
248        echo "${NAME}-${VERSION}" >> ${CACHE}
249        echo "< Installed ${NAME} ${VERSION}"
250    fi
251}
252
253jquery_dropdown() {
254    # We need version "master", as the latest release does not work properly
255    NAME="jquery-dropdown"
256    VERSION=master
257    URL=https://github.com/soundasleep/${NAME}/archive/${VERSION}.tar.gz
258    check_cache ${NAME} ${VERSION}
259    in_cache=$?
260    if [ ${in_cache} -eq 0 -a ${REINSTALL} -eq 1 ]; then
261        echo "${NAME}-${VERSION} $ALREADY_INSTALLED"
262    else
263        echo "> Installing ${NAME} ${VERSION}"
264        if [ -d ${COMPONENTS}/${NAME} ]; then
265            # Clean up, delete previous install before installing
266            rm -r ${COMPONENTS}/${NAME}
267        fi
268        mkdir ${COMPONENTS}/${NAME}
269        cd ${TMP}
270        ${GET} ${URL}
271        ${TAR} ${VERSION}.tar.gz
272        cd ${CURRENT}
273        mv ${TMP}/${NAME}-${VERSION}/jquery.dropdown.{css,js} ${COMPONENTS}/${NAME}
274        echo "${NAME}-${VERSION}" >> ${CACHE}
275        echo "< Installed ${NAME} ${VERSION}"
276    fi
277}
278
279
280echo "Installing JS dependencies in ${COMPONENTS}"
281
282jquery
283easy_autocomplete
284leaflet
285leaflet_gpx
286leaflet_elevation
287pickadate
288d3
289jquery_dropdown
290
291
292# Clean up, remove the tmp directory
293echo "Cleaning up temp storage"
294rm -r ${TMP}
Note: See TracBrowser for help on using the repository browser.