Use build script for markdown-js.html (#1038)

* add script to build and minify markdown-js.html from npm

* update markdown-js.html from build script
This commit is contained in:
Kory Prince 2018-03-28 01:52:27 -05:00 committed by Paulus Schoutsen
parent af1581b4c5
commit 6c2126fb5f
2 changed files with 56 additions and 13 deletions

File diff suppressed because one or more lines are too long

45
script/build_markdown Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
# Set XSS_VERSION or MARKED_VERSION to set package versions. If unset, the latest version will be used.
# Stop on errors
set -e
cd "$(dirname "$0")/.."
output="public/markdown-js.html"
echo "<script>" > $output
pkgs="xss:dist/xss.min.js marked:marked.min.js"
for pkg in $pkgs; do
name="$(cut -d':' -f1 <<< "$pkg")"
js_path="$(cut -d':' -f2 <<< "$pkg")"
# Check env variable for version
version=$(eval "echo \$$(echo $name | tr "a-z" "A-Z")_VERSION")
if [ -z "$version" ]; then
version=$(yarn -s info $name dist-tags.latest)
fi
homepage=$(yarn -s info "$name@$version" homepage)
license=$(yarn -s info "$name@$version" license)
tarball=$(yarn -s info "$name@$version" dist.tarball)
cat >>$output <<EOF
/*
* $name@$version ($license)
* $homepage
*/
EOF
echo "Downloading $name@$version"
echo "$(curl -s "$tarball" | tar -xzO "package/$js_path" | ./node_modules/.bin/uglifyjs -c -m)" >> $output
done
echo "</script>" >> $output
size=$(wc -c < $output)
gzip_size=$(cat $output | gzip | wc -c)
echo "$size bytes ($gzip_size bytes gzipped) written to $output"