#!/bin/bash

VERSION=`grep -E --only-match \"version\":\"[0-9.]+\" package.json | head -1 | grep -E --only-match [0-9.]+`

if [ -e node_modules/.bin ] ; then
    rm -rf out DuckClient-*
    node_modules/.bin/nwbuild --platform=linux --arch=x64 --glob=false .
    cp -r certs css fonts images lib sounds out/package.nw/
    mv out DuckClient-${VERSION}
    tar cvzf DuckClient-${VERSION}.tgz ./DuckClient-${VERSION}
    exit
else
    echo "Did not find nwjs-builder-phoenix script. Run 'npm install'"
    echo "in the project root directory and try again."
    exit 1
fi
