New build mechanism

This commit is contained in:
Valentin Brandl 2019-07-28 21:42:26 +02:00
parent fa4bf3e6dc
commit 4e0216a895
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D
2 changed files with 40 additions and 0 deletions

1
frontend/.gitignore vendored
View File

@ -10,3 +10,4 @@ repl-temp-*
# End of https://www.gitignore.io/api/elm # End of https://www.gitignore.io/api/elm
index.html index.html
output

39
frontend/build.sh Executable file
View File

@ -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}"