Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/build-js.sh

80 lines
1.5 KiB
Bash
Raw Normal View History

2016-04-27 17:21:12 +05:00
#!/usr/bin/env bash
root=$(readlink -e "$(dirname "$0")")
set -e
if [ "x" == "x$root" ] ; then
root=$PWD/${0##*}
fi
cd "$root"
2016-04-27 17:21:12 +05:00
if [ -z "$GOPATH" ]; then
export GOPATH=$root/go
mkdir -p "$GOPATH"
2016-04-27 17:21:12 +05:00
fi
if [ ! -f "$GOPATH/bin/minify" ]; then
echo "set up minifiy"
2016-04-30 17:26:14 +05:00
go get -v github.com/tdewolff/minify/cmd/minify
2016-04-27 17:21:12 +05:00
fi
outfile=$PWD/contrib/static/nntpchan.js
2016-04-27 17:21:12 +05:00
2016-04-30 21:25:15 +05:00
lint() {
if [ "$(which jslint)" == "" ] ; then
2016-04-30 21:25:15 +05:00
# no jslint
true
else
echo "jslint: $1"
jslint --browser "$1"
2016-04-30 21:25:15 +05:00
fi
}
2016-04-30 18:58:21 +05:00
mini() {
echo "minify $1"
echo "" >> $2
2016-10-07 19:17:29 +05:00
echo "/* begin $1 */" >> $2
"$GOPATH/bin/minify" --mime=text/javascript >> $2 < $1
2016-10-07 19:17:29 +05:00
echo "/* end $1 */" >> $2
2016-04-30 18:58:21 +05:00
}
2016-04-27 17:21:12 +05:00
2016-04-30 21:25:15 +05:00
# do linting too
if [ "x$1" == "xlint" ] ; then
echo "linting..."
for f in ./contrib/js/*.js ; do
lint "$f"
2016-04-30 21:25:15 +05:00
done
fi
rm -f "$outfile"
2016-10-07 19:17:29 +05:00
echo '/*' >> $outfile
echo ' * For source code and license information please check https://github.com/majestrate/nntpchan' >> $outfile
brandingfile=./contrib/branding.txt
if [ -e "$brandingfile" ] ; then
2016-10-07 19:17:29 +05:00
echo ' *' >> $outfile
while read line; do
echo -n ' * ' >> $outfile;
echo $line >> $outfile;
done < $brandingfile;
fi
echo ' */' >> $outfile
2016-04-30 18:58:21 +05:00
2016-05-03 23:58:57 +05:00
if [ -e ./contrib/js/contrib/*.js ] ; then
for f in ./contrib/js/contrib/*.js ; do
mini "$f" "$outfile"
2016-05-03 23:58:57 +05:00
done
fi
mini ./contrib/js/entry.js "$outfile"
2016-04-30 18:58:21 +05:00
# local js
2016-10-07 19:06:25 +05:00
for f in ./contrib/js/nntpchan/*.js ; do
mini "$f" "$outfile"
2016-04-27 17:21:12 +05:00
done
2016-10-07 19:06:25 +05:00
# vendor js
for f in ./contrib/js/vendor/*.js ; do
mini "$f" "$outfile"
2016-04-27 17:21:12 +05:00
done
2016-10-07 19:06:25 +05:00
2016-04-30 17:26:14 +05:00
echo "ok"