#!/bin/sh -e

echo "Unfortunately generation does not work"
cat <<EOT
npm WARN notice [SECURITY] lodash has the following vulnerability: 1 low. Go here for more details: https://nodesecurity.io/advisories?search=lodash&version=1.0.2 - Run 'npm i npm@latest -g' to upgrade your npm version, and then 'npm audit' to get more info.
npm WARN tar write after end
npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/andreas/.npm/_logs/2019-02-01T12_04_27_874Z-debug.log
EOT

exit 1

set -x
NAME=numbro
git clone --quiet https://github.com/BenjaminVanRyseghem/$NAME
DEINSTALLWEBPACK=0
if ! which webpack >/dev/null ; then
  yes | sudo apt-get install webpack node-core-js node-babel-loader >/dev/null
  DEINSTALLWEBPACK=1
fi
if ! which npm >/dev/null ; then
  yes | sudo apt-get install npm >/dev/null
  DEINSTALLNPM=1
fi
cd $NAME
npm i -D webpack-merge
# command line example found at https://wiki.debian.org/Javascript/Nodejs#Using_build_tools_like_grunt
#   webpack --config ../webpack.config.js lib/jsonld.js dist/jsonld.js --output-library=jsonld
# This was 
npm install && npm run build-webpack
mv dist ..
mv LICENSE ..
cd ..
rm -rf $NAME
mv dist/* .
rmdir dist
rm -rf node6
if [ $DEINSTALLWEBPACK -eq 1 ] ; then
  yes | sudo apt-get purge webpack node-core-js node-babel-loader >/dev/null
fi
if [ $DEINSTALLNPM -eq 1 ] ; then
  yes | sudo apt-get purge npm >/dev/null
fi
