#!/bin/sh
# Setup for this script:
# dnf install nodejs-yarn $(cat gateway-unbundle.list | while read line; do echo "nodejs-$line"; done)
#
#version=$(rpm -q --specfile --qf='%{version}\n' gateway.spec | head -n1)
version=0.7.0
## Download gateway
wget https://github.com/mozilla-iot/gateway/archive/v$version.tar.gz
tar zxf v$version.tar.gz
cd gateway-$version
## Download npm libraries
yarnpkg --ignore-optional
## Clean out binary modules (and deps) and link to rpm packages
echo "Removing modules that we already have as packages "
for module in $(cat ../gateway-unbundle.list)
do
echo -n "."
rm -rf node_modules/$module
ln -s /usr/lib/node_modules/$module node_modules/
for line in $(find . -type d -name $module | grep node_modules/$module$)
do
if ! [ -L $line ] ; then
echo -n "$(echo $line | tr -cd '/' | wc -c)"
rm -rf $line
ln -s /usr/lib/node_modules/$module $line
fi
done
done
echo
echo "Starting Webpack"
PATH="/usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:$PWD/node_modules/.bin:/usr/lib/node_modules/.bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
webpack
cd ..
tar cfz gateway-v$version.tar.gz gateway-$version