#!/bin/bash

which powershell.exe
if [ $? -ne 0 ] ; then
    echo "Skipping Windows build; not running on a Windows platform."
    exit
fi

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

# Fix icon line, which needs to be different for Windows builds than for Mac builds.
cp package.json package-old.json
sed -e 's/"icon": .*/"icon": "duckclient-128.ico",/' package-old.json >package.json

if [ -e node_modules/.bin ] ; then
    powershell.exe  .\\node_modules\\.bin\\nwbuild.cmd --platform=win --arch=x64 --glob=false .

    # Copy other files into application. Unlike nw-builder-phoenix, nw-builder does not
    # do this for us.
    cp -r certs css fonts images lib sounds out/package.nw/
    mv out DuckClient-${VERSION}
    mkdir dist
    zip -r dist/DuckClient-${VERSION}.zip DuckClient-${VERSION}
    rm -r 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
