diff --git a/frontend/.gitignore b/frontend/.gitignore index 127b251..04446a0 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -10,3 +10,4 @@ repl-temp-* # End of https://www.gitignore.io/api/elm index.html +output diff --git a/frontend/build.sh b/frontend/build.sh new file mode 100755 index 0000000..061664d --- /dev/null +++ b/frontend/build.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env sh + +js="gitcdn.js" +min="gitcdn.min.js" +outdir="./output/" +scriptdir="${outdir}scripts/" + +prepare() { + 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} + cp ${min} "${scriptdir}/gitcdn-${sha1}.min.js" +} + +create_index() { + sha1=${1} + SHA1="${sha1}" envsubst < index.html > "${outdir}/index.html" +} + +prepare +build +minify +sha1=$(sha1) +rename_with_hash "${sha1}" +create_index "${sha1}"