yagcdn/frontend/build.sh

46 lines
795 B
Bash
Raw Normal View History

2019-07-28 21:42:26 +02:00
#!/usr/bin/env sh
2019-08-09 19:43:58 +02:00
js="yagcdn.js"
min="yagcdn.min.js"
2019-07-28 21:42:26 +02:00
outdir="./output/"
scriptdir="${outdir}scripts/"
prepare() {
2019-07-29 21:14:34 +02:00
rm -rf "${outdir}"
2019-07-28 21:42:26 +02:00
mkdir -p "${outdir}/scripts"
}
build() {
elm make --optimize src/Main.elm --output=${js}
}
minify() {
uglifyjs ${js} --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | uglifyjs --mangle --output=${min}
}
sha1() {
sha1sum ${min} | cut -d' ' -f 1
}
rename_with_hash() {
sha1=${1}
2019-08-09 19:43:58 +02:00
cp ${min} "${scriptdir}/yagcdn-${sha1}.min.js"
2019-07-28 21:42:26 +02:00
}
create_index() {
sha1=${1}
2019-07-28 21:51:17 +02:00
SHA1="${sha1}" envsubst < template.html > "${outdir}/index.html"
2019-07-28 21:42:26 +02:00
}
2019-07-29 21:14:34 +02:00
copy_assets() {
cp -r assets ${outdir}
}
2019-07-28 21:42:26 +02:00
prepare
build
minify
sha1=$(sha1)
rename_with_hash "${sha1}"
create_index "${sha1}"
2019-07-29 21:14:34 +02:00
copy_assets